Skip to content

[Data] Fix Hive null_fallback partitions on the pandas path - #67363

Merged
richardliaw merged 6 commits into
ray-project:masterfrom
hzmsh:fix/hive-null-partition
Nov 20, 2026
Merged

richardliaw merged 6 commits into
ray-project:masterfrom
hzmsh:fix/hive-null-partition

Conversation

@hzmsh

@hzmsh hzmsh commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#67887 added opt-in Partitioning("hive", null_fallback=HIVE_DEFAULT_PARTITION), which reads a __HIVE_DEFAULT_PARTITION__ directory as None. With it set, two cases still go wrong when a reader produces pandas blocks, for example read_json(..., lines=True).

Before

  1. Filtering a null partition column with is_in raises ArrowTypeError. On the pandas path, a null partition column is filled with None. When that block is converted to Arrow, the all-None column gets type null, which pc.is_in rejects against a non-null value set:
partitioning = Partitioning("hive", null_fallback=HIVE_DEFAULT_PARTITION)
ds = ray.data.read_json(path, lines=True, partitioning=partitioning)
ds = ds.map_batches(lambda batch: batch, batch_format="pyarrow")
ds.filter(expr=col("year").is_in(["1970"])).count()
# ArrowTypeError: Array type doesn't match type of values set: null vs string
  1. When the file also contains the partition column, _add_partitions_to_dataframe casts the partition values [None, ...] to the file column's dtype (column.astype(df[field].dtype)) before checking for conflicts:
    • Boolean column with False: astype(bool) turns None into False, so the conflict is silently accepted instead of raising ValueError.
    • Integer column: astype(int) raises TypeError instead of the usual "different from in-data values" ValueError.

After

Testing

Run on this branch (b5f742a) and on master (71a71b8), WSL2, PyArrow 23.0.1:

Test target This branch master
test_partitioning.py 166 passed 160 passed
expressions/test_predicate.py 20 passed 18 passed
unit/test_expression_evaluator.py 38 passed 38 passed
datasource/test_json.py 64 passed 64 passed
datasource/test_csv.py 14 passed 14 passed
datasource/test_parquet.py 296 passed, 1 failed 296 passed, 1 failed
  • 8 new tests: 4 fail on master (test_read_json_pandas_null_partition_is_in, in_data=[False], in_data=[1], and is_in with strings on an all-null column), and 4 already pass on master (in_data=[None], in_data=[True], in_data=[None, True], and is_in with integers on an all-null column).
  • The test_parquet.py failure is test_get_parquet_dataset_fs_serialization_fallback, which fails on master too in my setup.
  • pre-commit run --files <changed files> passed.

Related to #67362: with #67887, null_fallback=HIVE_DEFAULT_PARTITION reads the null partition as None; this PR fixes the pandas path for it.

AI assistance

Co-developed with Claude Code (Claude Opus 5.5): the investigation, the fix, the tests and this description. I reviewed every changed line and ran the test commands above locally. I also used gemini 4 argon (high) for additional review and audit.

…ARTITION__"

Hive-style partitioning writes a null partition value as
key=__HIVE_DEFAULT_PARTITION__. Map that sentinel to None when parsing Hive
partition paths, pass None through _cast_value, and keep the partition
column's type when the value is None (predicate pruning and
FileBasedDatasource).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: hzmsh <[email protected]>
@hzmsh
hzmsh requested a review from a team as a code owner October 24, 2026 04:08
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

When a file also contains the partition column, compare a null partition
by checking that the column is all null; pc.equal returns null for null
inputs. Keep the partition column's type when the file's column is
null-typed, as an all-empty CSV column is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: hzmsh <[email protected]>
@ray-gardener ray-gardener Bot added docs An issue or change related to documentation data Ray Data-related issues community-contribution Contributed by the community labels Oct 24, 2026
@hzmsh

