This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new 936bf656222 [fix](nereids)decimal and datetime literal comparison should compare datatype too (#36064) 936bf656222 is described below commit 936bf6562224fa602885eb8aa424f8a66439c37c Author: starocean999 <40539150+starocean...@users.noreply.github.com> AuthorDate: Sat Jun 8 22:01:37 2024 +0800 [fix](nereids)decimal and datetime literal comparison should compare datatype too (#36064) pick from master #36055 --- .../trees/expressions/literal/DateTimeV2Literal.java | 16 ++++++++++++++++ .../trees/expressions/literal/DecimalLiteral.java | 15 +++++++++++++++ .../trees/expressions/literal/DecimalV3Literal.java | 15 +++++++++++++++ .../nereids/rules/expression/ExpressionRewriteTest.java | 8 ++++---- .../rules/expression/rules/SimplifyCastRuleTest.java | 12 ++++++------ .../trees/expressions/literal/DateTimeLiteralTest.java | 14 +++++++------- .../nereids_p0/aggregate/agg_window_project.groovy | 14 ++++++++++++++ 7 files changed, 77 insertions(+), 17 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeV2Literal.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeV2Literal.java index 778d74e1e3f..1ddd0cfcc5c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeV2Literal.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeV2Literal.java @@ -29,6 +29,7 @@ import org.apache.doris.nereids.util.StandardDateFormat; import com.google.common.base.Preconditions; import java.time.LocalDateTime; +import java.util.Objects; /** * date time v2 literal for nereids @@ -271,4 +272,19 @@ public class DateTimeV2Literal extends DateTimeLiteral { dateTime.getMinute(), dateTime.getSecond(), (dateTime.getNano() / 1000) / value * value); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + DateTimeV2Literal literal = (DateTimeV2Literal) o; + return Objects.equals(dataType, literal.dataType); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalLiteral.java index 84b8f07a94a..ea198d947ae 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalLiteral.java @@ -95,4 +95,19 @@ public class DecimalLiteral extends FractionalLiteral { precision, scale, realPrecision, realScale)); } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + DecimalLiteral literal = (DecimalLiteral) o; + return Objects.equals(dataType, literal.dataType); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java index 33bf5773165..beb8810c35d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java @@ -106,4 +106,19 @@ public class DecimalV3Literal extends FractionalLiteral { precision, scale, realPrecision, realScale)); } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + DecimalV3Literal literal = (DecimalV3Literal) o; + return Objects.equals(dataType, literal.dataType); + } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/ExpressionRewriteTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/ExpressionRewriteTest.java index 2dd1d6aa459..c5f69b1edbb 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/ExpressionRewriteTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/ExpressionRewriteTest.java @@ -234,13 +234,13 @@ class ExpressionRewriteTest extends ExpressionRewriteTestHelper { // decimal literal assertRewrite(new Cast(new TinyIntLiteral((byte) 1), DecimalV2Type.createDecimalV2Type(15, 9)), - new DecimalLiteral(new BigDecimal("1.000000000"))); + new DecimalLiteral(DecimalV2Type.createDecimalV2Type(15, 9), new BigDecimal("1.000000000"))); assertRewrite(new Cast(new SmallIntLiteral((short) 1), DecimalV2Type.createDecimalV2Type(15, 9)), - new DecimalLiteral(new BigDecimal("1.000000000"))); + new DecimalLiteral(DecimalV2Type.createDecimalV2Type(15, 9), new BigDecimal("1.000000000"))); assertRewrite(new Cast(new IntegerLiteral(1), DecimalV2Type.createDecimalV2Type(15, 9)), - new DecimalLiteral(new BigDecimal("1.000000000"))); + new DecimalLiteral(DecimalV2Type.createDecimalV2Type(15, 9), new BigDecimal("1.000000000"))); assertRewrite(new Cast(new BigIntLiteral(1L), DecimalV2Type.createDecimalV2Type(15, 9)), - new DecimalLiteral(new BigDecimal("1.000000000"))); + new DecimalLiteral(DecimalV2Type.createDecimalV2Type(15, 9), new BigDecimal("1.000000000"))); } @Test diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java index 71bfd37a578..f04f10f4026 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java @@ -71,7 +71,7 @@ class SimplifyCastRuleTest extends ExpressionRewriteTestHelper { assertRewrite(new Cast(tinyIntLiteral, TinyIntType.INSTANCE), tinyIntLiteral); // cast tinyint as decimalv2(3,0) assertRewrite(new Cast(tinyIntLiteral, DecimalV2Type.forType(TinyIntType.INSTANCE)), - new DecimalLiteral(new BigDecimal(12))); + new DecimalLiteral(DecimalV2Type.forType(TinyIntType.INSTANCE), new BigDecimal(12))); assertRewrite(new Cast(tinyIntLiteral, DecimalV2Type.createDecimalV2Type(5, 1)), new DecimalLiteral(DecimalV2Type.createDecimalV2Type(5, 1), @@ -79,7 +79,7 @@ class SimplifyCastRuleTest extends ExpressionRewriteTestHelper { // cast tinyint as decimalv3(3,0) assertRewrite(new Cast(tinyIntLiteral, DecimalV3Type.forType(TinyIntType.INSTANCE)), - new DecimalV3Literal(new BigDecimal(12))); + new DecimalV3Literal(DecimalV3Type.forType(TinyIntType.INSTANCE), new BigDecimal(12))); // cast tinyint as decimalv3(5,1) assertRewrite(new Cast(tinyIntLiteral, DecimalV3Type.createDecimalV3Type(5, 1)), new DecimalV3Literal(DecimalV3Type.createDecimalV3Type(5, 1), @@ -108,20 +108,20 @@ class SimplifyCastRuleTest extends ExpressionRewriteTestHelper { assertRewrite(new Cast(intLiteral, IntegerType.INSTANCE), intLiteral); // cast int as decimalv2 assertRewrite(new Cast(intLiteral, DecimalV2Type.forType(IntegerType.INSTANCE)), - new DecimalLiteral(new BigDecimal(30000000))); + new DecimalLiteral(DecimalV2Type.forType(IntegerType.INSTANCE), new BigDecimal(30000000))); // cast int as decimalv3 assertRewrite(new Cast(intLiteral, DecimalV3Type.forType(IntegerType.INSTANCE)), - new DecimalV3Literal(new BigDecimal(30000000))); + new DecimalV3Literal(DecimalV3Type.forType(IntegerType.INSTANCE), new BigDecimal(30000000))); Expression bigIntLiteral = new BigIntLiteral(30000000000L); // cast bigint as bigint assertRewrite(new Cast(bigIntLiteral, BigIntType.INSTANCE), bigIntLiteral); // cast bigint as decimalv2 assertRewrite(new Cast(bigIntLiteral, DecimalV2Type.forType(BigIntType.INSTANCE)), - new DecimalLiteral(new BigDecimal(30000000000L))); + new DecimalLiteral(DecimalV2Type.forType(BigIntType.INSTANCE), new BigDecimal(30000000000L))); // cast bigint as decimalv3 assertRewrite(new Cast(bigIntLiteral, DecimalV3Type.forType(BigIntType.INSTANCE)), - new DecimalV3Literal(new BigDecimal(30000000000L))); + new DecimalV3Literal(DecimalV3Type.forType(BigIntType.INSTANCE), new BigDecimal(30000000000L))); Expression varcharLiteral = new VarcharLiteral("12345"); // cast varchar(5) as varchar(3) diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteralTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteralTest.java index 94e456cf928..820c9ae9ac0 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteralTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteralTest.java @@ -416,32 +416,32 @@ class DateTimeLiteralTest { void testDateTimeV2Scale() { Assertions.assertEquals( new DateTimeV2Literal(DateTimeV2Type.of(3), "2016-07-02 00:00:00.123"), - new DateTimeV2Literal("2016-07-02 00:00:00.123")); + new DateTimeV2Literal(DateTimeV2Type.of(3), "2016-07-02 00:00:00.123")); Assertions.assertEquals( new DateTimeV2Literal(DateTimeV2Type.of(3), "2016-07-02 00:00:00.123456"), - new DateTimeV2Literal("2016-07-02 00:00:00.123")); + new DateTimeV2Literal(DateTimeV2Type.of(3), "2016-07-02 00:00:00.123")); Assertions.assertEquals( new DateTimeV2Literal(DateTimeV2Type.of(4), "2016-07-02 00:00:00.12345"), - new DateTimeV2Literal("2016-07-02 00:00:00.12345")); + new DateTimeV2Literal(DateTimeV2Type.of(4), "2016-07-02 00:00:00.1235")); Assertions.assertEquals( new DateTimeV2Literal(DateTimeV2Type.of(0), "2016-07-02 00:00:00.12345"), - new DateTimeV2Literal("2016-07-02 00:00:00.0")); + new DateTimeV2Literal(DateTimeV2Type.of(0), "2016-07-02 00:00:00")); Assertions.assertEquals( new DateTimeV2Literal(DateTimeV2Type.of(0), "2016-07-02 00:00:00.5123"), - new DateTimeV2Literal("2016-07-02 00:00:01.0")); + new DateTimeV2Literal(DateTimeV2Type.of(0), "2016-07-02 00:00:01")); Assertions.assertEquals( new DateTimeV2Literal(DateTimeV2Type.of(5), "2016-07-02 00:00:00.999999"), - new DateTimeV2Literal("2016-07-02 00:00:01.0")); + new DateTimeV2Literal(DateTimeV2Type.of(5), "2016-07-02 00:00:01.00000")); // test overflow Assertions.assertEquals( new DateTimeV2Literal(DateTimeV2Type.of(5), "2016-12-31 23:59:59.999999"), - new DateTimeV2Literal("2017-01-01 00:00:00.0")); + new DateTimeV2Literal(DateTimeV2Type.of(5), "2017-01-01 00:00:00.00000")); } @Test diff --git a/regression-test/suites/nereids_p0/aggregate/agg_window_project.groovy b/regression-test/suites/nereids_p0/aggregate/agg_window_project.groovy index eed0ec3fd24..df982c6d86e 100644 --- a/regression-test/suites/nereids_p0/aggregate/agg_window_project.groovy +++ b/regression-test/suites/nereids_p0/aggregate/agg_window_project.groovy @@ -109,4 +109,18 @@ suite("agg_window_project") { sql """select a, a aa, row_number() over (partition by b) from test_window_table2;""" sql "DROP TABLE IF EXISTS test_window_table2;" + + sql """DROP TABLE IF EXISTS test_window_union_t1;""" + sql """DROP TABLE IF EXISTS test_window_union_t2;""" + sql """create table test_window_union_t1 (item_code int) distributed by hash(item_code) properties("replication_num"="1");""" + sql """insert into test_window_union_t1 values(1), (11), (111);""" + + sql """create table test_window_union_t2 (orderamount_lj_tq decimalv3(38,5)) distributed by hash(orderamount_lj_tq) properties("replication_num"="1");""" + sql """insert into test_window_union_t2 values(123456.12345), (223456.12345), (323456.12345);""" + + sql """ + SELECT 0 AS `amount_dh_real_tq`, (CASE WHEN `t`.`item_code` IS NOT NULL THEN (1.0 / count(1) OVER (PARTITION BY `t`.`item_code`)) ELSE 0.0 END) AS `item_qty_dh_order` FROM `test_window_union_t1` t + UNION ALL + SELECT `t`.`orderamount_lj_tq` AS `amount_dh_real_tq`, 0 AS `item_qty_dh_order` FROM `test_window_union_t2` t ; + """ } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org