Skip to content

fix(spark): prevent false-negative data skipping for prefix predicates - #20392

Closed
fhan688 wants to merge 2 commits into
apache:masterfrom
fhan688:fix-startswith-data-skipping-false-negative
Closed

fhan688 wants to merge 2 commits into
apache:masterfrom
fhan688:fix-startswith-data-skipping-false-negative

Conversation

@fhan688

@fhan688 fhan688 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Describe the issue this Pull Request addresses

Prefix predicates can incorrectly exclude files containing matching records when data skipping uses column statistics.

Currently, StartsWith(column, prefix) is translated into an equality-style range check:

minValue <= prefix AND maxValue >= prefix

For example, a file containing abc1 and abc9 is excluded by name LIKE 'abc%' because its minimum value is greater than abc, even though both records match.

Summary and Changelog

Correct prefix pruning to retain files whose statistics range may overlap the prefix range:

maxValue >= prefix
AND (minValue <= prefix OR startsWith(minValue, prefix))
  • Preserve files when either minimum or maximum statistics are unavailable.
  • Apply this optimization only to direct binary string attributes; conservatively fall back for transformed expressions and non-binary collations.
  • Add regression coverage for matching ranges, singleton values, empty prefixes, missing statistics, Unicode, and compound predicates.
  • Add range-based checks ensuring matching values are never incorrectly pruned.
  • Add COW/MOR query regression tests comparing results with data skipping enabled and disabled, including LIKE, startswith, and NOT LIKE.

Validation

Executed with Spark 3.5.9 and Java 11:

  • TestDataSkippingUtils: 64 passed, 1 skipped. The skipped test requires Spark 4 non-binary collation support.
  • TestDataSkippingQuery: all 5 tests passed, including the new COW/MOR regression.
  • Scala style checks and git diff --check passed.

Impact

Prefix queries retain matching files and return correct results when data skipping is enabled.

Predicates outside the supported optimization scope may scan additional files due to conservative fallback. Existing tables require no index rebuild. No configuration, storage-format, or public API changes are introduced.

Risk Level

low

The change is limited to positive prefix-predicate translation. Boundary tests, matching-value checks, and COW/MOR query comparisons verify correctness. Conservative fallback can increase scanning but avoids unsafe pruning.

Documentation Update

none

This restores the intended query behavior without adding configuration or features.

Contributor's checklist

  • Contributor's guide reviewed by the PR author.
  • Issue context and implementation details provided.
  • Regression tests added and executed.

@codecov-commenter

codecov-commenter commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.75%. Comparing base (91ffb05) to head (3b02fe2).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
.../org/apache/spark/sql/hudi/DataSkippingUtils.scala 80.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #20392      +/-   ##
============================================
- Coverage     80.75%   80.75%   -0.01%     
+ Complexity    35316    35315       -1     
============================================
  Files          2562     2562              
  Lines        144141   144146       +5     
  Branches      17558    17559       +1     
============================================
+ Hits         116403   116405       +2     
- Misses        19763    19768       +5     
+ Partials       7975     7973       -2     
Components Coverage Δ
hudi-common 84.18% <ø> (ø)
hudi-client 83.95% <ø> (-0.01%) ⬇️
hudi-flink 86.08% <ø> (+<0.01%) ⬆️
hudi-spark-datasource 74.20% <80.00%> (+<0.01%) ⬆️
hudi-utilities 78.35% <ø> (+<0.01%) ⬆️
hudi-cli 70.80% <ø> (ø)
hudi-hadoop 71.17% <ø> (ø)
hudi-sync 76.82% <ø> (ø)
hudi-io 81.57% <ø> (ø)
hudi-timeline-service 83.41% <ø> (-0.25%) ⬇️
hudi-cloud 81.01% <ø> (ø)
hudi-kafka-connect 57.90% <ø> (ø)
Flag Coverage Δ
common-and-other-modules 52.68% <0.00%> (-0.01%) ⬇️
flink-integration-tests 49.64% <ø> (-0.01%) ⬇️
hadoop-mr-java-client 43.93% <ø> (-0.01%) ⬇️
integration-tests 13.40% <0.00%> (+<0.01%) ⬆️
spark-client-hadoop-common 38.52% <0.00%> (-0.01%) ⬇️
spark-java-tests 52.58% <80.00%> (+<0.01%) ⬆️
spark-scala-tests 47.55% <0.00%> (-0.02%) ⬇️
utilities 37.00% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../org/apache/spark/sql/hudi/DataSkippingUtils.scala 80.00% <80.00%> (ø)

... and 17 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.

@github-actions github-actions Bot added the size:M PR with lines of changes in (100, 300] label Oct 19, 2026

@wombatu-kun wombatu-kun 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.

#19169 (closes #18791) already fixes this StartsWith translation with the same max >= prefix AND (min < prefix OR startsWith(min, prefix)) bound, so this PR duplicates it, as did my #20226, which I have closed in its favor. Could we consolidate there and land your data-skipping on/off query test in TestDataSkippingQuery as a follow-up once #19169 merges?

@fhan688

fhan688 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

#19169 (closes #18791) already fixes this StartsWith translation with the same max >= prefix AND (min < prefix OR startsWith(min, prefix)) bound, so this PR duplicates it, as did my #20226, which I have closed in its favor. Could we consolidate there and land your data-skipping on/off query test in TestDataSkippingQuery as a follow-up once #19169 merges?

Thanks for pointing this out. I compared the two implementations, and I agree that #19169 should remain the canonical production fix.

For non-null binary strings, the bounds are equivalent: this PR uses min <= prefix, while #19169 uses min < prefix; the equality case is already covered by startsWith(min, prefix). #19169 also preserves support for allowed
order-preserving transformations.

I’ll close this PR in favor of #19169 and submit the COW/MOR data-skipping on/off query regression test as a focused follow-up after #19169 merges.

I also noticed two defensive differences worth discussing separately on #19169: handling missing min/max statistics conservatively, and falling back for Spark 4 non-binary collations. I’ll raise those there rather than maintain a competing
implementation.

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