hzmsh commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Hi @bveeramani and @goutamvenkat-anyscale, microcheck is green, and the one Cursor Bugbot finding is fixed in a1e27955cf. This PR changes _parse_hive_path (#57625) and evaluate_predicate_on_partition (#65990), which you each merged. If you have time, would you mind taking a look, please? Thanks!

@Jadiouo Jadiouo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified against base 3608367 and PR head a1e2795 (Python 3.13, pyarrow 25.0.1).

  • On base, a null Hive partition reads back as the __HIVE_DEFAULT_PARTITION__ string and filter(col("year").is_null()) matches 0 rows. With the PR it reads back as None and matches 1 row, for both parquet and CSV, including multi-level partitions. field_types={"year": int} now works instead of raising ValueError.
  • The new tests fail on base (6 of 7) and all pass with the PR. The rest of test_partitioning.py shows no new failures (6 s3-fixture errors occur on both base and the PR in my environment).
  • I reproduced the Bugbot finding on b759b35 and confirmed it’s fixed in a1e2795.

One question: partition_filter callbacks such as d["year"] >= "2020" now raise TypeError on a null partition, since the value is None instead of a string. The new behavior is more correct, but would it be worth a note in the release notes?

LGTM.

@hzmsh

hzmsh commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for verifying this, @Jadiouo! The partition_filter change is listed under "Behaviour change" in the description; I'll leave the release-notes question to the maintainers.

@richardliaw

Copy link
Copy Markdown
Contributor

@jiangxt2 could you take a look?

Resolve conflicts with ray-project#67073 in partitioning.py and test_partitioning.py.

Signed-off-by: hzmsh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hzmsh

hzmsh commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi jiangxt2, thank you for the careful review and the clear repros! I reproduced both P2s locally and agree with all three comments. While checking the first one, I found that master has the mirror case (a file value of true under a null partition is accepted silently), so I plan to make both true and false raise, matching the Arrow path. I'll push the fix with public-API regression tests tomorrow and reply on each comment.

- pandas blocks (read_json with lines=True): a null partition only matches
  a file column that is all null. Casting None to the column's dtype turned
  it into False for bool columns and hid the conflict.
- V1 Parquet: fill a null partition with a typed null (the field_types type,
  or string), so the materialized column isn't null-typed.
- Update the partition value annotations and the schema docstring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: hzmsh <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit e9bb343. Configure here.

An all-null column is null-typed in Arrow, for example a Hive null
partition's column read with read_json(lines=True) once its block is
converted to Arrow. pyarrow's is_in rejects a null-typed input against a
string value set, so cast the nulls to the value set's type first. The
result doesn't change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: hzmsh <[email protected]>
@richardliaw

Copy link
Copy Markdown
Contributor

hi - assigned @AarryaSaraf to take a look at this PR - thanks!

@richardliaw

Copy link
Copy Markdown
Contributor

hi, also - there are merge conflicts, could you fix?

ray-project#67887 added opt-in null_fallback for Hive null partitions, which covers the
parser, Parquet and the Arrow path. Keep only what it leaves out on the pandas
path: a null partition vs the file column in _add_partitions_to_dataframe,
and is_in on a null-typed column.

Signed-off-by: hzmsh <[email protected]>
@hzmsh hzmsh changed the title [Data] Read Hive null partitions as None instead of "__HIVE_DEFAULT_PARTITION__" [Data] Fix Hive null_fallback partitions on the pandas path Nov 11, 2026
@hzmsh

hzmsh commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @richardliaw for the heads-up!

I merged master into this branch to resolve the conflicts.

While resolving them, I found that #67887 already covers most of this PR, so I narrowed it down:

  • Kept [Data][Delta DSv2][1/7] Shared Parquet and partitioning fixes for the Delta reader #67887's opt-in null_fallback (dropped changing the default to HIVE_DEFAULT_PARTITION).
  • Kept only the two fixes needed when a reader produces pandas blocks (for example, read_json(..., lines=True)):
    1. _pa_is_in: allow is_in on an all-null column converted from pandas.
    2. _add_partitions_to_dataframe: properly check a None partition value against an existing column in the file.

Locally, all 8 new tests pass, existing test suites match master, and pre-commit passes. CI will run on the new push.

I have also updated the title and description to match.

@richardliaw richardliaw added the go add ONLY when ready to merge, run all tests label Nov 18, 2026
@abhishekverma-ray
abhishekverma-ray self-requested a review November 18, 2026 06:26

@abhishekverma-ray abhishekverma-ray 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.

Thanks, this looks good to me. I checked the fix on master vs this branch: is_in, not in and the string form filter(expr="year in ['1970']") all fail on master once blocks are converted to Arrow, and all pass here.

@richardliaw
richardliaw merged commit c8c3247 into ray-project:master Nov 20, 2026
7 checks passed
@hzmsh
hzmsh deleted the fix/hive-null-partition branch November 20, 2026 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues docs An issue or change related to documentation go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants