Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-4345] NPE in AggregateCaseToFilterRule when converts SUM(CASE WHEN c THEN 1 END) (Jiatao Tao) #2225

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ private static boolean isThreeArgCase(final RexNode rexNode) {

private static boolean isIntLiteral(final RexNode rexNode) {
return rexNode instanceof RexLiteral
&& SqlTypeName.INT_TYPES.contains(rexNode.getType().getSqlTypeName());
&& SqlTypeName.INT_TYPES.contains(rexNode.getType().getSqlTypeName())
&& !RexLiteral.isNullLiteral(rexNode);
}

/** Rule configuration. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3825,7 +3825,11 @@ public boolean test(Project project) {
+ " sum(case when deptno = 10 then sal end) as sum_sal_d10,\n"
+ " sum(case when deptno = 20 then sal else 0 end) as sum_sal_d20,\n"
+ " sum(case when deptno = 30 then 1 else 0 end) as count_d30,\n"
+ " count(case when deptno = 40 then 'x' end) as count_d40,\n"
+ " sum(case when deptno = 40 then 1 end) as count_d40,\n"
Aaaaaaron marked this conversation as resolved.
Show resolved Hide resolved
+ " sum(case when deptno = 50 then 1 else null end) as count_d50,\n"
+ " sum(case when deptno = 60 then null end) as sum_null_d60,\n"
+ " sum(case when deptno = 70 then null else 1 end) as sum_null_d70,\n"
+ " count(case when deptno = 10 then 'x' end) as count_d10,\n"
+ " count(case when deptno = 20 then 1 end) as count_d20\n"
+ "from emp";
sql(sql).withRule(CoreRules.AGGREGATE_CASE_TO_FILTER).check();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,26 @@
sum(case when deptno = 10 then sal end) as sum_sal_d10,
sum(case when deptno = 20 then sal else 0 end) as sum_sal_d20,
sum(case when deptno = 30 then 1 else 0 end) as count_d30,
count(case when deptno = 40 then 'x' end) as count_d40,
sum(case when deptno = 40 then 1 end) as count_d40,
sum(case when deptno = 50 then 1 else null end) as count_d50,
sum(case when deptno = 60 then null end) as sum_null_d60,
sum(case when deptno = 70 then null else 1 end) as sum_null_d70,
count(case when deptno = 10 then 'x' end) as count_d10,
count(case when deptno = 20 then 1 end) as count_d20
from emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalAggregate(group=[{}], SUM_SAL=[SUM($0)], COUNT_DISTINCT_CLERK=[COUNT(DISTINCT $1)], SUM_SAL_D10=[SUM($2)], SUM_SAL_D20=[SUM($3)], COUNT_D30=[SUM($4)], COUNT_D40=[COUNT($5)], COUNT_D20=[COUNT($6)])
LogicalProject(SAL=[$5], $f1=[CASE(=($2, 'CLERK'), $7, null:INTEGER)], $f2=[CASE(=($7, 10), $5, null:INTEGER)], $f3=[CASE(=($7, 20), $5, 0)], $f4=[CASE(=($7, 30), 1, 0)], $f5=[CASE(=($7, 40), 'x', null:CHAR(1))], $f6=[CASE(=($7, 20), 1, null:INTEGER)])
LogicalAggregate(group=[{}], SUM_SAL=[SUM($0)], COUNT_DISTINCT_CLERK=[COUNT(DISTINCT $1)], SUM_SAL_D10=[SUM($2)], SUM_SAL_D20=[SUM($3)], COUNT_D30=[SUM($4)], COUNT_D40=[SUM($5)], COUNT_D50=[SUM($6)], SUM_NULL_D60=[SUM($7)], SUM_NULL_D70=[SUM($8)], COUNT_D10=[COUNT($9)], COUNT_D20=[COUNT($10)])
LogicalProject(SAL=[$5], $f1=[CASE(=($2, 'CLERK'), $7, null:INTEGER)], $f2=[CASE(=($7, 10), $5, null:INTEGER)], $f3=[CASE(=($7, 20), $5, 0)], $f4=[CASE(=($7, 30), 1, 0)], $f5=[CASE(=($7, 40), 1, null:INTEGER)], $f6=[CASE(=($7, 50), 1, null:INTEGER)], $f7=[null:DECIMAL(19, 9)], $f8=[CASE(=($7, 70), null:INTEGER, 1)], $f9=[CASE(=($7, 10), 'x', null:CHAR(1))], $f10=[CASE(=($7, 20), 1, null:INTEGER)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SUM_SAL=[$0], COUNT_DISTINCT_CLERK=[$1], SUM_SAL_D10=[$2], SUM_SAL_D20=[$3], COUNT_D30=[CAST($4):INTEGER], COUNT_D40=[$5], COUNT_D20=[$6])
LogicalAggregate(group=[{}], SUM_SAL=[SUM($0)], COUNT_DISTINCT_CLERK=[COUNT(DISTINCT $1) FILTER $2], SUM_SAL_D10=[SUM($3) FILTER $4], SUM_SAL_D20=[SUM($5) FILTER $6], COUNT_D30=[COUNT() FILTER $7], COUNT_D40=[COUNT() FILTER $8], COUNT_D20=[COUNT() FILTER $9])
LogicalProject(SAL=[$5], DEPTNO=[$7], $f8=[=($2, 'CLERK')], SAL0=[$5], $f10=[=($7, 10)], SAL1=[$5], $f12=[=($7, 20)], $f13=[=($7, 30)], $f14=[=($7, 40)], $f15=[=($7, 20)])
LogicalProject(SUM_SAL=[$0], COUNT_DISTINCT_CLERK=[$1], SUM_SAL_D10=[$2], SUM_SAL_D20=[$3], COUNT_D30=[CAST($4):INTEGER], COUNT_D40=[$5], COUNT_D50=[$6], SUM_NULL_D60=[$7], SUM_NULL_D70=[$8], COUNT_D10=[$9], COUNT_D20=[$10])
LogicalAggregate(group=[{}], SUM_SAL=[SUM($0)], COUNT_DISTINCT_CLERK=[COUNT(DISTINCT $2) FILTER $3], SUM_SAL_D10=[SUM($4) FILTER $5], SUM_SAL_D20=[SUM($6) FILTER $7], COUNT_D30=[COUNT() FILTER $8], COUNT_D40=[SUM($9) FILTER $10], COUNT_D50=[SUM($11) FILTER $12], SUM_NULL_D60=[SUM($1)], SUM_NULL_D70=[SUM($13) FILTER $14], COUNT_D10=[COUNT() FILTER $15], COUNT_D20=[COUNT() FILTER $16])
LogicalProject(SAL=[$5], $f7=[null:DECIMAL(19, 9)], DEPTNO=[$7], $f12=[=($2, 'CLERK')], SAL0=[$5], $f14=[=($7, 10)], SAL1=[$5], $f16=[=($7, 20)], $f17=[=($7, 30)], $f18=[1], $f19=[=($7, 40)], $f20=[1], $f21=[=($7, 50)], $f22=[1], $f23=[<>($7, 70)], $f24=[=($7, 10)], $f25=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
Expand Down