From c51607e1b1d2d62ab5db90bde2ec4857e6fb95e5 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Fri, 13 Dec 2024 10:09:37 +0000 Subject: [PATCH] fix --- .../calcite/planner/DruidRelFieldTrimmer.java | 2 +- ...rayColumnsOrFilters@NullHandling=default.iq | 18 ++++++++++-------- ...ereOnUnnestArrayCol@NullHandling=default.iq | 14 ++++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRelFieldTrimmer.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRelFieldTrimmer.java index 5982aefb3a3..6577ea3857e 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRelFieldTrimmer.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRelFieldTrimmer.java @@ -101,7 +101,7 @@ public class DruidRelFieldTrimmer extends RelFieldTrimmer ImmutableBitSet fieldsUsed, Set extraFields) { - if (trimTableScan) { + if (fieldsUsed.cardinality()>0 || trimTableScan) { return super.trimFields(tableAccessRel, fieldsUsed, extraFields); } else { Mapping mapping = Mappings.createIdentity(tableAccessRel.getRowType().getFieldCount()); diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteArraysQueryTest/testUnnestThriceWithFiltersOnDimAndAllUnnestColumnsArrayColumnsOrFilters@NullHandling=default.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteArraysQueryTest/testUnnestThriceWithFiltersOnDimAndAllUnnestColumnsArrayColumnsOrFilters@NullHandling=default.iq index 5a8542970a9..f604252db9a 100644 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteArraysQueryTest/testUnnestThriceWithFiltersOnDimAndAllUnnestColumnsArrayColumnsOrFilters@NullHandling=default.iq +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteArraysQueryTest/testUnnestThriceWithFiltersOnDimAndAllUnnestColumnsArrayColumnsOrFilters@NullHandling=default.iq @@ -30,10 +30,11 @@ LogicalProject(arrayString=[CAST(ARRAY('a':VARCHAR, 'b':VARCHAR)):VARCHAR ARRAY] LogicalProject(arrayStringNulls=[$0], uln=[$2], udn=[$3]) LogicalFilter(condition=[OR(=($2, 1), =($3, 2.2))]) LogicalUnnest(unnestExpr=[$1]) - LogicalProject(arrayStringNulls=[$2], arrayDoubleNulls=[$6], uln=[$12]) - LogicalUnnest(unnestExpr=[$4]) - LogicalFilter(condition=[=($1, CAST(ARRAY('a', 'b')):VARCHAR ARRAY NOT NULL)]) - LogicalTableScan(table=[[druid, arrays]]) + LogicalProject(arrayStringNulls=[$0], arrayDoubleNulls=[$2], uln=[$3]) + LogicalUnnest(unnestExpr=[$1]) + LogicalProject(arrayStringNulls=[$2], arrayLongNulls=[$4], arrayDoubleNulls=[$6]) + LogicalFilter(condition=[=($1, CAST(ARRAY('a', 'b')):VARCHAR ARRAY NOT NULL)]) + LogicalTableScan(table=[[druid, arrays]]) !logicalPlan DruidProject(arrayString=[CAST(ARRAY('a':VARCHAR, 'b':VARCHAR)):VARCHAR ARRAY], uln=[$1], udn=[$2], usn=[$3], druid=[logical]) @@ -41,10 +42,11 @@ DruidProject(arrayString=[CAST(ARRAY('a':VARCHAR, 'b':VARCHAR)):VARCHAR ARRAY], DruidProject(arrayStringNulls=[$0], uln=[$2], udn=[$3], druid=[logical]) DruidFilter(condition=[OR(=($2, 1), =($3, 2.2))]) DruidUnnest(unnestExpr=[$1]) - DruidProject(arrayStringNulls=[$2], arrayDoubleNulls=[$6], uln=[$12], druid=[logical]) - DruidUnnest(unnestExpr=[$4]) - DruidFilter(condition=[=($1, CAST(ARRAY('a', 'b')):VARCHAR ARRAY NOT NULL)]) - DruidTableScan(table=[[druid, arrays]], druid=[logical]) + DruidProject(arrayStringNulls=[$0], arrayDoubleNulls=[$2], uln=[$3], druid=[logical]) + DruidUnnest(unnestExpr=[$1]) + DruidProject(arrayStringNulls=[$2], arrayLongNulls=[$4], arrayDoubleNulls=[$6], druid=[logical]) + DruidFilter(condition=[=($1, CAST(ARRAY('a', 'b')):VARCHAR ARRAY NOT NULL)]) + DruidTableScan(table=[[druid, arrays]], druid=[logical]) !druidPlan { diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteArraysQueryTest/testUnnestWithGroupByHavingWithWhereOnUnnestArrayCol@NullHandling=default.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteArraysQueryTest/testUnnestWithGroupByHavingWithWhereOnUnnestArrayCol@NullHandling=default.iq index 5ca239e8831..e46f6bef54b 100644 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteArraysQueryTest/testUnnestWithGroupByHavingWithWhereOnUnnestArrayCol@NullHandling=default.iq +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteArraysQueryTest/testUnnestWithGroupByHavingWithWhereOnUnnestArrayCol@NullHandling=default.iq @@ -18,14 +18,16 @@ SELECT uln, COUNT(*) FROM druid.arrays, UNNEST(arrayLongNulls) AS unnested(uln) (1 row) !ok -LogicalAggregate(group=[{12}], EXPR$1=[COUNT()]) - LogicalUnnest(unnestExpr=[$4], filter=[=($0, 1)]) - LogicalTableScan(table=[[druid, arrays]]) +LogicalAggregate(group=[{1}], EXPR$1=[COUNT()]) + LogicalUnnest(unnestExpr=[$0], filter=[=($0, 1)]) + LogicalProject(arrayLongNulls=[$4]) + LogicalTableScan(table=[[druid, arrays]]) !logicalPlan -DruidAggregate(group=[{12}], EXPR$1=[COUNT()], druid=[logical]) - DruidUnnest(unnestExpr=[$4], filter=[=($0, 1)]) - DruidTableScan(table=[[druid, arrays]], druid=[logical]) +DruidAggregate(group=[{1}], EXPR$1=[COUNT()], druid=[logical]) + DruidUnnest(unnestExpr=[$0], filter=[=($0, 1)]) + DruidProject(arrayLongNulls=[$4], druid=[logical]) + DruidTableScan(table=[[druid, arrays]], druid=[logical]) !druidPlan {