github-actions[bot] commented on code in PR #62628:
URL: https://github.com/apache/doris/pull/62628#discussion_r3122737349


##########
regression-test/suites/nereids_p0/hash_shuffle_key_prune/join_parent.groovy:
##########
@@ -0,0 +1,201 @@
+// 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("join_parent", "agg_shuffle_prune_func") {
+    sql """set enable_nereids_planner=true;"""
+    sql """set enable_fallback_to_original_planner=false;"""
+    sql """set enable_sql_cache=false;"""
+    sql """set enable_query_cache=false;"""
+    sql """set agg_phase=0;"""
+
+    def dbName = context.config.getDbNameByFile(context.file)
+    sql "create database if not exists ${dbName};"
+    sql "use ${dbName};"
+
+    def tptn = 8
+    sql "set parallel_fragment_exec_instance_num=1;"
+    sql "set parallel_pipeline_task_num=${tptn};"
+    sql "set be_number_for_test=1;"
+
+    def rowCount = "480000"
+    def highNdv = (tptn * 512 + tptn * 64).toString()
+    def lowNdv = "4"
+    def esc = { Object v -> v == null ? "null" : v.toString().replace("\\", 
"\\\\").replace("'", "\\'") }
+    def norm = { rows -> rows.collect { r -> r.collect { v -> v == null ? 
"NULL" : v.toString() }.join("||") }.sort() }
+    def explainText = { String q -> (sql "explain physical plan " + q).collect 
{ it[0].toString() }.join("\n") }
+    def shuffleSigns = { String e ->
+        def signs = []
+        def matcher = (e =~ /orderedShuffledColumns=\[([0-9,\s-]*)\]/)
+        while (matcher.find()) {
+            signs << "[" + matcher.group(1).replaceAll("\\s+", "") + "]"
+        }
+        signs
+    }
+    def setStats = { String t, String c, String n, String nn, String ds, 
String mi, String ma, String hv ->
+        def hotValues = hv == null ? "" : ", 'hot_values'='${esc(hv)}'"
+        sql """alter table ${t} modify column ${c} set stats (
+                'row_count'='${rowCount}',
+                'ndv'='${esc(n)}',
+                'num_nulls'='${esc(nn)}',
+                'data_size'='${esc(ds)}',
+                'min_value'='${esc(mi)}',
+                'max_value'='${esc(ma)}'${hotValues});"""
+    }
+    def checkPlanChange = { String id, String q, boolean expectChange ->

Review Comment:
   This helper has the same false-positive problem for the join-to-agg cases: 
`join_scan_to_agg_prune` only needs the agg-side `PhysicalDistribute` under the 
GLOBAL agg to shrink, but here we accept any change in any 
`orderedShuffledColumns` list in the whole plan. If another distribute node 
changes and the agg child remains full-width, the suite still passes. Please 
inspect the agg-side distribute ids directly, like the earlier targeted helper 
or `runJoin` in `join_key_prune.groovy`.



##########
regression-test/suites/nereids_p0/hash_shuffle_key_prune/distinct_mixed.groovy:
##########
@@ -0,0 +1,154 @@
+// 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("distinct_mixed", "agg_shuffle_prune_func") {
+    sql """set enable_nereids_planner=true;"""
+    sql """set enable_fallback_to_original_planner=false;"""
+    sql """set enable_sql_cache=false;"""
+    sql """set enable_query_cache=false;"""
+    sql """set agg_phase=0;"""
+
+    def dbName = context.config.getDbNameByFile(context.file)
+    sql "create database if not exists ${dbName};"
+    sql "use ${dbName};"
+
+    def tptn = 8
+    sql "set parallel_fragment_exec_instance_num=1;"
+    sql "set parallel_pipeline_task_num=${tptn};"
+    sql "set be_number_for_test=1;"
+
+    def rowCount = "480000"
+    def highNdv = (tptn * 512 + tptn * 64).toString()
+    def lowNdv = "4"
+    def esc = { Object v -> v == null ? "null" : v.toString().replace("\\", 
"\\\\").replace("'", "\\'") }
+    def norm = { rows -> rows.collect { r -> r.collect { v -> v == null ? 
"NULL" : v.toString() }.join("||") }.sort() }
+    def explainText = { String q -> (sql "explain physical plan " + q).collect 
{ it[0].toString() }.join("\n") }
+    def shuffleSigns = { String e ->
+        def signs = []
+        def matcher = (e =~ /orderedShuffledColumns=\[([0-9,\s-]*)\]/)
+        while (matcher.find()) {
+            signs << "[" + matcher.group(1).replaceAll("\\s+", "") + "]"
+        }
+        signs
+    }
+    def setStats = { String t, String c, String n, String nn, String ds, 
String mi, String ma, String hv ->
+        def hotValues = hv == null ? "" : ", 'hot_values'='${esc(hv)}'"
+        sql """alter table ${t} modify column ${c} set stats (
+                'row_count'='${rowCount}',
+                'ndv'='${esc(n)}',
+                'num_nulls'='${esc(nn)}',
+                'data_size'='${esc(ds)}',
+                'min_value'='${esc(mi)}',
+                'max_value'='${esc(ma)}'${hotValues});"""
+    }
+    def checkPlanChange = { String id, String q, boolean expectChange ->

Review Comment:
   These DISTINCT cases used to verify the `PhysicalDistribute` directly under 
the DISTINCT/GLOBAL aggregate subtree. After the refactor, this helper only 
compares the complete list of `orderedShuffledColumns` occurrences anywhere in 
the plan. That can still pass on an unrelated `PhysicalDistribute` change while 
the DISTINCT partition key remains unpruned, so `distinct_basic` / 
`distinct_avg_mixed` no longer prove the behavior they describe. Please keep a 
targeted subtree check here, similar to `assertDistinctShufflePrunedToSingle` 
in `window_distinct_regression.groovy`.



##########
regression-test/suites/nereids_p0/hash_shuffle_key_prune/join_parent.groovy:
##########
@@ -0,0 +1,201 @@
+// 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("join_parent", "agg_shuffle_prune_func") {
+    sql """set enable_nereids_planner=true;"""
+    sql """set enable_fallback_to_original_planner=false;"""
+    sql """set enable_sql_cache=false;"""
+    sql """set enable_query_cache=false;"""
+    sql """set agg_phase=0;"""
+
+    def dbName = context.config.getDbNameByFile(context.file)
+    sql "create database if not exists ${dbName};"
+    sql "use ${dbName};"
+
+    def tptn = 8
+    sql "set parallel_fragment_exec_instance_num=1;"
+    sql "set parallel_pipeline_task_num=${tptn};"
+    sql "set be_number_for_test=1;"
+
+    def rowCount = "480000"
+    def highNdv = (tptn * 512 + tptn * 64).toString()
+    def lowNdv = "4"
+    def esc = { Object v -> v == null ? "null" : v.toString().replace("\\", 
"\\\\").replace("'", "\\'") }
+    def norm = { rows -> rows.collect { r -> r.collect { v -> v == null ? 
"NULL" : v.toString() }.join("||") }.sort() }
+    def explainText = { String q -> (sql "explain physical plan " + q).collect 
{ it[0].toString() }.join("\n") }
+    def shuffleSigns = { String e ->
+        def signs = []
+        def matcher = (e =~ /orderedShuffledColumns=\[([0-9,\s-]*)\]/)
+        while (matcher.find()) {
+            signs << "[" + matcher.group(1).replaceAll("\\s+", "") + "]"
+        }
+        signs
+    }
+    def setStats = { String t, String c, String n, String nn, String ds, 
String mi, String ma, String hv ->
+        def hotValues = hv == null ? "" : ", 'hot_values'='${esc(hv)}'"
+        sql """alter table ${t} modify column ${c} set stats (
+                'row_count'='${rowCount}',
+                'ndv'='${esc(n)}',
+                'num_nulls'='${esc(nn)}',
+                'data_size'='${esc(ds)}',
+                'min_value'='${esc(mi)}',
+                'max_value'='${esc(ma)}'${hotValues});"""
+    }
+    def checkPlanChange = { String id, String q, boolean expectChange ->
+        sql "set enable_shuffle_key_prune=false;"
+        def explainOff = explainText(q)
+        sql "set enable_shuffle_key_prune=true;"
+        def explainOn = explainText(q)
+        if (expectChange) {
+            assertTrue(shuffleSigns(explainOff).toString() != 
shuffleSigns(explainOn).toString(),
+                "${id}: expected plan change")
+        } else {
+            assertTrue(shuffleSigns(explainOff).toString() == 
shuffleSigns(explainOn).toString(),
+                "${id}: plan should stay unchanged")
+        }
+        sql "set enable_shuffle_key_prune=false;"
+        def resultOff = sql q
+        sql "set enable_shuffle_key_prune=true;"
+        def resultOn = sql q
+        assertTrue(norm(resultOff) == norm(resultOn), "${id}: results differ")
+    }
+    def checkParentKey = { String id, String q, boolean expectChange ->

Review Comment:
   `agg_shuffle_use_parent_key` is specifically about rewriting the agg child's 
requested hash columns to the parent join-key intersection in 
`RequestPropertyDeriver.shouldUseParent()`. This helper only checks that some 
`orderedShuffledColumns` signature changes somewhere in the plan, so 
`parent_key_subset` can still pass if the wrong subset is chosen or if a 
different distribute node changes. Please assert the exact off/on agg-child 
keys here (`[b,c,d,e,f,g] -> [c,d,e]` for the positive case, unchanged for the 
low-NDV case).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to