shikhae6 opened a new pull request, #4968: URL: https://github.com/apache/calcite/pull/4968
## Summary
When composing HEP optimization phases via `Programs.sequence`, the
`HepPlanner` is constructed internally inside `Programs.of` with no
seam to attach a `RelOptListener` before `findBestExp()`. This makes
it impossible to observe rule firings across sequenced phases — a
common need for query optimizer tracing and observability.
This change adds a new overload:
```java
Programs.of(HepProgram, boolean, RelMetadataProvider, RelOptListener)
If listener is not null, it is attached to the internally constructed
HepPlanner via addListener() before setRoot / findBestExp.
If listener is null, the method delegates to the existing
Programs.of(HepProgram, boolean, RelMetadataProvider) — zero
behavior change for current callers.
Use case
In production query optimizers built on Calcite, optimization is
typically structured as multiple HEP phases composed via
Programs.sequence. To trace which rules fire, in which phase, and
in what order, a RelOptListener must be attached to each
HepPlanner. Without this overload, the only options are:
- Bypass Programs.of entirely and construct HepPlanner manually
(losing the metadata/materialization/lattice setup that Programs.of
provides).
- Use reflection to access the internally constructed planner.
This overload provides a clean, supported hook.
Backward compatibility
- The existing Programs.of(HepProgram, boolean, RelMetadataProvider)
method is unchanged.
- The new overload with a null listener delegates directly to the
existing method — identical behavior, no overhead.
- No changes to Program interface or HepPlanner.
Testing
Two new tests added to HepPlannerTest:
- testProgramsOfWithListener — verifies the listener receives
ruleAttempted events when rules fire through Programs.of.
- testProgramsOfWithNullListener — verifies null listener is
safely ignored and produces identical results.
--
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]
