You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "cshuo (via GitHub)" <gi...@apache.org> on 2026/10/13 02:25:16 UTC

[I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

cshuo opened a new issue, #20296:
URL: https://github.com/apache/hudi/issues/20296

   ### Description
   
   Spark data skipping can silently omit matching rows after adding columns to the Column Stats Index (CSI).
   
   After adding `name` to the indexed column list, existing files may still lack statistics for `name`, even though they contain non-null names. When a query references both an originally indexed column and the newly indexed column, the partially indexed file is incorrectly pruned.
   
   For example, after changing the indexed column list from `age` to `age,name`:
   
   - `name = 'alice'` returns the matching row.
   - `age >= 0 AND name = 'alice'` incorrectly returns no rows with data skipping enabled.
   - The same combined predicate returns the matching row with data skipping disabled.
   
   This was reproduced with real Spark SQL writes and queries in a local regression test added to `TestDataSkippingQuery`.
   
   ### Environment
   
   - Hudi: `master` at `a41f6eaf7df0`, `1.3.0-SNAPSHOT`.
   - Spark: `3.5.9`.
   - Scala: `2.12.18`.
   - Java: `11`.
   - Table type: `COPY_ON_WRITE`.
   - Metadata and column statistics enabled.
   - Partition statistics disabled to isolate file-level CSI pruning.
   
   ### Steps to reproduce
   
   Use a fresh table location and wait for each INSERT to complete.
   
   ```sql
   SET hoodie.metadata.enable=true;
   SET hoodie.metadata.index.column.stats.enable=true;
   SET hoodie.metadata.index.partition.stats.enable=false;
   SET hoodie.metadata.index.column.stats.column.list=age;
   SET hoodie.enable.data.skipping=false;
   
   CREATE TABLE csi_partial_stats (
     id INT,
     name STRING,
     age INT,
     ts BIGINT,
     dt STRING
   ) USING hudi
   TBLPROPERTIES (
     primaryKey = 'id',
     orderingFields = 'ts',
     type = 'cow'
   )
   PARTITIONED BY (dt)
   LOCATION '/tmp/hudi-spark-csi-partial-stats';
   
   -- The name column exists in the data, but only age is indexed.
   INSERT INTO csi_partial_stats
   VALUES (1, 'alice', 25, 1, 'par1');
   
   SET hoodie.metadata.index.column.stats.column.list=age,name;
   
   -- Writing to another partition leaves the old file untouched.
   INSERT INTO csi_partial_stats
   VALUES (2, 'bob', 30, 2, 'par2');
   
   -- Returns (1, alice, 25).
   SELECT id, name, age
   FROM csi_partial_stats
   WHERE age >= 0 AND name = 'alice';
   
   SET hoodie.enable.data.skipping=true;
   
   -- Explicitly update the table property: changing only the session setting
   -- can leave the creation-time false setting in effect.
   ALTER TABLE csi_partial_stats
   SET TBLPROPERTIES ('hoodie.enable.data.skipping' = 'true');
   
   REFRESH TABLE csi_partial_stats;
   
   -- Returns (1, alice, 25).
   SELECT id, name, age
   FROM csi_partial_stats
   WHERE name = 'alice';
   
   -- Incorrectly returns no rows.
   SELECT id, name, age
   FROM csi_partial_stats
   WHERE age >= 0 AND name = 'alice';
   ```
   
   ### Expected behavior
   
   All three SELECTs should return:
   
   ```text
   1, alice, 25
   ```
   
   Enabling data skipping or adding a predicate satisfied by the matching row must not change the query result.
   
   ### Actual behavior
   
   | Predicate | Data skipping | Actual result |
   |---|---|---|
   | `age >= 0 AND name = 'alice'` | Disabled | `(1, alice, 25)` |
   | `name = 'alice'` | Enabled | `(1, alice, 25)` |
   | `age >= 0 AND name = 'alice'` | Enabled | Empty |
   
   The regression test confirms the required metadata state before executing these queries:
   
   - The CSI definition includes both `age` and `name`.
   - Two files have `age` statistics.
   - Only one file has `name` statistics.
   - Per-file statistics coverage is `{age}` for one file and `{age, name}` for the other.
   
   The test fails at the final query assertion:
   
   ```text
   Combined age/name predicate with data skipping enabled:
   Expected Array([1,alice,25]), but got Array()
   ```
   
   ### Root cause
   
   1. [`ColumnStatsIndexSupport`](https://github.com/apache/hudi/blob/a41f6eaf7df0/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/ColumnStatsIndexSupport.scala#L289-L313) pads missing per-file column statistics with `(null, null, null)`.
   
   2. [`DataSkippingUtils.genColumnValuesEqualToExpression`](https://github.com/apache/hudi/blob/a41f6eaf7df0/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/DataSkippingUtils.scala#L495-L501) translates `name = 'alice'` into:
   
      ```sql
      name_minValue <= 'alice' AND name_maxValue >= 'alice'
      ```
   
      For the old file, both bounds are NULL, so this predicate evaluates to SQL NULL rather than conservatively retaining the file.
   
   3. [`SparkBaseIndexSupport.getCandidateFiles`](https://github.com/apache/hudi/blob/a41f6eaf7df0/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/SparkBaseIndexSupport.scala#L115-L143) applies the translated predicate directly through `DataFrame.where`, which drops rows whose predicate evaluates to NULL. Its fallback only restores files entirely absent from the transposed index. The old file already appears because it has `age` statistics, so it is not restored.
   
   For the name-only query, the old file is absent from the requested statistics projection and is retained by the unindexed-file fallback. Adding the `age` predicate causes the file to appear in that projection and exposes the incorrect pruning.
   
   The data column is present from the first write; this is missing statistics, not a missing schema field or known all-null data.
   
   ### Suggested behavior
   
   Treat unavailable column statistics as unknown and retain a file whenever the available statistics cannot prove that the predicate is unsatisfiable.
   
   Spark already handles unknown null counts conservatively for `IS NULL` and `IS NOT NULL`. Equality and range predicates also need to account for incomplete statistics without conflating them with known all-null columns.
   
   ### Validation
   
   A local regression test was added to `TestDataSkippingQuery`:
   
   ```text
   Data skipping retains files with missing column statistics after index expansion
   ```
   
   The targeted ScalaTest run reproduced the incorrect empty result. Relevant sources were recompiled against locally built dependencies; a full Maven build and the complete test suite were not run. No production fix is included, and the regression test has not yet been published in a PR.
   
   ### Related issue
   
   The Flink reader has a separately reproduced issue involving partial column-statistics coverage: [apache/hudi#20289](https://github.com/apache/hudi/issues/20289).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "cshuo (via GitHub)" <gi...@apache.org>.
cshuo commented on issue #20296:
URL: https://github.com/apache/hudi/issues/20296#issuecomment-6355595410

   @imonteroq Thanks for sharing! We’ll continue following up on the fix in [apache/hudi#20328](https://github.com/apache/hudi/pull/20328). Missing column stats are tolerated by design and should only reduce pruning, not cause missing rows.
   
   BTW, could you open a separate issue to investigate the unexpected omissions of column stats? Please include the full exception messages and stack traces for `Stream not closed` / IOException on `.col-stats-*.log` files.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "voonhous (via GitHub)" <gi...@apache.org>.
voonhous commented on issue #20296:
URL: https://github.com/apache/hudi/issues/20296#issuecomment-6444672997

   Okay cool, let's create a parent ticket, to track all the bugs we need to fix under there. Each bug or type is one sub issue. Whichever you want to take, you can assign it to you or me. We can bring it to completion from there!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "voonhous (via GitHub)" <gi...@apache.org>.
voonhous commented on issue #20296:
URL: https://github.com/apache/hudi/issues/20296#issuecomment-6367089200

   I think this is the same class of problem as:
   https://github.com/apache/hudi/issues/20227
   https://github.com/apache/hudi/issues/20229
   https://github.com/apache/hudi/issues/19646
   
   So this is the fourth occurrence on Spark and another on Flink: https://github.com/apache/hudi/issues/20289
   
   
   Cases i can think of at the top of my head that we should also check are involving transforms in `OrderPreservingTransformation`:
   - `date_format`, `from_unixtime` with a format: formatted strings don't sort like dates (shown above).
   - `Multiply` / `Divide`: dividing or multiplying by a negative constant reverses the order. C * -1 = -2 against a file with min 1, max 3 gives -1 <= -2, which is false, so the file is pruned.
   - `BitwiseOr`: doesn't preserve order. 1 | 2 = 3 but 2 | 2 = 2.
   - `Add`, `ShiftLeft`: overflow wraps around in non-ANSI mode.
   - `to_unix_timestamp(stringCol, fmt)`: the string order of stringCol isn't the order of the parsed times.
   
   We need to add a test that will exhaustively cover such bugs:
   
   1. Add a property test at `TestDataSkippingUtils` level. No hudi tables so it runs fast
   2. Generate random values (use fixed seed) for each file (Must include NULLS)
   3. Compute each file's min, max and NULL count from those values. In some files, randomnly null out the stats for a column to simulate missing states
   4. For each predicate shape (=, <, IN, IS NULL, AND, OR, NOT, ...) and each whitelisted transform with random literals, check if every file where the orignal predicate is true for some raw row must survive the translated filter.
   
   
   With this the raw data is the reference answer, so the test doesn't depend on anyone's belief about a transform, so there's no ambiguity. With this taest, it would have caught all four bugs above, and it should fail for some of the ones that we are not catching today above. 
   
   LMK if you guys want me to pick it up. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "imonteroq (via GitHub)" <gi...@apache.org>.
imonteroq commented on issue #20296:
URL: https://github.com/apache/hudi/issues/20296#issuecomment-6345619696

   We hit this failure mode on `hudi-spark4.1-bundle:1.2.0` without any `column.list` change or schema evolution on the queried columns. A conjunctive filter `identifier = 1 AND date = 100` intermittently returned 0 rows on a COW table where each single-column predicate matched and the data was present:
   
   ```
   identifier = 1                → 1
   date = 100                    → 3
   identifier = 1 AND date = 100 → 0   (correct: 1)
   ```
   
   ~40% of test-suite runs before instrumentation; 0 reproductions in ~2,700 instrumented queries after. The `column_stats` partition is read via `getRecordsByKeyPrefixes`, and we saw recurring `Stream not closed`/`IOException` on `.col-stats-*.log` files in the same runs, so a plausible trigger is a transiently missing `(column, file)` stats record (partial MDT read or a data-commit/stats-commit visibility gap), though we could not isolate it.
   
   We then reproduced the mechanism deterministically: write file1 with `hoodie.metadata.index.column.stats.column.list=identifier`, expand to `identifier,date`, write file2. File1 shows stats for `identifier` but no `date` record, and the conjunction drops it: `catalog=0, load=0, skipping-off=1` (COW, `hoodie.write.table.version=6`, non-partitioned, S3).
   
   The point for this issue: the missing-stats state isn't only reachable via config changes; it can arise transiently in the wild, and when it does the result is silent row loss on conjunctive queries. This argues for the trigger-agnostic guard in #20328 (retain files whose conjunct stat columns show missing stats) rather than a fix scoped to index expansion.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "voonhous (via GitHub)" <gi...@apache.org>.
voonhous commented on issue #20296:
URL: https://github.com/apache/hudi/issues/20296#issuecomment-6420971544

   Done, raised a PR here: #20439. 
   
   I'll mark it as DNM first, the PR should fail as there are existing bugs that are not fixed yet.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "voonhous (via GitHub) via commits" <co...@hudi.apache.org>.
voonhous closed issue #20296: Spark data skipping drops matching rows after adding columns to the column stats index
URL: https://github.com/apache/hudi/issues/20296


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "cshuo (via GitHub)" <gi...@apache.org>.
cshuo commented on issue #20296:
URL: https://github.com/apache/hudi/issues/20296#issuecomment-6381342996

   Thanks @nsivabalan for reproducing these cases, and @voonhous for offering to build the tests. Agreed that the harness should exercise getCandidateFiles and partition pruning, with ANSI mode and session timezone as dimensions. It should also distinguish missing stats from NULL bounds produced by transforms on otherwise complete stats—the guard in [apache/hudi#20328](https://github.com/apache/hudi/pull/20328) addresses the former; the latter needs separate handling. Happy to help review the tests.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "voonhous (via GitHub)" <gi...@apache.org>.
voonhous commented on issue #20296:
URL: https://github.com/apache/hudi/issues/20296#issuecomment-6430101841

   Test failures are here: https://github.com/apache/hudi/actions/runs/40361179394/job/121707712154?pr=20439
   
   @cshuo How do you propose we split the work to fix the errors? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "cshuo (via GitHub)" <gi...@apache.org>.
cshuo commented on issue #20296:
URL: https://github.com/apache/hudi/issues/20296#issuecomment-6458086701

   > 15\. Okay cool, let's create a parent ticket, to track all the bugs we need to fix under there. Each bug or type is one sub issue. Whichever you want to take, you can assign it to you or me. We can bring it to completion from there!
   
   Thanks, @voonhous! I’ve created [apache/hudi#20449](https://github.com/apache/hudi/issues/20449) to track the data skipping correctness.  We can add issues for the remaining gaps and split them up from there.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "cshuo (via GitHub)" <gi...@apache.org>.
cshuo commented on issue #20296:
URL: https://github.com/apache/hudi/issues/20296#issuecomment-6432436541

   Thanks @voonhous for putting together the test!
   
   I suggest splitting the fixes by root cause:
   
   1. **Missing stats:** I’ll continue with #20328.
   2. **Prefix `LIKE`:** tracked in #20430.
   3. **Casts and arithmetic:** #19445 covers narrowing casts and negative factors; overflow and bitwise OR need tracking.
   4. **Date/time transformations:** #19481 covers formats and parsing; DST and extreme values need tracking.
   5. **NULL transformed bounds:** cover cases such as logarithms, where stats exist but a transformed bound is NULL.
   
   We can open new issues for the gaps and use #20439 to validate the fixes. Would you like to pick up any of these groups? I can help with the remaining fixes and reviews.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Spark data skipping drops matching rows after adding columns to the column stats index [hudi]

Posted by "nsivabalan (via GitHub)" <gi...@apache.org>.
nsivabalan commented on issue #20296:
URL: https://github.com/apache/hudi/issues/20296#issuecomment-6381016266

   Thanks @voonhous, agreed this is one class of bug, and the oracle-based property test is the right fix. Please go ahead and pick it up.
   
   We reproduced your list on a real table (Spark 3.5.3, 1.3.0-SNAPSHOT, single-file COW table, data skipping on vs. off, ANSI off). All of them return wrong results: multiply/divide by a negative, `BitwiseOr`, `Add`/`ShiftLeft` overflow, `date_format` with a non-sortable format, and `to_unix_timestamp(str, fmt)`. A few more gaps the test should cover:
   
   1. **`LIKE 'abc%'` on a plain column**, with no transform. The prefix match is rewritten as `min <= 'abc' <= max`, so a file with min=`abc1`, max=`abc9` is pruned (2 rows → 0). Filed separately as #20430, since it affects every prefix query.
   2. **Transforms that return NULL for real values.** `log10`/`ln` on a negative min, `to_date` on a string that can't be parsed, and decimal-narrowing casts all produce a NULL bound, and the file is dropped.
   3. **DST.** `date_format(ts, 'yyyy-MM-dd HH:mm')` (a big-endian format), `cast(ts as string)` and `from_utc_timestamp` all break across a fall-back transition (`America/New_York`, 2026-11-01). Please add session timezone as a test dimension alongside ANSI mode.
   4. **Casts.** `isCastPreservingOrdering` only excludes string ↔ numeric. `cast(bigint as int)` wraps around, and `cast(str as date)` / `to_date(str)` on unpadded strings like `2024-2-1` reorders values.
   
   | Predicate | rows (skipping off → on) |
   |---|---|
   | `s like 'abc%'` | 2 → 0 |
   | `i * -1 = -2` / `i / -1 = -2` | 1 → 0 |
   | `(b \| 2) = 3` | 1 → 0 |
   | `a + 1 < 0` / `shiftleft(a, 1) < 0` (overflow) | 1 → 0 |
   | `log10(n) < 0.5` / `ln(n) < 1.0` (min = -1) | 1 → 0 |
   | `date_format(dt, 'dd-MM-yyyy') = '15-03-2026'` | 1 → 0 |
   | `date_format(ts, 'yyyy-MM-dd HH:mm') > '2026-11-01 01:45'` (NY) | 1 → 0 |
   | `cast(ts as string) > '2026-11-01 01:45'` (NY) | 1 → 0 |
   | `from_utc_timestamp(ts, 'America/New_York') > ...` | 1 → 0 |
   | `to_date(sd) = date'2024-02-01'` / `cast(sd as date) = ...` | 1 → 0 |
   | `to_unix_timestamp(sd, 'yyyy-M-d') = ...` | 1 → 0 |
   | `to_date(sd2) >= date'2024-01-01'` (max string can't be parsed) | 1 → 0 |
   | `cast(l as int) < 0` | 1 → 0 |
   | `cast(dec as decimal(3,1)) >= 1.0` | 1 → 0 |
   
   One correction to the overall picture: `AllowedTransformationExpression` requires exactly one column reference, so `col + otherCol` is not matched. Also, `to_timestamp(str, fmt)` never reached the matcher in our run (Spark replaces it before Hudi sees it), so the `ParseToTimestamp` branch may be dead code on 3.5.
   
   For the harness, it would be good to go through `getCandidateFiles` rather than only `translateIntoColumnStatsIndexFilterExpr`, so the missing-stats handling from #20328 is covered too. The partition-stats path should be included as well.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org