This is an automated email from the ASF dual-hosted git repository.
morningman 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 74e3228480d [fix](nereids)fix the cascadesContext.getMemo()==null
(#48771)
74e3228480d is described below
commit 74e3228480df15845a12ce8db2354debb551443e
Author: zhangm365 <[email protected]>
AuthorDate: Fri Mar 14 18:19:36 2025 +0800
[fix](nereids)fix the cascadesContext.getMemo()==null (#48771)
### What problem does this PR solve?
fix the cascadesContext.getMemo() == null, the error:
Cannot invoke "org.apache.doris.nereids.memo.Memo.toString()" because
the return value of "org.apache.doris.nereids.CascadesContext.getMemo()"
is null
---
.../org/apache/doris/nereids/NereidsPlanner.java | 15 ++++--
.../test_insert_table_with_dump_nereids_memo.out | Bin 0 -> 126 bytes
...test_insert_table_with_dump_nereids_memo.groovy | 58 +++++++++++++++++++++
3 files changed, 70 insertions(+), 3 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java
index ab882768d45..56adf5f2f82 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java
@@ -272,8 +272,12 @@ public class NereidsPlanner extends Planner {
// print memo before choose plan.
// if chooseNthPlan failed, we could get memo to debug
if
(cascadesContext.getConnectContext().getSessionVariable().dumpNereidsMemo) {
- String memo = cascadesContext.getMemo().toString();
- LOG.info("{}\n{}", ConnectContext.get().getQueryIdentifier(),
memo);
+ Memo memo = cascadesContext.getMemo();
+ if (memo != null) {
+ LOG.info("{}\n{}", ConnectContext.get().getQueryIdentifier(),
memo.toString());
+ } else {
+ LOG.info("{}\nMemo is null",
ConnectContext.get().getQueryIdentifier());
+ }
}
int nth =
cascadesContext.getConnectContext().getSessionVariable().getNthOptimizedPlan();
PhysicalPlan physicalPlan = chooseNthPlan(getRoot(),
requireProperties, nth);
@@ -696,10 +700,15 @@ public class NereidsPlanner extends Planner {
plan = optimizedPlan.shape("");
break;
case MEMO_PLAN:
- plan = cascadesContext.getMemo().toString()
+ Memo memo = cascadesContext.getMemo();
+ if (memo == null) {
+ plan = "Memo is null";
+ } else {
+ plan = memo.toString()
+ "\n\n========== OPTIMIZED PLAN ==========\n"
+ optimizedPlan.treeString()
+ mvSummary;
+ }
break;
case DISTRIBUTED_PLAN:
StringBuilder distributedPlanStringBuilder = new
StringBuilder();
diff --git
a/regression-test/data/correctness/test_insert_table_with_dump_nereids_memo.out
b/regression-test/data/correctness/test_insert_table_with_dump_nereids_memo.out
new file mode 100644
index 00000000000..a8291e75384
Binary files /dev/null and
b/regression-test/data/correctness/test_insert_table_with_dump_nereids_memo.out
differ
diff --git
a/regression-test/suites/correctness/test_insert_table_with_dump_nereids_memo.groovy
b/regression-test/suites/correctness/test_insert_table_with_dump_nereids_memo.groovy
new file mode 100644
index 00000000000..a51aba93a5a
--- /dev/null
+++
b/regression-test/suites/correctness/test_insert_table_with_dump_nereids_memo.groovy
@@ -0,0 +1,58 @@
+// 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("test_insert_table_with_dump_nereids_memo") {
+
+ def testTable = "test_insert_table_with_dump_nereids_memo"
+ // Clean up any existing table with the same name
+ sql "DROP TABLE IF EXISTS ${testTable}"
+
+ // Create table with with test 'dump_nereids_memo' SessionVariable
+ // set dump_nereids_memo to true
+ sql "set dump_nereids_memo = true"
+
+ // Verify that the variable is set correctly
+ def result = sql "SHOW VARIABLES LIKE 'dump_nereids_memo'"
+ assertTrue(result[0][1] == "true")
+
+ sql """
+ CREATE TABLE ${testTable}
+ (
+ id int,
+ name string
+ )
+ COMMENT "test table with dump_nereids_memo"
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ )
+ """
+
+ // Insert data into the table
+ sql "INSERT INTO ${testTable} VALUES (1, 'hello'), (2, 'world')"
+
+ // Synchronize to ensure data is visible
+ sql "SYNC"
+
+ // Verify that data was inserted correctly
+ qt_select "SELECT * FROM ${testTable} ORDER BY id"
+
+ // Clean up after the test
+ sql "DROP TABLE IF EXISTS ${testTable}"
+ sql "set dump_nereids_memo = false"
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]