From 7209a4901eaea0aafc1a30858c7a1fb78b470eda Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:19:48 +0800 Subject: [PATCH] [BugFix] Fix decimal literal equals uncheck type (backport #50626) (#50661) Co-authored-by: Seaven --- .../java/com/starrocks/analysis/DecimalLiteral.java | 6 ++++++ .../java/com/starrocks/sql/plan/DecimalTypeTest.java | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/analysis/DecimalLiteral.java b/fe/fe-core/src/main/java/com/starrocks/analysis/DecimalLiteral.java index 0555aa1f3de2e..736b2c33e61b6 100644 --- a/fe/fe-core/src/main/java/com/starrocks/analysis/DecimalLiteral.java +++ b/fe/fe-core/src/main/java/com/starrocks/analysis/DecimalLiteral.java @@ -492,4 +492,10 @@ public Expr uncheckedCastTo(Type targetType) throws AnalysisException { public int hashCode() { return Objects.hash(super.hashCode(), value); } + + @Override + public boolean equals(Object obj) { + return super.equals(obj) && (type.matchesType(((LiteralExpr) obj).getType())); + } + } diff --git a/fe/fe-core/src/test/java/com/starrocks/sql/plan/DecimalTypeTest.java b/fe/fe-core/src/test/java/com/starrocks/sql/plan/DecimalTypeTest.java index 8a494246a7d23..146ace5d5366f 100644 --- a/fe/fe-core/src/test/java/com/starrocks/sql/plan/DecimalTypeTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/sql/plan/DecimalTypeTest.java @@ -172,4 +172,15 @@ public void testExpressionRangeCheck() throws Exception { String plan = getFragmentPlan(sql); assertContains(plan, "PREDICATES: 4: c_1_3 <= 1000"); } + + @Test + public void testSameValueDiffTypeDecimal() throws Exception { + String sql = "SELECT t1a,\n" + + " sum(t1f * 1.00000000000) / NULLIF(sum(t1c), 0) AS aaaa,\n" + + " sum(t1f * 1.000) / NULLIF(sum(t1d * 1.000), 0) * 1000 AS bbbb\n" + + " FROM test_all_type \n" + + " GROUP BY t1a;\n "; + String plan = getFragmentPlan(sql); + assertContains(plan, " : 6: t1f * 1.0\n"); + } }