From ea68c9f776fc5176384beb8a303b0dbd0d2a1769 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Mon, 6 May 2024 18:03:10 +0800 Subject: [PATCH 1/3] [Fix](nereids) fix ScalarType.getAssignmentCompatibleType() when deal boolean and decimal --- .../main/java/org/apache/doris/catalog/ScalarType.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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)); } } From 4abbdae626f437e9b4242e9b1601ac4fde7a5b7c Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Wed, 8 May 2024 17:58:06 +0800 Subject: [PATCH 2/3] add regression test --- .../get_assignment_compatible_type.out | 8 +++ .../get_assignment_compatible_type.groovy | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 regression-test/data/datatype_p0/scalar_types/get_assignment_compatible_type.out create mode 100644 regression-test/suites/datatype_p0/scalar_types/get_assignment_compatible_type.groovy 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..9f8d9b546fc663 --- /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 `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); utf8mb4 utf8mb4_0900_bin + +-- !test_union -- +0 +1 + 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 From d2529b96192b86025a79d42c9b8f842710f7c772 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Sat, 11 May 2024 14:11:20 +0800 Subject: [PATCH 3/3] modify regression --- .../scalar_types/get_assignment_compatible_type.out | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 index 9f8d9b546fc663..5706a768d2d000 100644 --- 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 @@ -1,8 +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 `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); utf8mb4 utf8mb4_0900_bin +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 -1 +0.0 +1.0