This is an automated email from the ASF dual-hosted git repository.
yujun777 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 49323a0219d [fix](fe) Handle unqualified function names in hashCode
(#70346)
49323a0219d is described below
commit 49323a0219d0220c0a44377bf320f4c39514ad13
Author: yujun <[email protected]>
AuthorDate: Wed Nov 18 20:05:04 2026 +0800
[fix](fe) Handle unqualified function names in hashCode (#70346)
Function names can omit a database name, as built-in functions normally
do. Function expressions and materialized view partition metadata
include these names in their hash codes.
### What problem does this PR solve?
Issue Number: None
Related PR: None
PR Type: Bugfix
Problem Summary:
Formatting materialized view partition metadata while recording a
rewrite failure can throw a NullPointerException when the partition
expression contains an unqualified function such as `date_trunc`. Handle
the absent database name in `FunctionName.hashCode()` so the existing
diagnostic path completes normally.
---
.../org/apache/doris/catalog/FunctionName.java | 2 +-
.../org/apache/doris/catalog/FunctionNameTest.java | 82 ++++++++++++++++++++++
.../partition_expr_failure_diagnostic.out | 4 ++
.../partition_expr_failure_diagnostic.groovy | 63 +++++++++++++++++
4 files changed, 150 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-catalog/src/main/java/org/apache/doris/catalog/FunctionName.java
b/fe/fe-catalog/src/main/java/org/apache/doris/catalog/FunctionName.java
index 51ac69a3f4a..53a62751ce3 100644
--- a/fe/fe-catalog/src/main/java/org/apache/doris/catalog/FunctionName.java
+++ b/fe/fe-catalog/src/main/java/org/apache/doris/catalog/FunctionName.java
@@ -101,7 +101,7 @@ public class FunctionName {
@Override
public int hashCode() {
- return 31 * Objects.hashCode(db.toLowerCase()) +
Objects.hashCode(fn.toLowerCase());
+ return 31 * Objects.hashCode(db == null ? null : db.toLowerCase()) +
Objects.hashCode(fn.toLowerCase());
}
@Override
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionNameTest.java
b/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionNameTest.java
new file mode 100644
index 00000000000..40c9ab08e26
--- /dev/null
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionNameTest.java
@@ -0,0 +1,82 @@
+// 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.catalog;
+
+import org.apache.doris.analysis.FunctionCallExpr;
+import org.apache.doris.analysis.SlotRef;
+import org.apache.doris.analysis.StringLiteral;
+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")),
true);
+ }
+}
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]