diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java index cd635649fd1a68..7b4e4f05814fc2 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java @@ -1124,7 +1124,13 @@ public static ScalarType getAssignmentCompatibleType( if (t1.isFloatingPointType() || t2.isFloatingPointType()) { return t1.isFloatingPointType() ? t1 : t2; } else if (t1.isBoolean() || t2.isBoolean()) { - return t1.isDecimalV3() ? t1 : t2; + return t1.isDecimalV3() + ? ScalarType.createDecimalV3Type( + Math.max(t1.precision - t1.scale, 1) + Math.max(t1.scale, 0), + Math.max(t1.scale, 0)) : + ScalarType.createDecimalV3Type( + Math.max(t2.precision - t2.scale, 1) + Math.max(t2.scale, 0), + Math.max(t2.scale, 0)); } } diff --git a/regression-test/data/datatype_p0/scalar_types/get_assignment_compatible_type.out b/regression-test/data/datatype_p0/scalar_types/get_assignment_compatible_type.out new file mode 100644 index 00000000000000..5706a768d2d000 --- /dev/null +++ b/regression-test/data/datatype_p0/scalar_types/get_assignment_compatible_type.out @@ -0,0 +1,8 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test_sql -- +test_decimal_boolean_view CREATE VIEW `test_decimal_boolean_view` COMMENT 'VIEW' AS SELECT `id` AS `id`, `c1` AS `c1`, `c2` AS `c2` FROM `default_cluster:regression_test_datatype_p0_scalar_types`.`test_decimal_boolean` WHERE 0.0 = CAST(`c1` AS DECIMALV3(2, 1)) AND CAST(`c2` AS DECIMALV3(6, 1)) = 1.0; utf8 utf8_general_ci + +-- !test_union -- +0.0 +1.0 + diff --git a/regression-test/suites/datatype_p0/scalar_types/get_assignment_compatible_type.groovy b/regression-test/suites/datatype_p0/scalar_types/get_assignment_compatible_type.groovy new file mode 100644 index 00000000000000..afbf3746259533 --- /dev/null +++ b/regression-test/suites/datatype_p0/scalar_types/get_assignment_compatible_type.groovy @@ -0,0 +1,52 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("get_assignment_compatible_type") { + sql 'set enable_nereids_planner=false' + sql "drop table if exists test_decimal_boolean" + sql """create table test_decimal_boolean ( + id int, + c1 boolean, + c2 tinyint + ) duplicate key (`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ); """ + sql "insert into test_decimal_boolean values (1,1,1),(2,0,1);" + sql "sync" + sql "drop view if exists test_decimal_boolean_view;" + // 0.0 = c1 is the test point + sql "create view test_decimal_boolean_view as select id,c1,c2 from test_decimal_boolean where 0.0=c1 and c2 = 1.0;" + sql "select * from test_decimal_boolean_view;" + qt_test_sql "show create view test_decimal_boolean_view" + + sql "drop table if exists test_decimal_boolean_union" + sql """create table test_decimal_boolean_union ( + id int, + c1 boolean, + c2 decimalv3(1,1) + ) duplicate key (`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); """ + sql "insert into test_decimal_boolean_union values(1,true,0.0),(1,false,0.0)" + qt_test_union "select c1 from test_decimal_boolean_union union select c2 from test_decimal_boolean_union order by 1" +} \ No newline at end of file