Make PlannerContext implement Calcite Context for rule-time option access#18567
Merged
gortiz merged 1 commit intoMay 25, 2026
Merged
Conversation
PlannerContext now implements org.apache.calcite.plan.Context and passes itself as the context to both the opt planner (LogicalPlanner backed by optProgram) and the trait planner (LogicalPlanner backed by traitProgram). This allows Calcite rules contributed via the new RuleSetCustomizer SPI (see apache#18387) to read per-query options at match time without reflection: PlannerContext ctx = call.getPlanner().getContext().unwrap(PlannerContext.class); String runtime = ctx.getOptions().get("workerRuntime"); unwrap() also delegates to _envConfig, so any rule that currently unwraps QueryEnvironment.Config continues to work unchanged. A package-private constructor and a public forTesting() factory are added so unit tests can construct a PlannerContext without going through QueryEnvironment (which requires a full broker setup).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18567 +/- ##
============================================
- Coverage 64.29% 64.28% -0.01%
Complexity 1137 1137
============================================
Files 3314 3314
Lines 204064 204082 +18
Branches 31760 31761 +1
============================================
- Hits 131193 131186 -7
- Misses 62348 62372 +24
- Partials 10523 10524 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
yashmayya
approved these changes
May 22, 2026
Contributor
|
Opened the matching docs update in pinot-contrib/pinot-docs#825: pinot-contrib/pinot-docs#825 |
xiangfu0
added a commit
to pinot-contrib/pinot-docs
that referenced
this pull request
May 25, 2026
## Summary - document the new `PlannerContext` access path for `RuleSetCustomizer` plugins - show how planner rules can unwrap `PlannerContext` from Calcite context and read per-query options - keep the update scoped to the existing planner rule customizer SPI docs ## Validation - `git diff --check` - lightweight link resolution check for `developers/plugin-architecture/README.md` ## Source cross-check - `pinot-query-planner/src/main/java/org/apache/pinot/query/context/PlannerContext.java` - `pinot-query-planner/src/test/java/org/apache/pinot/query/context/PlannerContextTest.java` - `apache/pinot#18567`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PlannerContextnow implementsorg.apache.calcite.plan.Contextand passes itself as the context to both the opt planner and the trait planner.This allows Calcite rules contributed via the
RuleSetCustomizerSPI (#18387) to read per-query options at match time without reflection:unwrap()also delegates to_envConfig, so any code that previously unwrappedQueryEnvironment.Configcontinues to work unchanged.A package-private constructor and a
forTesting()factory method are added so unit tests can construct aPlannerContextwithout going throughQueryEnvironment, andPlannerContextTestcovers theunwrapcontract and verifies that both planners expose thePlannerContextinstance through their context.Changes
PlannerContextimplementsContext_relOptPlannerand_relTraitPlannerreceivethisas their contextunwrap(PlannerContext.class)andunwrap(Context.class)returnthis;unwrap(QueryEnvironment.Config.class)delegates to_envConfigforTesting()factory + package-private constructor for unit testingPlannerContextTest— 5 tests verifying theunwrapcontract and planner context exposureTest plan
PlannerContextTest(5 tests) — all passpinot-query-plannertest suite passes