feat: add coverage threshold to skip Comet for low-coverage queries#3816
Open
andygrove wants to merge 7 commits intoapache:mainfrom
Open
feat: add coverage threshold to skip Comet for low-coverage queries#3816andygrove wants to merge 7 commits intoapache:mainfrom
andygrove wants to merge 7 commits intoapache:mainfrom
Conversation
Add spark.comet.exec.coverageThreshold config (0.0-1.0, default 0.0) that reverts to the original Spark plan when the fraction of converted operators falls below the threshold. This avoids the overhead of Spark-to-Comet transitions for queries where only a small percentage of operators can run natively.
Extract classifyNode() to eliminate duplicated match logic between generateTreeString and collectStats. Replace coveragePercent with coverageFraction (0.0-1.0) to match the threshold config units and avoid unnecessary multiply/divide conversions.
The merge with apache/main introduced two object CometCoverageStats declarations (forPlan from main, fromPlan from this branch). Drop the local fromPlan variant and reuse the existing forPlan helper.
…a withInfo Apply the threshold check on the canonical first pass only: the queryStagePrepRule registration in AQE mode, or preColumnarTransitions in non-AQE mode. AQE per-stage re-entries skip the check, and a sticky SKIP_COMET_PLAN_TAG on every node ensures any fallback decision survives into per-stage rule applications so we don't flip-flop. When falling back, attach the reason to the plan via withInfo so it shows up in extended explain output alongside other Comet fallback reasons. Add CometExecRuleSuite tests covering: default disabled, fallback above coverage, conversion below threshold, reason in extension info, and AQE stickiness on re-entry.
Replace the in-method early-return on threshold fallback with a helper that returns either the converted or the original plan as the value of the if/else expression. Expand the tuning guide with a section on AQE behavior and the known limitations of an operator-count metric (no cost weighting, no row/byte weighting, transitions excluded, single global value).
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.
Which issue does this PR close?
Part of #833
Rationale for this change
When Comet can only convert a small fraction of a query's operators, the overhead from Spark to Comet transitions can outweigh the benefit of native execution. This adds a coarse safety valve so users can opt into "skip Comet entirely if coverage is below X" without having to disable Comet globally.
What changes are included in this PR?
spark.comet.exec.coverageThreshold(double, 0.0 to 1.0, default 0.0 = disabled). When the fraction of converted operators in the final plan is below the threshold,CometExecRulereturns the original Spark plan instead of the converted one.injectQueryStagePrepRuleregistration in AQE mode, orpreColumnarTransitionsin non-AQE mode). AQE per-stagepreColumnarTransitionsre-entries skip the check.SKIP_COMET_PLAN_TAGso any subsequent rule application (e.g. AQE per-stage on a sub-plan) honors the prior decision instead of re-evaluating coverage on a smaller view of the plan.withInfo. When the threshold triggers, the reason string ("Comet native coverage X% is below threshold Y% (...)") is attached to the plan and shows up in extended explain output alongside other Comet fallback reasons.Limitations
This is a coarse safety valve, not a cost model. Worth being explicit about what it does not capture:
The default of
0.0keeps behavior unchanged for existing users.How are these changes tested?
New tests in
CometExecRuleSuite:0.0disables the checkapplyThresholdCheck = falseand the threshold reset to 0 still leaves the plan as Spark, demonstrating the AQE per-stage sentinel)