This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new b381df42c23 branch-4.2: [fix](fe) Handle unqualified function names in
hashCode #70346 (#70898)
b381df42c23 is described below
commit b381df42c238494619804768a2f0fa3237e08c01
Author: yujun <[email protected]>
AuthorDate: Tue Nov 24 18:46:57 2026 +0800
branch-4.2: [fix](fe) Handle unqualified function names in hashCode #70346
(#70898)
cherry-pick: #70346
---
.../org/apache/doris/analysis/FunctionName.java | 3 +-
.../apache/doris/analysis/FunctionNameTest.java | 79 ++++++++++++++++++++++
.../partition_expr_failure_diagnostic.out | 4 ++
.../partition_expr_failure_diagnostic.groovy | 63 +++++++++++++++++
4 files changed, 148 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionName.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionName.java
index 1f31fa11ac0..80f2a4e6fd9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionName.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionName.java
@@ -147,7 +147,8 @@ public class FunctionName {
@Override
public int hashCode() {
- return 31 * Objects.hashCode(db) + Objects.hashCode(fn);
+ return 31 * Objects.hashCode(db == null ? null : db.toLowerCase())
+ + Objects.hashCode(fn == null ? null : fn.toLowerCase());
}
@Override
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/analysis/FunctionNameTest.java
b/fe/fe-core/src/test/java/org/apache/doris/analysis/FunctionNameTest.java
new file mode 100644
index 00000000000..7c0f7096a2a
--- /dev/null
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/FunctionNameTest.java
@@ -0,0 +1,79 @@
+// 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.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.mtmv.MTMVPartitionInfo;
+import org.apache.doris.mtmv.MTMVPartitionInfo.MTMVPartitionType;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+class FunctionNameTest {
+ @Test
+ void testUnqualifiedFunctionHashCode() {
+ FunctionName name = new FunctionName("date_trunc");
+ FunctionName sameName = new FunctionName(null, "DATE_TRUNC");
+ FunctionName builtinName =
FunctionName.createBuiltinName("DATE_TRUNC");
+ Assertions.assertEquals(name, sameName);
+ Assertions.assertEquals(name, builtinName);
+ Assertions.assertEquals(name.hashCode(), sameName.hashCode());
+ Assertions.assertEquals(name.hashCode(), builtinName.hashCode());
+ Set<FunctionName> names = new HashSet<>();
+ names.add(name);
+ Assertions.assertTrue(names.contains(sameName));
+ Assertions.assertTrue(names.contains(builtinName));
+ Assertions.assertFalse(names.contains(new FunctionName("abs")));
+ }
+
+ @Test
+ void testQualifiedFunctionHashCode() {
+ FunctionName name = new FunctionName("test_db", "my_func");
+ FunctionName sameName = new FunctionName("TEST_DB", "MY_FUNC");
+ Assertions.assertEquals(name, sameName);
+ Assertions.assertEquals(name.hashCode(), sameName.hashCode());
+ Assertions.assertEquals(31 * "test_db".hashCode() +
"my_func".hashCode(), name.hashCode());
+ Assertions.assertNotEquals(name, new FunctionName("my_func"));
+ Assertions.assertNotEquals(new FunctionName("my_func"), name);
+ }
+
+ @Test
+ void testFunctionCallExprHashCode() {
+ FunctionCallExpr expr = dateTruncExpr();
+ FunctionCallExpr sameExpr = dateTruncExpr();
+ Assertions.assertEquals(expr, sameExpr);
+ Assertions.assertEquals(expr.hashCode(), sameExpr.hashCode());
+ }
+
+ @Test
+ void testMvPartitionInfoDiagnosticFormatting() {
+ MTMVPartitionInfo partitionInfo = new
MTMVPartitionInfo(MTMVPartitionType.EXPR, "data_date");
+ partitionInfo.setExpr(dateTruncExpr());
+ String diagnostic = Assertions.assertDoesNotThrow(
+ () -> String.format("mv partition info is %s", partitionInfo));
+ Assertions.assertTrue(diagnostic.startsWith("mv partition info is " +
MTMVPartitionInfo.class.getName()));
+ }
+
+ private FunctionCallExpr dateTruncExpr() {
+ return new FunctionCallExpr("date_trunc", ImmutableList.of(
+ new SlotRef(null, "data_date"), new StringLiteral("day")));
+ }
+}
diff --git
a/regression-test/data/nereids_rules_p0/mv/union_rewrite/partition_expr_failure_diagnostic.out
b/regression-test/data/nereids_rules_p0/mv/union_rewrite/partition_expr_failure_diagnostic.out
new file mode 100644
index 00000000000..7fc994036fb
--- /dev/null
+++
b/regression-test/data/nereids_rules_p0/mv/union_rewrite/partition_expr_failure_diagnostic.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !result --
+2
+
diff --git
a/regression-test/suites/nereids_rules_p0/mv/union_rewrite/partition_expr_failure_diagnostic.groovy
b/regression-test/suites/nereids_rules_p0/mv/union_rewrite/partition_expr_failure_diagnostic.groovy
new file mode 100644
index 00000000000..4d7b87e6664
--- /dev/null
+++
b/regression-test/suites/nereids_rules_p0/mv/union_rewrite/partition_expr_failure_diagnostic.groovy
@@ -0,0 +1,63 @@
+// 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("partition_expr_failure_diagnostic") {
+ sql "DROP MATERIALIZED VIEW IF EXISTS partition_expr_failure_mv"
+ sql "DROP TABLE IF EXISTS partition_expr_failure_t1"
+ sql "DROP TABLE IF EXISTS partition_expr_failure_t2"
+ sql """CREATE TABLE partition_expr_failure_t1 (
+ data_date DATETIME NOT NULL, slot_id VARCHAR(255) NULL, num INT NULL
+ ) DUPLICATE KEY(data_date, slot_id)
+ PARTITION BY RANGE(data_date) (
+ FROM ('2024-09-01') TO ('2024-09-30') INTERVAL 1 DAY
+ ) DISTRIBUTED BY HASH(data_date, slot_id) BUCKETS 2
+ PROPERTIES ('replication_num' = '1')"""
+ sql "CREATE TABLE partition_expr_failure_t2 LIKE partition_expr_failure_t1"
+ sql """INSERT INTO partition_expr_failure_t1 VALUES
+ ('2024-09-12 00:20:00', 'a', 1), ('2024-09-13 00:20:00', 'b', 1)"""
+ sql """INSERT INTO partition_expr_failure_t2 VALUES
+ ('2024-09-12 00:20:00', 'a', 1), ('2024-09-13 00:20:00', 'b', 1)"""
+ sql """CREATE MATERIALIZED VIEW partition_expr_failure_mv
+ BUILD IMMEDIATE REFRESH AUTO ON MANUAL
+ PARTITION BY (date_trunc(data_date, 'day'))
+ DISTRIBUTED BY HASH(data_date) BUCKETS 2
+ PROPERTIES ('replication_num' = '1')
+ AS SELECT date_trunc(t1.data_date, 'day') AS data_date,
+ to_date(t1.data_date) AS dt, t2.slot_id, sum(t1.num) AS num_sum
+ FROM partition_expr_failure_t1 t1 INNER JOIN partition_expr_failure_t2
t2
+ ON t1.data_date = t2.data_date
+ GROUP BY date_trunc(t1.data_date, 'day'), to_date(t1.data_date),
t2.slot_id"""
+ waitingMTMVTaskFinishedByMvName("partition_expr_failure_mv")
+ sql "REFRESH MATERIALIZED VIEW partition_expr_failure_mv COMPLETE"
+ waitingMTMVTaskFinishedByMvName("partition_expr_failure_mv")
+
+ // Make one partition stale so rewrite needs partition compensation.
+ sql "INSERT INTO partition_expr_failure_t1 VALUES ('2024-09-12 00:30:00',
'a', 2)"
+ String query = """SELECT sum(t1.num)
+ FROM partition_expr_failure_t1 t1 INNER JOIN partition_expr_failure_t2
t2
+ ON t1.data_date = t2.data_date
+ WHERE to_date(t1.data_date) >= '2024-09-12'"""
+ // MEMO PLAN evaluates the detailed failure supplier, which formats the
partition expression.
+ // Check that diagnosis completes, rather than only checking the fallback
query result:
+ // the rewrite rule catches exceptions, so the query can succeed even with
the hashCode bug.
+ explain {
+ sql "MEMO PLAN ${query}"
+ contains "need compensate union all, but can not, because the query
structInfo"
+ contains "mv partition info is
org.apache.doris.mtmv.MTMVPartitionInfo@"
+ }
+ order_qt_result query
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]