iwanttobepowerful commented on code in PR #4598:
URL: https://github.com/apache/calcite/pull/4598#discussion_r2463191080
##########
core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml:
##########
@@ -216,6 +216,189 @@ LogicalProject(HIREDATE=[$1])
LogicalProject(MGR=[$3])
LogicalFilter(condition=[AND(IS NULL($3), =($4, CURRENT_TIMESTAMP))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testAggregateExtractLiteralAggRule1">
+ <Resource name="sql">
+ <![CDATA[select e.deptno,
+e.deptno < some (select deptno from emp where emp.ename = e.ename) as v
+from emp as e]]>
+ </Resource>
+ <Resource name="planBefore">
+ <![CDATA[
+LogicalProject(variablesSet=[[$cor0]], DEPTNO=[$7], V=[< SOME($7, {
+LogicalProject(DEPTNO=[$7])
+ LogicalFilter(condition=[=($1, $cor0.ENAME)])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+})])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ <Resource name="planMid">
+ <![CDATA[
+LogicalProject(DEPTNO=[$7], V=[CAST(OR(AND(IS TRUE(<($7, $9)), IS NOT
TRUE(OR(IS NULL($12), =($10, 0)))), AND(IS TRUE(>($10, $11)), null, IS NOT
TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(<($7, $9))), AND(<($7, $9), IS
NOT TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(<($7, $9)), IS NOT
TRUE(>($10, $11))))):BOOLEAN NOT NULL])
+ LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{1}])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalProject(m=[$0], c=[$1], d=[$1], trueLiteral=[$2])
+ LogicalAggregate(group=[{}], m=[MAX($0)], c=[COUNT()],
trueLiteral=[LITERAL_AGG(true)])
+ LogicalProject(DEPTNO=[$7])
+ LogicalFilter(condition=[=($1, $cor0.ENAME)])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ <Resource name="planAfter">
+ <![CDATA[
+LogicalProject(DEPTNO=[$7], V=[CAST(OR(AND(IS TRUE(<($7, $9)), IS NOT
TRUE(OR(IS NULL($12), =($10, 0)))), AND(IS TRUE(>($10, $11)), null, IS NOT
TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(<($7, $9))), AND(<($7, $9), IS
NOT TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(<($7, $9)), IS NOT
TRUE(>($10, $11))))):BOOLEAN NOT NULL])
+ LogicalJoin(condition=[=($1, $13)], joinType=[left])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalProject(m=[$2], c=[CASE(IS NOT NULL($3), $3, 0)], d=[CASE(IS NOT
NULL($3), $3, 0)], trueLiteral=[$4], ENAME=[$0])
+ LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $1)], joinType=[left])
+ LogicalAggregate(group=[{1}])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalProject(ENAME=[$0], m=[$1], c=[$2], $f3=[true])
+ LogicalAggregate(group=[{0}], m=[MAX($1)], c=[COUNT()])
+ LogicalProject(ENAME=[$1], DEPTNO=[$7])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testAggregateExtractLiteralAggRule2">
+ <Resource name="sql">
+ <![CDATA[select deptno, name = ANY (
+ select mgr from emp)
+from dept]]>
+ </Resource>
+ <Resource name="planBefore">
+ <![CDATA[
+LogicalProject(DEPTNO=[$0], EXPR$1=[IN($1, {
+LogicalProject(MGR=[$3])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+})])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+]]>
+ </Resource>
+ <Resource name="planMid">
+ <![CDATA[
+LogicalProject(DEPTNO=[$0], EXPR$1=[OR(AND(IS NOT NULL($5), <>($2, 0)),
AND(<($3, $2), null, <>($2, 0), IS NULL($5)))])
+ LogicalJoin(condition=[=($1, $4)], joinType=[left])
+ LogicalJoin(condition=[true], joinType=[inner])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0)])
+ LogicalProject(MGR=[$3])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalAggregate(group=[{0}], i=[LITERAL_AGG(true)])
+ LogicalProject(MGR=[$3])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ <Resource name="planAfter">
+ <![CDATA[
+LogicalProject(DEPTNO=[$0], EXPR$1=[OR(AND(IS NOT NULL($5), <>($2, 0)),
AND(<($3, $2), null, <>($2, 0), IS NULL($5)))])
+ LogicalJoin(condition=[=($1, $4)], joinType=[left])
+ LogicalJoin(condition=[true], joinType=[inner])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0)])
+ LogicalProject(MGR=[$3])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalProject(MGR=[$0], $f1=[true])
+ LogicalAggregate(group=[{0}])
+ LogicalProject(MGR=[$3])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testAggregateExtractLiteralAggRule3">
+ <Resource name="sql">
+ <![CDATA[select * from emp where empno > ANY (
+ select deptno from dept where emp.job = dept.name)
+]]>
+ </Resource>
+ <Resource name="planBefore">
+ <![CDATA[
+LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
+ LogicalFilter(condition=[> SOME($0, {
+LogicalProject(DEPTNO=[$0])
+ LogicalFilter(condition=[=($cor0.JOB, $1)])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+})], variablesSet=[[$cor0]])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ <Resource name="planMid">
+ <![CDATA[
+LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
+ LogicalFilter(condition=[OR(AND(IS TRUE(>($0, $9)), IS NOT TRUE(OR(IS
NULL($12), =($10, 0)))), AND(IS TRUE(>($10, $11)), null, IS NOT TRUE(OR(IS
NULL($12), =($10, 0))), IS NOT TRUE(>($0, $9))), AND(>($0, $9), IS NOT
TRUE(OR(IS NULL($12), =($10, 0))), IS NOT TRUE(>($0, $9)), IS NOT TRUE(>($10,
$11))))])
+ LogicalCorrelate(correlation=[$cor0], joinType=[left],
requiredColumns=[{2}])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalProject(m=[$0], c=[$1], d=[$1], trueLiteral=[$2])
+ LogicalAggregate(group=[{}], m=[MIN($0)], c=[COUNT()],
trueLiteral=[LITERAL_AGG(true)])
Review Comment:
add an end-to-end test in planner.iq is needed.
but we can not see logical plan that affected by this rule.
--
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]