This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit d4d994d844f895f6944829e19c8ddf5754c10a5a Author: morrySnow <[email protected]> AuthorDate: Thu Apr 6 13:51:50 2023 +0800 [fix](planner) decimalv2 castTo decimalv2 should change type directly (#18297) --- .../main/java/org/apache/doris/analysis/Expr.java | 7 ++ .../data/query_p0/aggregate/select_distinct.out | 4 ++ .../query_p0/aggregate/select_distinct.groovy | 77 ++++++++++++++++++++++ 3 files changed, 88 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java index a94a1ee21d..4c76d1bade 100755 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java @@ -1392,6 +1392,13 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl && (this.type.isStringType() || this.type.isHllType())) { return this; } + + if (targetType.getPrimitiveType() == PrimitiveType.DECIMALV2 + && this.type.getPrimitiveType() == PrimitiveType.DECIMALV2) { + this.type = targetType; + return this; + } + // Preconditions.checkState(PrimitiveType.isImplicitCast(type, targetType), // "cast %s to %s", this.type, targetType); // TODO(zc): use implicit cast diff --git a/regression-test/data/query_p0/aggregate/select_distinct.out b/regression-test/data/query_p0/aggregate/select_distinct.out new file mode 100644 index 0000000000..8c6c3f37f1 --- /dev/null +++ b/regression-test/data/query_p0/aggregate/select_distinct.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !distinct_decimal_cast -- +1 5.300000000 + diff --git a/regression-test/suites/query_p0/aggregate/select_distinct.groovy b/regression-test/suites/query_p0/aggregate/select_distinct.groovy new file mode 100644 index 0000000000..6456158bda --- /dev/null +++ b/regression-test/suites/query_p0/aggregate/select_distinct.groovy @@ -0,0 +1,77 @@ +// 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("select_distinct") { + sql """DROP TABLE IF EXISTS decimal_a;""" + sql """DROP TABLE IF EXISTS decimal_b;""" + sql """DROP TABLE IF EXISTS decimal_c;""" + + sql """ + CREATE TABLE IF NOT EXISTS `decimal_a` ( + `id` int(11) NOT NULL + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + CREATE TABLE IF NOT EXISTS `decimal_b` ( + `id` int(11) NOT NULL, + `age` decimal(11, 3) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + CREATE TABLE IF NOT EXISTS `decimal_c` ( + `id` int(11) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 64 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """insert into decimal_a values(1);""" + sql """insert into decimal_b values (1, 5.3);""" + sql """insert into decimal_c values(1);""" + + qt_distinct_decimal_cast """ + select distinct + decimal_a.id, + case + when decimal_b.age >= 0 then decimal_b.age + when decimal_b.age >= 0 then floor(decimal_b.age/365) + end + from + decimal_a + inner join decimal_b on decimal_a.id =decimal_b.id + left join decimal_c on decimal_a.id=decimal_c.id; + """ + + sql """DROP TABLE IF EXISTS decimal_a;""" + sql """DROP TABLE IF EXISTS decimal_b;""" + sql """DROP TABLE IF EXISTS decimal_c;""" +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
