a2l007 commented on issue #13204: URL: https://github.com/apache/druid/issues/13204#issuecomment-1279607887
Thanks for your insights @gianm From the [Calcite debug logs](https://gist.github.com/a2l007/d84a51a4ced915e57a3adf9bda40a0fa), I see the following activity within the `HepPlanner`: ``` org.apache.calcite.plan.RelOptPlanner - call#0: Apply rule [ReduceExpressionsRule(Project)] to [rel#38:LogicalProject.NONE.[](input=HepRelVertex#37,EXPR$0=$2,countryName=$1)] org.apache.calcite.plan.RelOptPlanner - call#0: Rule ReduceExpressionsRule(Project) arguments [rel#38:LogicalProject.NONE.[](input=HepRelVertex#37,EXPR$0=$2,countryName=$1)] produced LogicalProject#42 org.apache.calcite.plan.RelOptPlanner - call#1: Apply rule [ReduceExpressionsRule(Project)] to [rel#42:LogicalProject.NONE.[](input=HepRelVertex#37,EXPR$0=$2,countryName=CAST('Indonesia':VARCHAR):VARCHAR)] org.apache.calcite.plan.RelOptPlanner - call#2: Apply rule [ReduceExpressionsRule(Project)] to [rel#34:LogicalProject.NONE.[](input=HepRelVertex#33,$f0=FLOOR($0, FLAG(MONTH)),countryName=$3,added=$1)] org.apache.calcite.plan.RelOptPlanner - call#2: Rule ReduceExpressionsRule(Project) arguments [rel#34:LogicalProject.NONE.[](input=HepRelVertex#33,$f0=FLOOR($0, FLAG(MONTH)),countryName=$3,added=$1)] produced LogicalProject#44 org.apache.calcite.plan.RelOptPlanner - call#3: Apply rule [ReduceExpressionsRule(Project)] to [rel#44:LogicalProject.NONE.[](input=HepRelVertex#33,$f0=FLOOR($0, FLAG(MONTH)),countryName=CAST('Indonesia':VARCHAR):VARCHAR,added=$1)] org.apache.calcite.plan.RelOptPlanner - call#4: Apply rule [ReduceExpressionsRule(Project)] to [rel#30:LogicalProject.NONE.[](input=HepRelVertex#29,__time=$0,added=$7,cityName=$18,countryName=$19)] org.apache.calcite.plan.RelOptPlanner - call#5: Apply rule [ReduceExpressionsRule(Project)] to [rel#30:LogicalProject.NONE.[](input=HepRelVertex#29,__time=$0,added=$7,cityName=$18,countryName=$19)] org.apache.calcite.plan.RelOptPlanner - call#6: Apply rule [ReduceExpressionsRule(Project)] to [rel#42:LogicalProject.NONE.[](input=HepRelVertex#37,EXPR$0=$2,countryName=CAST('Indonesia':VARCHAR):VARCHAR)] org.apache.calcite.plan.RelOptPlanner - call#7: Apply rule [ReduceExpressionsRule(Project)] to [rel#44:LogicalProject.NONE.[](input=HepRelVertex#33,$f0=FLOOR($0, FLAG(MONTH)),countryName=CAST('Indonesia':VARCHAR):VARCHAR,added=$1)] org.apache.calcite.plan.RelOptPlanner - call#8: Apply rule [ReduceExpressionsRule(Project)] to [rel#30:LogicalProject.NONE.[](input=HepRelVertex#29,__time=$0,added=$7,cityName=$18,countryName=$19)] org.apache.calcite.plan.RelOptPlanner - call#9: Apply rule [ReduceExpressionsRule(Filter)] to [rel#32:LogicalFilter.NONE.[](input=HepRelVertex#31,condition=AND(=($2, 'Cilacap'), =($3, 'Indonesia')))] org.apache.calcite.plan.RelOptPlanner - For final plan, using rel#40:LogicalSort.NONE.[](input=HepRelVertex#39,fetch=1001) org.apache.calcite.plan.RelOptPlanner - For final plan, using rel#42:LogicalProject.NONE.[](input=HepRelVertex#37,EXPR$0=$2,countryName=CAST('Indonesia':VARCHAR):VARCHAR) org.apache.calcite.plan.RelOptPlanner - For final plan, using rel#36:LogicalAggregate.NONE.[](input=HepRelVertex#35,group={0, 1},groups=[{0, 1}, {0}],EXPR$0=SUM($2)) org.apache.calcite.plan.RelOptPlanner - For final plan, using rel#44:LogicalProject.NONE.[](input=HepRelVertex#33,$f0=FLOOR($0, FLAG(MONTH)),countryName=CAST('Indonesia':VARCHAR):VARCHAR,added=$1) org.apache.calcite.plan.RelOptPlanner - For final plan, using rel#32:LogicalFilter.NONE.[](input=HepRelVertex#31,condition=AND(=($2, 'Cilacap'), =($3, 'Indonesia'))) org.apache.calcite.plan.RelOptPlanner - For final plan, using rel#30:LogicalProject.NONE.[](input=HepRelVertex#29,__time=$0,added=$7,cityName=$18,countryName=$19) org.apache.calcite.plan.RelOptPlanner - For final plan, using rel#5:LogicalTableScan.NONE.[](table=[druid, wikipedia]) ``` it looks like the `countryName` dimension has been converted to `CAST('Indonesia':VARCHAR):VARCHAR)` via the `ProjectReduceExpressionsRule` during the `HepPlanner` phase. As a result, during the post grouping projection phase, the selectProject already has `countryName` as a constant which eventually converts it into a expression based post aggregation and then proceeds to drop the dimension. Since the query has GROUPING SETS, shouldn't the calcite layer be avoiding this incorrect CAST? -- 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]
