Skip to content

test(spark): add nested schema pruning coverage - #19406

Draft
yihua wants to merge 1 commit into
apache:masterfrom
yihua:test-nested-schema-pruning-coverage
Draft

test(spark): add nested schema pruning coverage#19406
yihua wants to merge 1 commit into
apache:masterfrom
yihua:test-nested-schema-pruning-coverage

Conversation

@yihua

@yihua yihua commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Describe the issue this Pull Request addresses

HoodieNestedSchemaPruning, the Catalyst optimizer rule that prunes nested (struct) schemas for Hudi relations, sat at roughly 30 percent line coverage. TestNestedSchemaPruningOptimization only exercised a single-nested-struct table, leaving several branches of the rule untested: the array and map cases of countLeaves, the successful-pruning path (getPrunedOutput / buildNewProjection / buildPrunedRelation), the no-op when the pruned schema has the same leaf count as the data schema, and the no-op when the optimizer flag is off.

Summary and Changelog

Test-only change. Extends TestNestedSchemaPruningOptimization with three cases that assert the optimized plan's read schema, pinning the exact pruned/unpruned schema rather than just that the query returns rows:

  • prunes nested struct when array and map columns are present: a MOR table with item struct<...>, tags array<struct<...>>, and props map<string, struct<...>>; projecting id, item.name prunes item down to name and drops the unreferenced complex columns. Because countLeaves is called on the full data schema, this exercises its ArrayType and MapType branches along with the whole successful-pruning path.
  • no-op when all nested sub-fields are selected: selecting every leaf keeps item as struct<name, price> (the leaf-count comparison is an equality, so the rule does not rewrite).
  • no-op when nested schema pruning is disabled: with spark.sql.optimizer.nestedSchemaPruning.enabled=false the rule short-circuits and item retains price even though only item.name is projected.

The plan-level schema assertion that the existing successful test performed inline is factored into a shared assertPrunedReadSchema helper used by both.

Impact

None. Adds test coverage only, no production code changes.

Risk Level

none

Documentation Update

none

Contributor's checklist

  • Read through contributor's guide
  • Enough context is provided in the sections above
  • Adequate tests were added if applicable

Extend TestNestedSchemaPruningOptimization to cover the previously
untested branches of HoodieNestedSchemaPruning (around 30 percent line
coverage):

- Prune a nested struct when array<struct> and map<string,struct> columns
  are also present, exercising the array and map branches of countLeaves
  and the full successful-pruning path (getPrunedOutput, buildNewProjection,
  buildPrunedRelation).
- No-op when every nested sub-field is selected, so the pruned schema has
  the same leaf count as the data schema.
- No-op when the nested schema pruning optimizer flag is disabled.

Factor the plan-level schema assertion shared with the existing successful
test into a single helper.
@github-actions github-actions Bot added the size:M PR with lines of changes in (100, 300] label Jul 29, 2026
@codecov-commenter

codecov-commenter commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.89%. Comparing base (a284d6e) to head (d674ee9).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #19406      +/-   ##
============================================
+ Coverage     74.83%   74.89%   +0.06%     
- Complexity    32332    32369      +37     
============================================
  Files          2574     2574              
  Lines        142978   142984       +6     
  Branches      17527    17536       +9     
============================================
+ Hits         106992   107086      +94     
+ Misses        27921    27832      -89     
- Partials       8065     8066       +1     
Components Coverage Δ
hudi-common 82.25% <ø> (+<0.01%) ⬆️
hudi-client 82.07% <ø> (+0.27%) ⬆️
hudi-flink 78.63% <ø> (-0.01%) ⬇️
hudi-spark-datasource 68.35% <ø> (+0.01%) ⬆️
hudi-utilities 71.18% <ø> (ø)
hudi-cli 15.32% <ø> (ø)
hudi-hadoop 63.53% <ø> (+0.03%) ⬆️
hudi-sync 70.67% <ø> (ø)
hudi-io 79.66% <ø> (+0.09%) ⬆️
hudi-timeline-service 83.44% <ø> (-0.79%) ⬇️
hudi-cloud 64.00% <ø> (ø)
hudi-kafka-connect 53.20% <ø> (ø)
Flag Coverage Δ
common-and-other-modules 47.77% <ø> (+<0.01%) ⬆️
flink-integration-tests 47.64% <ø> (+<0.01%) ⬆️
hadoop-mr-java-client 43.38% <ø> (-0.02%) ⬇️
integration-tests 13.63% <ø> (+<0.01%) ⬆️
spark-client-hadoop-common 48.71% <ø> (+<0.01%) ⬆️
spark-java-tests 51.46% <ø> (+0.08%) ⬆️
spark-scala-tests 46.09% <ø> (+<0.01%) ⬆️
utilities 36.65% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hudi-bot

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M PR with lines of changes in (100, 300]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants