github-actions[bot] commented on code in PR #62628: URL: https://github.com/apache/doris/pull/62628#discussion_r3110714806
########## regression-test/suites/nereids_p0/hash_shuffle_key_prune/join_parent.groovy: ########## @@ -0,0 +1,247 @@ +// 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. + +// =========================================================================================== +// Category 06: Join Paths and Parent Requests — J01-J12, P01-P02 +// =========================================================================================== +// +// Purpose +// Validate the interaction between Shuffle Key Pruning and Join operators, and verify the correctness of +// Parent Requests (where the parent asks the child to adjust its shuffle key to remove extra exchanges). +// +// Core Background +// - When Agg output is consumed by Join, the Agg shuffle key can be adjusted to a subset of the Join keys, +// avoiding the re-shuffle exchange before the Join. +// - tByB = distributed by hash(b) -> if group by includes b, distribution may already be satisfied -> no pruning +// - tByX = distributed by hash(x) -> x is not in group by -> shuffle is required -> pruning is possible +// +// J Group Case List +// J01: scan JOIN agg(tByB) -> distribution already satisfied -> no pruning (negative) +// J02: scan JOIN agg(tByX) -> shuffle required -> pruning works (positive) +// J03: agg(tByB) JOIN agg(tByB) -> both sides already satisfied -> no pruning (negative) +// J04: agg(tByX) JOIN agg(tByX) -> both sides require shuffle -> pruning works (positive) +// J05: LEFT JOIN + agg(tByX) -> same as J02 -> pruning works (positive) +// J06: LEFT SEMI JOIN -> pruning works (positive) +// J07: LEFT ANTI JOIN -> pruning works (positive) +// J08: agg(tByB) JOIN scan on a non-group-by column -> requirement not satisfied -> no pruning (negative) +// J09: scan JOIN scan -> no agg -> no pruning (negative) +// J10: agg on join output + all skewed columns -> no safe key -> no pruning (negative) +// J11: parent-key-subset positive case -> agg shuffle key is adjusted to a subset of join keys +// J12: parent-key-subset negative case -> low-NDV columns do not qualify -> no adjustment +// +// P Group Case List +// P01: subquery agg -> parent agg -> inner distribution already satisfied -> no pruning (negative) +// P02: subquery agg -> window(partition by) -> inner distribution already satisfied -> no pruning (negative) +// +// Validation +// Use run() to check orderedShuffledColumns changes; +// use runParent() to check how agg_shuffle_use_parent_key adjusts shuffle keys. +// =========================================================================================== +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 qn = (tptn*512 + tptn*64).toString() + def ln = "4" + def R = "480000" + def esc = { Object v -> v==null?"null":v.toString().replace("\\","\\\\").replace("'","\\'") } + def ss = { String t,String c,String n,String nn,String ds,String mi,String ma,String hv -> + def hvc = hv==null ? "" : ", 'hot_values'='${esc(hv)}'" + sql "alter table ${t} modify column ${c} set stats ('row_count'='${R}','ndv'='${esc(n)}','num_nulls'='${esc(nn)}','data_size'='${esc(ds)}','min_value'='${esc(mi)}','max_value'='${esc(ma)}'${hvc});" + } + def extractSigns = { String e -> + def s=[]; def m=(e=~/orderedShuffledColumns=\[([0-9,\s-]*)\]/); while(m.find()){s<<"["+m.group(1).replaceAll("\\s+","")+"]"}; s + } + def extractSingle = { String e -> + def ids=[]; def m=(e=~/orderedShuffledColumns=\[([0-9,\s-]*)\]/) + while(m.find()){def r=m.group(1).trim(); if(r.length()==0)continue; def p=r.split(",").collect{it.trim()}.findAll{it.length()>0}; if(p.size()==1)ids<<Integer.parseInt(p[0])}; ids + } + def exprId = { String e,String c -> def m=(e=~("\\b"+java.util.regex.Pattern.quote(c)+"#(\\d+)\\b")); m.find()?Integer.parseInt(m.group(1)):null } + def norm = { rows -> rows.collect{r->r.collect{v->v==null?"NULL":v.toString()}.join("||")}.sort() } + def parseOrderedIds = { String line -> + def m = (line =~ /orderedShuffledColumns=\[([0-9,\s-]*)\]/) + if (!m.find()) { + return null + } + def r = m.group(1).trim() + return (r.length() == 0) ? Collections.emptyList() + : r.split(",").collect { it.trim() }.findAll { it.length() > 0 }.collect { Integer.parseInt(it) } + } + def findGlobalAggChildShuffleIds = { String e -> + def lines = e.readLines() + for (int i = 0; i < lines.size(); i++) { + def line = lines[i] + if (!(line.contains("PhysicalHashAggregate") && line.contains("aggPhase=GLOBAL"))) { + continue + } + int aggIndent = line.indexOf("PhysicalHashAggregate") + for (int j = i + 1; j < lines.size(); j++) { + def childLine = lines[j] + int childIndent = childLine.indexOf("Physical") + if (childIndent < 0) { + continue + } + if (childIndent <= aggIndent) { + break + } + if (childLine.contains("PhysicalDistribute") && childLine.contains("orderedShuffledColumns=")) { + return parseOrderedIds(childLine) + } + } + } + return null + } + def assertGlobalAggChildCols = { String id, String e, List<String> cols -> + def actualIds = findGlobalAggChildShuffleIds(e) + assertTrue(actualIds != null, "${id}: missing agg-side PhysicalDistribute") + def expectedIds = cols.collect { c -> + def eid = exprId(e, c) Review Comment: `exprId(e, c)` here is using a whole-plan first-match lookup, while `findGlobalAggChildShuffleIds()` returns the first GLOBAL agg child exchange it sees. In these join/subquery plans the same column names exist on multiple branches, so this assertion can compare ExprIds from different nodes and either fail spuriously or pass without checking the intended exchange. Please derive the expected ExprIds from the target agg child itself, or otherwise scope the search to that subtree. ########## regression-test/suites/nereids_p0/hash_shuffle_key_prune/window_distinct_regression.groovy: ########## @@ -0,0 +1,234 @@ +// 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. + +// =========================================================================================== +// Category 09: Window / Distinct Regression — WD01-WD04 +// =========================================================================================== +// +// Purpose +// Add a more focused regression set for window / distinct patterns: +// - Window guard: ensure pruning is not triggered incorrectly under window wrappers +// - Distinct + Window: ensure DISTINCT aggregation keeps the correct prune / no-prune behavior when wrapped by a window +// +// Case List +// WD01: window over inner agg, child distribution already satisfied -> no pruning (negative) +// WD02: count(distinct) + window, high NDV -> pruning works (positive) +// WD03: count(distinct) + avg + window, high NDV -> pruning still works (positive) +// WD04: count(distinct) + window, low NDV -> no pruning (negative) +// =========================================================================================== +suite("window_distinct_regression", "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;""" + sql """set agg_shuffle_use_parent_key=false;""" + + 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 highNdv = (tptn * 512 + tptn * 64).toString() + def lowNdv = "4" + def rowCount = "480000" + def esc = { Object v -> v == null ? "null" : v.toString().replace("\\", "\\\\").replace("'", "\\'") } + def ss = { String t, String c, String n, String nn, String ds, String mi, String ma, String hv -> + def hvc = 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)}'${hvc});" + } + def extractSigns = { String e -> + def s = [] + def m = (e =~ /orderedShuffledColumns=\[([0-9,\s-]*)\]/) + while (m.find()) { + s << "[" + m.group(1).replaceAll("\\s+", "") + "]" + } + s + } + def extractSingle = { String e -> + def ids = [] + def m = (e =~ /orderedShuffledColumns=\[([0-9,\s-]*)\]/) + while (m.find()) { + def r = m.group(1).trim() + if (r.length() == 0) continue + def p = r.split(",").collect { it.trim() }.findAll { it.length() > 0 } + if (p.size() == 1) ids << Integer.parseInt(p[0]) + } + ids + } + def extractIdLists = { String e -> + def ids = [] + def m = (e =~ /orderedShuffledColumns=\[([0-9,\s-]*)\]/) + while (m.find()) { + def r = m.group(1).trim() + ids << (r.length() == 0 ? [] : r.split(",").collect { it.trim() }.findAll { it.length() > 0 }.collect { Integer.parseInt(it) }) + } + ids + } + def exprId = { String e, String c -> + def m = (e =~ ("\\b" + java.util.regex.Pattern.quote(c) + "#(\\d+)\\b")) + m.find() ? Integer.parseInt(m.group(1)) : null + } + def assertDistinctShufflePrunedToSingle = { String id, String eOff, String eOn, String c -> + def offIds = extractIdLists(eOff) Review Comment: This helper counts any shuffle list containing `a` anywhere in the full explain output. With the window wrapper there can be multiple hash exchanges or partitioning requests, while `ShuffleKeyPruner` only rewrites the target agg-side distribute. That makes WD02/WD03 brittle and can also let the test pass without proving the intended node changed. ########## regression-test/suites/nereids_p0/hash_shuffle_key_prune/distinct_mixed.groovy: ########## @@ -0,0 +1,194 @@ +// 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. + +// =========================================================================================== +// Category 08: Distinct Partition and Mixed Join — DA01-DA05, M01-M03 +// =========================================================================================== +// +// Purpose +// Validate two kinds of special scenarios: +// A. COUNT(DISTINCT) cases: DISTINCT introduces an extra partition operator, so pruning must optimize +// both the partition and agg shuffle keys +// B. Mixed Join: pruning behavior when Agg hot_values and Join probe-side hot_values=null are mixed +// +// DA Group Case List +// DA01: High NDV + COUNT(DISTINCT g) + agg_phase=2 -> pruning works (positive) +// DA02: Low NDV + COUNT(DISTINCT g) -> NDV is insufficient -> no pruning (negative) +// DA03: Mixed COUNT(DISTINCT g) + AVG(v) aggregation -> pruning still works (positive) +// DA04: agg_phase=4 (2+2 mode) -> pruning still works (positive) +// DA05: count(distinct [skew] g) -> explicit skew-distinct guard -> no pruning (negative) +// +// M Group Case List +// M01: t_08_m_agg (hot_values='') JOIN t_08_m_probe (hot_values=null) +// join on 6 columns = group by 6 columns -> conservative -> plan unchanged (negative) +// M02: join on 3 columns < group by 6 columns, but probe-side hot_values=null -> conservative -> plan unchanged (negative) +// M03: Probe side uses an agg table with hot_values=null -> conservative -> plan unchanged (negative) +// +// Validation +// Both DA and M groups use hard assertions. +// Every case verifies that OFF/ON results are identical. +// =========================================================================================== +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 qn = (tptn*512 + tptn*64).toString() + def R = "480000" + def lowNdv = "4" + def daQn = "60000" + def esc = { Object v -> v==null?"null":v.toString().replace("\\","\\\\").replace("'","\\'") } + def ss = { String t,String c,String n,String nn,String ds,String mi,String ma,String hv -> + def hvc = hv==null ? "" : ", 'hot_values'='${esc(hv)}'" + sql "alter table ${t} modify column ${c} set stats ('row_count'='${R}','ndv'='${esc(n)}','num_nulls'='${esc(nn)}','data_size'='${esc(ds)}','min_value'='${esc(mi)}','max_value'='${esc(ma)}'${hvc});" + } + def extractSigns = { String e -> + def s=[]; def m=(e=~/orderedShuffledColumns=\[([0-9,\s-]*)\]/); while(m.find()){s<<"["+m.group(1).replaceAll("\\s+","")+"]"}; s + } + def extractIdLists = { String e -> + def ids=[]; def m=(e=~/orderedShuffledColumns=\[([0-9,\s-]*)\]/) + while(m.find()){ + def r=m.group(1).trim() + ids << (r.length()==0 ? [] : r.split(",").collect{it.trim()}.findAll{it.length()>0}.collect{Integer.parseInt(it)}) + } + ids + } + def exprId = { String e,String c -> def m=(e=~("\\b"+java.util.regex.Pattern.quote(c)+"#(\\d+)\\b")); m.find()?Integer.parseInt(m.group(1)):null } + 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") } + + // DA-group test helper + def runDA = { String id,String q,boolean expChg,int ap -> + sql "set agg_phase=${ap};"; sql "set disable_nereids_rules='';" + sql "set enable_shuffle_key_prune=false;" + def eOff=explainText(q); def oS=extractSigns(eOff); def offIds=extractIdLists(eOff) + sql "set enable_shuffle_key_prune=true;" + def eOn=explainText(q); def nS=extractSigns(eOn); def onIds=extractIdLists(eOn) + def chg=(eOff!=eOn) + logger.info("${id}: oS=${oS}, nS=${nS}, offIds=${offIds}, onIds=${onIds}, changed=${chg}") + if(expChg){ + assertTrue(chg,"${id}: signs should change") + assertTrue(!offIds.isEmpty() && offIds.size()==onIds.size(), "${id}: expected matching hash-shuffle lists, got off=${offIds}, on=${onIds}") + assertTrue(offIds.any{it.size()>1}, "${id}: expected at least one multi-key shuffle before pruning, got ${offIds}") + def target = exprId(eOn, "a") + assertTrue(target!=null, "${id}: missing exprId for a") + assertTrue(onIds.every{it.size()==1 && it[0]==target}, Review Comment: `extractIdLists(eOn)` is collecting every `orderedShuffledColumns=[...]` in the plan, but `ShuffleKeyPruner` only rewrites the specific distribute under the prunable DISTINCT/global-agg path. Requiring `onIds.every { ... }` to collapse all of them to `[a]` is too broad: unrelated exchanges can make this fail, and a passing result still does not prove the target distribute was the one that changed. Please anchor the check to the DISTINCT-global child distribute instead of the full explain text. ########## regression-test/suites/nereids_p0/hash_shuffle_key_prune/expr_bucket.groovy: ########## @@ -0,0 +1,170 @@ +// 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. + +// =========================================================================================== +// Category 05: Expression Keys and Bucket Variations — EX01-EX04, BK01-BK02 +// =========================================================================================== +// +// Purpose +// Validate the following two categories: +// A. Expression Keys: pruning behavior when GROUP BY contains expressions rather than plain column references +// B. Bucket-count variations: how different bucket counts affect pruning logic +// +// EX Group Case List +// EX01: cast(b as bigint) -> type cast folds back to the original slot -> pruning works normally (positive) +// EX02: substr(s_key,1,8) -> string slicing creates an expression slot -> can be selected (positive) +// Columns b, c, d, and e are injected with 80% skew to ensure they are excluded +// EX03: coalesce(null_k,-1) -> unknown stats -> uncertainty -> no pruning (negative) +// EX04: date_trunc(dt_key,'day') -> unstable distribution -> no pruning (negative) +// +// BK Group Case List +// BK01: 1-bucket table -> pruning still works (positive) +// BK02: 32-bucket table -> pruning still works (positive) +// Note: bucket count does not affect pruning logic (pruning applies to shuffle exchange and is independent of buckets) +// +// Validation +// Check changes in orderedShuffledColumns in the plan and verify result consistency. +// =========================================================================================== +suite("expr_bucket", "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 R = "480000" + def nullSkew = "48000" + def esc = { Object v -> v==null?"null":v.toString().replace("\\","\\\\").replace("'","\\'") } + def ss = { String t,String c,String n,String nn,String ds,String mi,String ma,String hv -> + def hvc = hv==null ? "" : ", 'hot_values'='${esc(hv)}'" + sql "alter table ${t} modify column ${c} set stats ('row_count'='${R}','ndv'='${esc(n)}','num_nulls'='${esc(nn)}','data_size'='${esc(ds)}','min_value'='${esc(mi)}','max_value'='${esc(ma)}'${hvc});" + } + def extractSigns = { String e -> + def s=[]; def m=(e=~/orderedShuffledColumns=\[([0-9,\s-]*)\]/); while(m.find()){s<<"["+m.group(1).replaceAll("\\s+","")+"]"}; s + } + def extractSingle = { String e -> + def ids=[]; def m=(e=~/orderedShuffledColumns=\[([0-9,\s-]*)\]/) + while(m.find()){def r=m.group(1).trim(); if(r.length()==0)continue; def p=r.split(",").collect{it.trim()}.findAll{it.length()>0}; if(p.size()==1)ids<<Integer.parseInt(p[0])}; ids + } + def norm = { rows -> rows.collect{r->r.collect{v->v==null?"NULL":v.toString()}.join("||")}.sort() } + + def runEx = { String id,String q,int ap,boolean single,boolean reqShuffle,Boolean expChg,String sel,def exc -> + def exprId = { String e,String c -> def m=(e=~("\\b"+java.util.regex.Pattern.quote(c)+"#(\\d+)\\b")); m.find()?Integer.parseInt(m.group(1)):null } + sql "set agg_phase=${ap};"; sql "set disable_nereids_rules='';" + sql "set enable_shuffle_key_prune=false;" + def eOff=(sql "explain physical plan "+q).toString(); def oS=extractSigns(eOff) + sql "set enable_shuffle_key_prune=true;" + def eOn=(sql "explain physical plan "+q).toString(); def nS=extractSigns(eOn); def si=extractSingle(eOn) + def shouldChg = (expChg==null ? single : expChg) + if(shouldChg){assertTrue(oS.toString()!=nS.toString(),"${id}: signs should change"); if(single)assertTrue(si.size()>0,"${id}: expect single")} + else{assertTrue(oS.toString()==nS.toString(),"${id}: should stay unchanged"); if(reqShuffle)assertTrue(nS.size()>0,"${id}: need shuffle")} + if(sel!=null){def eid=exprId(eOn,sel); assertTrue(eid!=null&&si.contains(eid),"${id}: ${sel} not selected")} + exc.each{c->def eid=exprId(eOn,c); if(eid!=null)assertTrue(!si.contains(eid),"${id}: ${c} excluded")} + sql "set enable_shuffle_key_prune=false;"; def rOff=sql q + sql "set enable_shuffle_key_prune=true;"; def rOn=sql q + assertTrue(norm(rOff)==norm(rOn),"${id}: results differ") + logger.info("${id}: oS=${oS}, nS=${nS}, si=${si}") + } + + // ===== EX group table setup ===== + sql "drop table if exists t_05_expr;" + sql """create table t_05_expr (x bigint, b bigint, c bigint, d bigint, e bigint, + s_key string, null_k bigint, dt_key datetimev2(0), v bigint) + duplicate key(x) distributed by hash(x) buckets 4 properties ("replication_num"="1");""" + sql """insert into t_05_expr select + (bitand(murmur_hash3_32(concat(cast(number as string),'_x')),2147483647)%12000)*100000+1, + (bitand(murmur_hash3_32(concat(cast(number as string),'_b')),2147483647)%5200)*100000+2, + (bitand(murmur_hash3_32(concat(cast(number as string),'_c')),2147483647)%5600)*100000+3, + (bitand(murmur_hash3_32(concat(cast(number as string),'_d')),2147483647)%6000)*100000+4, + (bitand(murmur_hash3_32(concat(cast(number as string),'_e')),2147483647)%6400)*100000+5, + concat('expr_',cast(number%6800 as string)), + if(number%20==0,null,number%7200+1), + cast(concat('2024-01-',lpad(cast(((number%28)+1) as string),2,'0'),' 00:00:00') as datetimev2(0)), + number from numbers("number"="2000");""" + + def applyExpr = { Map<String,String> hv -> + ss("t_05_expr","x","12000","0","1600000","100001","1199900001","") + ss("t_05_expr","b","5200","0","1600000","2","519900002",hv.getOrDefault("b","")) + ss("t_05_expr","c","5600","0","1600000","3","559900003",hv.getOrDefault("c","")) + ss("t_05_expr","d","6000","0","1600000","4","599900004",hv.getOrDefault("d","")) + ss("t_05_expr","e","6400","0","1600000","5","639900005",hv.getOrDefault("e","")) + ss("t_05_expr","s_key","6800","0","6400000","expr_0","expr_6799",hv.getOrDefault("s_key","")) + ss("t_05_expr","null_k","7200",nullSkew,"1600000","1","7200",hv.getOrDefault("null_k","")) + ss("t_05_expr","dt_key","28","0","1600000","2024-01-01 00:00:00","2024-01-28 00:00:00",hv.getOrDefault("dt_key","")) + ss("t_05_expr","v","60000","0","1600000","0","1999","") + } + def guard = ["b":"2 :0.8","c":"3 :0.8","d":"4 :0.8","e":"5 :0.8"] as Map<String,String> + + // EX01: cast(b as bigint) -> folds back to a slot -> prune + applyExpr([:] as Map<String,String>) + runEx("EX01","select cast(b as bigint) as b1,c,d,e,s_key,sum(v) from t_05_expr group by cast(b as bigint),c,d,e,s_key",0,true,true,true,null,[]) + + // EX02: substr -> expression slot -> can be selected + applyExpr(guard) + runEx("EX02","select substr(s_key,1,8) as s8,b,c,d,e,sum(v) from t_05_expr group by substr(s_key,1,8),b,c,d,e",0,true,true,true,"s8",["b","c","d","e"]) + + // EX03: coalesce -> unknown stats -> no pruning + applyExpr(guard) + runEx("EX03","select coalesce(null_k,-1) as nk,b,c,d,e,sum(v) from t_05_expr group by coalesce(null_k,-1),b,c,d,e",0,false,true,false,null,[]) + + // EX04: date_trunc -> unstable -> no pruning + applyExpr(guard) + runEx("EX04","select date_trunc(dt_key,'day') as day_k,b,c,d,e,sum(v) from t_05_expr group by date_trunc(dt_key,'day'),b,c,d,e",0,false,true,false,null,[]) Review Comment: This case is not validating the behavior described in the comment. `ShuffleKeyPruneUtils.selectOptimalShuffleKeys()` only reasons about `SlotReference`s and does not have a special `date_trunc` or "unstable distribution" guard, so a no-prune result here would come from some indirect slot or stats property instead. Please tighten the assertion to the real contract being exercised, or drop the claim that EX04 covers a dedicated `date_trunc` no-prune path. -- 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]
