Skip to content

Add TPC-H distributed plan-stability test suite#1966

Merged
andygrove merged 7 commits into
apache:mainfrom
andygrove:tpch-plan-stability
Jul 8, 2026
Merged

Add TPC-H distributed plan-stability test suite#1966
andygrove merged 7 commits into
apache:mainfrom
andygrove:tpch-plan-stability

Conversation

@andygrove

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A — adds plan-stability test coverage (analogous to Comet's TPC-DS plan-stability golden files).

Rationale for this change

Ballista has no protection against accidental changes to the distributed plan shape of TPC-H queries. The existing per-query TPC-H tests (benchmarks/src/bin/tpch.rs) verify query results, not plan structure — a change that alters join strategy, shuffle/stage boundaries, stage count, or broadcast decisions but still returns correct rows passes silently.

Comet (and Spark upstream) guard against exactly this with plan-stability golden files: each query's plan is frozen as a checked-in text file and CI fails when it drifts. This PR brings the same protection to Ballista for TPC-H. Concretely, it would have caught plan-shape changes such as a flip in the default join strategy or changes in exchange-reuse stage counts.

What changes are included in this PR?

A new integration test in the ballista-scheduler crate under ballista/scheduler/tests/tpch_plan_stability/:

  • Dataless stats-injecting table provider (stats_table.rs): a TableProvider with a real TPC-H schema and injected SF100 row-count statistics (a StatsExec leaf modeled on DataFusion's EmptyExec), so the physical optimizer makes realistic join/broadcast choices without reading any data.
  • Fixtures + helper (fixtures.rs): the 8 TPC-H schemas, SF100 cardinalities, and staged_plan_text(), which plans a query with the static DefaultDistributedPlanner (target_partitions=16, Ballista default config), renders the resulting stages (ShuffleWriterExec/UnresolvedShuffleExec boundaries) to normalized text.
  • Golden suite (main.rs): #[tokio::test] cases q1..q22 comparing the live staged plan against approved/qN.txt; regenerate with BALLISTA_GENERATE_GOLDEN=1 (wrapped by dev/update-tpch-plan-stability.sh).
  • 22 approved plan files, the query SQL copied under queries/, a README.md, and a RAT exclusion for the header-less golden text files.

Scope (v1): TPC-H only, static planner, Ballista default config (SortMergeJoin). SHJ / adaptive variants can be added later as sibling golden directories.

Are there any user-facing changes?

No. Test infrastructure only. Adds a developer helper script dev/update-tpch-plan-stability.sh for regenerating the approved plans after an intended change.

andygrove added 6 commits July 8, 2026 12:34
Add the 8 TPC-H schemas (copied verbatim from benchmarks/src/bin/tpch.rs),
SF100 row-count constants, and staged_plan_text(query_name) which loads a
TPC-H query's SQL, registers stats-only tables, builds the physical plan
with the Ballista-configured planner (target_partitions=16), splits it into
distributed query stages via DefaultDistributedPlanner, and renders the
stages to normalized text. Copy the 22 TPC-H query SQL files and add
helper tests covering a single-statement query (q1) and a multi-statement
query with view DDL (q15).
Add dev/update-tpch-plan-stability.sh to regenerate approved golden
plans, and document the suite's scope, usage, and existing CI
coverage. No workflow changes needed: rust.yml already runs
workspace-wide cargo test/clippy/fmt jobs that pick up the new
[[test]] target automatically.
Fix outstanding cargo fmt --check deltas in fixtures.rs, stats_table.rs,
and the plan_stability_test! macro invocation in main.rs.

@avantgardnerio avantgardnerio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I very much intend to be changing these plans (for the better), but producing the same result. I'm happy to update them though - I think the value of seeing the plans checked in (and changed in PRs) is far higher than the maintenance cost.

@andygrove

Copy link
Copy Markdown
Member Author

LGTM. I very much intend to be changing these plans (for the better), but producing the same result. I'm happy to update them though - I think the value of seeing the plans checked in (and changed in PRs) is far higher than the maintenance cost.

This approach has prevented many regressions in Comet from accidental planning changes. It would be nice to expand this to the AQE use case as well. Currently it uses the static planner.

@andygrove andygrove merged commit 4f1d7da into apache:main Jul 8, 2026
17 checks passed
@andygrove andygrove deleted the tpch-plan-stability branch July 8, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants