From b95c6ee5776fa285f8884e85742ae44021fed4e7 Mon Sep 17 00:00:00 2001 From: Seaven Date: Wed, 4 Sep 2024 10:46:20 +0800 Subject: [PATCH] [BugFix] Fix decimal literal equals uncheck type (#50626) Signed-off-by: Seaven --- .../java/com/starrocks/analysis/DecimalLiteral.java | 2 +- .../java/com/starrocks/sql/plan/DecimalTypeTest.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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 aa070749906bf..534614ea58e12 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 @@ -526,7 +526,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - return super.equals(obj); + return super.equals(obj) && (type.matchesType(((LiteralExpr) obj).getType())); } @Override 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 1bddb8648e1f5..edf06c433a912 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 @@ -275,4 +275,15 @@ public void testDateToDecimal() throws Exception { assertContains(plan, "1:Project\n" + " | : CAST(1: c_0_0 AS DOUBLE) < CAST('1969-12-10 23:46:53' AS DOUBLE)"); } + + @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"); + } }