> On Feb 20, 2026, at 11:07 AM, Mihai Budiu <[email protected]> wrote:
> 
>> We probably need a new Quidem command to fire the rules and generate the 
>> before and after plans.
> 
> https://issues.apache.org/jira/browse/CALCITE-6335
> Quidem tests should allow specifying optimization passes to apply to programs
> 
> This issue is implemented.

Yes, the ‘!set rules’ command will be useful. I think we will also need 
‘!plan-before’ and ‘!plan-after’ commands, something like this:

# Pull aggregate through union ====================
# Tests that AggregateUnionAggregateRule can convert
# a union of two ’select distinct’ queries to a ’select distinct’
# of a union.
!set rules "AGGREGATE_UNION_AGGREGATE"
select deptno, job
from (select deptno, job
  from emp as e1
  group by deptno, job
  union all
  select deptno, job
  from emp as e2
   group by deptno, job)
group by deptno, job;
+--------+-----------+
| DEPTNO |    JOB    |
+--------+-----------+
| 20     | CLERK     |
| 30     | SALESMAN  |
| 20     | MANAGER   |
| 30     | MANAGER   |
| 10     | MANAGER   |
| 20     | ANALYST   |
| 10     | PRESIDENT |
| 30     | CLERK     |
| 10     | CLERK     |
+--------+-----------+
(9 rows)

!ok
LogicalAggregate(group=[{0, 1}])
  LogicalUnion(all=[true])
    LogicalAggregate(group=[{0, 1}])
      LogicalProject(DEPTNO=[$7], JOB=[$2])
        LogicalTableScan(table=[[CATALOG, SALES, EMP]])
    LogicalAggregate(group=[{0, 1}])
      LogicalProject(DEPTNO=[$7], JOB=[$2])
        LogicalTableScan(table=[[CATALOG, SALES, EMP]])
!plan-before
LogicalAggregate(group=[{0, 1}])
  LogicalUnion(all=[true])
    LogicalProject(DEPTNO=[$7], JOB=[$2])
      LogicalTableScan(table=[[CATALOG, SALES, EMP]])
    LogicalProject(DEPTNO=[$7], JOB=[$2])
      LogicalTableScan(table=[[CATALOG, SALES, EMP]])
!plan-after

Note that the !plan-before and !plan-after commands work with the previous SQL 
query, and (as is the usual way in Quidem) follow their expected output.

The information is the same as in 
RelOptRulesTest.testPullAggregateThroughUnion() (and the corresponding XML 
resource), just laid out in a way that works for Quidem.

Julian

Reply via email to