This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 1bc27ddbc57 [fix](nereids)decimal and datetime literal comparison 
should compare datatype too (#36065)
1bc27ddbc57 is described below

commit 1bc27ddbc57439d5a9d7d5d6561e25bbce7635a3
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Tue Jun 11 14:08:51 2024 +0800

    [fix](nereids)decimal and datetime literal comparison should compare 
datatype too (#36065)
    
    pick from master #36055
    
    this pr revert #35961 and fix the bug in correct way.
    
    The root cause is decimal literal's comparison only compare value, we 
should also compare their datatype as well as datetime literal.
    
    suppose
    a=0 with type decimal(2,1)
    b=0 with type decimal(3,1)
    we have:
    a.equals(b) returns false
---
 .../rewrite/ExtractAndNormalizeWindowExpression.java     |  3 +--
 .../trees/expressions/literal/DateTimeV2Literal.java     | 16 ++++++++++++++++
 .../trees/expressions/literal/DecimalLiteral.java        | 15 +++++++++++++++
 .../trees/expressions/literal/DecimalV3Literal.java      | 15 +++++++++++++++
 .../nereids/rules/expression/ExpressionRewriteTest.java  |  8 ++++----
 .../trees/expressions/literal/DateTimeLiteralTest.java   | 14 +++++++-------
 6 files changed, 58 insertions(+), 13 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ExtractAndNormalizeWindowExpression.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ExtractAndNormalizeWindowExpression.java
index 20d1662cfc7..383ad266511 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ExtractAndNormalizeWindowExpression.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ExtractAndNormalizeWindowExpression.java
@@ -66,8 +66,7 @@ public class ExtractAndNormalizeWindowExpression extends 
OneRewriteRuleFactory i
 
             // 1. handle bottom projects
             Set<Alias> existedAlias = ExpressionUtils.collect(outputs, 
Alias.class::isInstance);
-            Set<Expression> toBePushedDown = 
collectExpressionsToBePushedDown(outputs.stream()
-                    .filter(expr -> 
!expr.isConstant()).collect(Collectors.toList()));
+            Set<Expression> toBePushedDown = 
collectExpressionsToBePushedDown(outputs);
             NormalizeToSlotContext context = 
NormalizeToSlotContext.buildContext(existedAlias, toBePushedDown);
             // set toBePushedDown exprs as NamedExpression, e.g. (a+1) -> 
Alias(a+1)
             Set<NamedExpression> bottomProjects = 
context.pushDownToNamedExpression(toBePushedDown);
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 ed6126fb781..784167c81ca 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
@@ -28,6 +28,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
@@ -219,4 +220,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 03973fe6b03..1d0281796ba 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 Literal {
                             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 403eeba3904..a7c9813fe5d 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 Literal {
                             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 de859058ecc..434e04c0f0c 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
@@ -200,13 +200,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/trees/expressions/literal/DateTimeLiteralTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteralTest.java
index 3ff030400e7..a7553ef658b 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
@@ -426,32 +426,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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to