← Back to Pull requests

GH-3574: Preserve null counts when min/max exceed limit #3819

Open
efegokdemir opened this pull request with 97 lines diff across 2 files
View on GitHub
efegokdemir efegokdemir commented on Sep 25, 2026 07:05 UTC
Author

Summary

Preserve null_count when a column's min/max statistics exceed the metadata size limit.

The size guard is needed for min/max values, but null_count is a compact independent statistic and remains useful to readers. This keeps the null count available without reintroducing oversized min/max metadata.

Changes

  • Emit null_count and nan_count before applying the min/max size limit for non-empty statistics.

  • Keep min/max omission behavior unchanged for oversized statistics.

  • Extend the binary statistics round-trip test to cover the preserved counts.
  • Testing

  • git diff --check passed.

  • The focused Maven test and Spotless check could not be run in this environment because no Java runtime is installed.
  • Compatibility note

    For oversized, non-empty statistics, this changes the result from no statistics to counts without min/max. This is narrower than the unconditional null-count change reverted in #3688, but it still changes the previous all-or-nothing behavior. That compatibility question is under discussion.

    Fixes #3574

    Diff: 97 lines (+66 / -31) across 2 files Reviewer: divjotarora Review duration: 98242m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.39) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 97 lines diff across 2 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.95 · 5 substantive comment(s)
    0.95
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    90%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.274
    Real PR Conversation Timeline
    14 items
    divjotarora divjotarora commented on code on Sep 25, 2026 07:55 UTC
    Code Review
    parquet-hadoop/src/main/java/org/apache/parquet/format/converter/ParquetMetadataConverter.java:1
    @@ -828,35 +828,43 @@ public static Statistics toParquetStatistics(
         // rationale is that some engines may use the minimum value in the page as
         // the true minimum for aggregations and there is no way to mark that a
         // value has been truncated and is a lower bound and not in the page.
    -    if (!stats.isEmpty() && withinLimit(stats, truncateLength)) {
    -      formatStats.setNull_count(stats.getNumNulls());
    -      if (stats.isNanCountSet()) {
    -        formatStats.setNan_count(stats.getNanCount());
    +    if (stats.isEmpty()) {
    +      return formatStats;
    +    }
    +
    +    // null_count is independent of the min/max size limit and remains useful
    +    // when min/max values are omitted.
    +    formatStats.setNull_count(stats.getNumNulls());
    +    if (!withinLimit(stats, truncateLength)) {
    +      return formatStats;
    +    }
    +
    +    if (stats.isNanCountSet()) {
    +      formatStats.setNan_count(stats.getNanCount());
    +    }

    Why not move this before the withinLimit check as well? Seems the reasoning can be that fixed-width stats (e.g. counts) can always be published while variable-length stats (min/max) are published only if withinLimit.

    divjotarora divjotarora approved these changes on Sep 25, 2026 08:00 UTC
    Approved Reviewer

    Thanks @efegokdemir!

    efegokdemir efegokdemir commented on code on Sep 30, 2026 22:08 UTC
    Code Review
    parquet-hadoop/src/main/java/org/apache/parquet/format/converter/ParquetMetadataConverter.java:1
    @@ -828,35 +828,43 @@ public static Statistics toParquetStatistics(
         // rationale is that some engines may use the minimum value in the page as
         // the true minimum for aggregations and there is no way to mark that a
         // value has been truncated and is a lower bound and not in the page.
    -    if (!stats.isEmpty() && withinLimit(stats, truncateLength)) {
    -      formatStats.setNull_count(stats.getNumNulls());
    -      if (stats.isNanCountSet()) {
    -        formatStats.setNan_count(stats.getNanCount());
    +    if (stats.isEmpty()) {
    +      return formatStats;
    +    }
    +
    +    // null_count is independent of the min/max size limit and remains useful
    +    // when min/max values are omitted.
    +    formatStats.setNull_count(stats.getNumNulls());
    +    if (!withinLimit(stats, truncateLength)) {
    +      return formatStats;
    +    }
    +
    +    if (stats.isNanCountSet()) {
    +      formatStats.setNan_count(stats.getNanCount());
    +    }

    Implemented in the current HEAD . is now written before the gate, while variable-length min/max statistics remain gated by the size limit. The regression asserts null-count preservation for oversized binary statistics.

    efegokdemir efegokdemir commented on code on Sep 30, 2026 22:08 UTC
    Code Review
    parquet-hadoop/src/main/java/org/apache/parquet/format/converter/ParquetMetadataConverter.java:1
    @@ -828,35 +828,43 @@ public static Statistics toParquetStatistics(
         // rationale is that some engines may use the minimum value in the page as
         // the true minimum for aggregations and there is no way to mark that a
         // value has been truncated and is a lower bound and not in the page.
    -    if (!stats.isEmpty() && withinLimit(stats, truncateLength)) {
    -      formatStats.setNull_count(stats.getNumNulls());
    -      if (stats.isNanCountSet()) {
    -        formatStats.setNan_count(stats.getNanCount());
    +    if (stats.isEmpty()) {
    +      return formatStats;
    +    }
    +
    +    // null_count is independent of the min/max size limit and remains useful
    +    // when min/max values are omitted.
    +    formatStats.setNull_count(stats.getNumNulls());
    +    if (!withinLimit(stats, truncateLength)) {
    +      return formatStats;
    +    }
    +
    +    if (stats.isNanCountSet()) {
    +      formatStats.setNan_count(stats.getNanCount());
    +    }

    Correction: current HEAD ca2fdbe writes null_count before the withinLimit gate while retaining the min/max size gate. The regression verifies null-count preservation for oversized binary statistics.

    divjotarora divjotarora commented on Oct 01, 2026 10:42 UTC
    Reviewer

    @efegokdemir My previous comment was not addressed, the current code still sets NaN count stats after the withinLimit check. I suggest we set null + NaN stats unconditionally and guard only min/max by the withinLimit check.

    Proposed code:

    formatStats.setNull_count(stats.getNumNulls());
    if (stats.isNanCountSet()) {
        formatStats.setNan_count(stats.getNanCount());
    }
    
    if (!withinLimit(stats, truncateLength)) {
        return formatStats;
    }
    
       

    efegokdemir efegokdemir commented on Oct 02, 2026 22:17 UTC
    Author

    Moved nan_count alongside null_count before the withinLimit early return; min/max remain size-gated. Added testNanCountIsPreservedWhenMinMaxExceedLimit, which forces the floating-point stats size check over the limit and verifies null count, NaN count, and omitted min/max. The pushed remote HEAD is d015ab76dd7d2c9bf79f5795d971ee1c3a568f23, and I verified both changed files at that SHA. git diff --check passed. Focused Maven/Spotless validation could not run: the wrapper reports “Unable to locate a Java Runtime” in this environment.

    wgtmac wgtmac commented on Oct 08, 2026 07:20 UTC
    Contributor

    IIUC, this PR will hit the same issue as https://github.com/apache/parquet-java/pull/3688?

    cc @Fokko

    efegokdemir efegokdemir commented on Oct 08, 2026 10:25 UTC
    Author

    Thanks for flagging #3688. At the current head, this change emits null_count and nan_count only for non-empty stats that fail the min/max size check; it still creates counts-only metadata where the old code emitted none. That is narrower than #3688’s unconditional behavior, but it does change the all-or-nothing contract. I have corrected the PR description to make that scope and compatibility question explicit. I will hold further code changes pending maintainer direction on whether this contract change is acceptable for #3574.

    divjotarora divjotarora commented on Oct 08, 2026 14:05 UTC
    Contributor

    @wgtmac Do you have a link to some discussion on why we reverted the previous change? https://github.com/apache/parquet-java/pull/3688 has very little context

    wgtmac wgtmac commented on Oct 08, 2026 15:13 UTC
    Contributor

    @divjotarora Sorry I cannot find any concrete evidence right now. If I remember it correctly, that change may break Iceberg to consume Parquet statistics. Perhaps @kevinjqliu @Fokko could provide more detail.

    Fokko Fokko commented on Oct 12, 2026 06:46 UTC
    Contributor

    The issue is described on the devlist: https://lists.apache.org/thread/fx96wnmkbmx7pcz2h89t592ztc8bcrn1 I'm unable to open it ritght now.

    It had to do with the semantic meaning of isEmpty of the statistics. I believe it was something that we expect everything to be set on Iceberg when isEmpty is false. Ideally, we want to check what we break with this change.

    divjotarora divjotarora commented on Oct 12, 2026 07:26 UTC
    Contributor

    @Fokko Thanks for the link. Unfortunately, it doesn't load for me, just says "Could not load this thread". Seems like this is an issue on the Iceberg side? Is it a general spec issue in Iceberg or localized to a subset of implementations?

    Fokko Fokko commented on Oct 12, 2026 14:23 UTC
    Contributor

    The build has been unblocked for me after https://github.com/apache/parquet-java/pull/3855 (thanks @wgtmac for the quick review). I've published the jar locally using mvn install -DskipTests and bumped Iceberg to 1.19.0-SNAPSHOT (make sure that you're on the latest main that includes https://github.com/apache/iceberg/pull/18347).

    I ran the tests and it passed all the tests on the Iceberg side:

    BUILD SUCCESSFUL in 56m 29s
    130 actionable tasks: 65 executed, 65 up-to-date
    

    I would have to check what the difference is between this one, and the previous PR, but this seems to play nicer with Iceberg 👍

    Reviewers
    Assignees
    efegokdemir efegokdemir
    Labels
    risk: low confidence: 90.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.9% (MEDIUM) · Higher = larger blast radius
    38.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.8% · Lower = rushed or shallow review
    90.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.6% · Safe to merge
    3.6%