Skip to content

feat: add coverage threshold to skip Comet for low-coverage queries#3816

Draft
andygrove wants to merge 3 commits intoapache:mainfrom
andygrove:feat/coverage-threshold
Draft

feat: add coverage threshold to skip Comet for low-coverage queries#3816
andygrove wants to merge 3 commits intoapache:mainfrom
andygrove:feat/coverage-threshold

Conversation

@andygrove
Copy link
Copy Markdown
Member

@andygrove andygrove commented Mar 27, 2026

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 simple cost-based mechanism to skip Comet entirely for such queries.

What changes are included in this PR?

  • Add spark.comet.exec.coverageThreshold config (double, 0.0–1.0, default 0.0 = disabled). When set, Comet falls back to the original Spark plan if the percentage of converted operators is below the threshold.
  • Extract CometCoverageStats.fromPlan() to compute coverage stats from a SparkPlan without building the explain string, reusable by both the explain output and the threshold check.
  • Add threshold check at the end of CometExecRule._apply() that logs a warning and returns the original plan when coverage is insufficient.

How are these changes tested?

Default behavior is unchanged (threshold = 0.0 disables the check). Manual verification that compile succeeds. Tests to be added.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant