You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "shikhae6 (via GitHub)" <gi...@apache.org> on 2026/05/25 18:47:08 UTC
[PR] [CALCITE-7549] Add Programs.of overload that accepts RelOptListener [calcite]
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7549] Add Programs.of overload that accepts RelOptListener [calcite]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #4968:
URL: https://github.com/apache/calcite/pull/4968#issuecomment-5155365473
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7549] Add Programs.of overload that accepts RelOptListener [calcite]
Posted by "shikhae6 (via GitHub)" <gi...@apache.org>.
shikhae6 commented on PR #4968:
URL: https://github.com/apache/calcite/pull/4968#issuecomment-4862425971
@julianhyde
I have proposed an alternate solution in Jira , here are the details:
I was treating the listener as part of the program definition, but it is really runtime/session state.
I’m thinking of changing the approach so the listener is not passed to Programs.of at all. Instead, callers would continue to attach the listener to the runtime planner for the current planning session:
planner.addListener(listener);
Program program = Programs.of(hepProgram, noDag, metadataProvider);
program.run(planner, rel, traits, materializations, lattices);
Then, inside the existing Programs.of(HepProgram, boolean, RelMetadataProvider) implementation, when it creates the internal HepPlanner, it would propagate the listener from the runtime planner passed to Program.run.
if (planner instanceof AbstractRelOptPlanner) {
RelOptListener listener = ((AbstractRelOptPlanner) planner).getListener();
if (listener != null)
{ hepPlanner.addListener(listener); }
}
This keeps Program stateless and reusable, while preserving the listener’s session lifetime. It also makes the behavior generally useful: any listener registered on the runtime planner will receive events from the internal HEP planner used by this program, rather than requiring a special Programs.of overload with listener.
If this direction sounds reasonable, I’ll remove the new overload and update the test to register the listener on the planner passed into Program.run, then verify that HEP rule events are forwarded through that session listener.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7549] Add Programs.of overload that accepts RelOptListener [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4968:
URL: https://github.com/apache/calcite/pull/4968#issuecomment-4536608465
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4968) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4968&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4968&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4968&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [76.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4968&metric=new_coverage&view=list)
 [36.8% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4968&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4968)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7549] Add Programs.of overload that accepts RelOptListener [calcite]
Posted by "julianhyde (via GitHub)" <gi...@apache.org>.
julianhyde commented on PR #4968:
URL: https://github.com/apache/calcite/pull/4968#issuecomment-4537875517
I raised some concerns in the jira case.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7549] Add Programs.of overload that accepts RelOptListener [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4968:
URL: https://github.com/apache/calcite/pull/4968#issuecomment-4630123293
@shikhae6 Do you think this PR is still needed?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7549] Add Programs.of overload that accepts RelOptListener [calcite]
Posted by "shikhae6 (via GitHub)" <gi...@apache.org>.
shikhae6 commented on PR #4968:
URL: https://github.com/apache/calcite/pull/4968#issuecomment-4630230907
>
@xiedeyantu I have proposed an alternate way in Jira , awaiting @julianhyde view on it
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7549] Add Programs.of overload that accepts RelOptListener [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4968:
URL: https://github.com/apache/calcite/pull/4968#discussion_r3299953532
##########
core/src/main/java/org/apache/calcite/tools/Programs.java:
##########
@@ -190,6 +193,41 @@ public static Program of(final HepProgram hepProgram, final boolean noDag,
return hepPlanner.findBestExp();
};
}
+ /** Creates a program that executes a {@link HepProgram}.
+ *
+ * <p>If {@code listener} is not null, it is
+ * {@linkplain HepPlanner#addListener(RelOptListener) attached}
+ * to the planner before execution. */
+ @SuppressWarnings("deprecation")
Review Comment:
Can't this be done without calling deprecated functions?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org