Repository navigation
Conversation
Signed-off-by: WenDing-Y <[email protected]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
| for field in schema: | ||
| if field.name in names: | ||
| column = table[field.name] | ||
| if column.type != field.type: |
There was a problem hiding this comment.
Potential failure when input blocks have promotable types
I found a reproducible issue through the public ray.data.from_arrow() and Dataset.union() APIs.
A Dataset created from int32 and int64 Arrow blocks infers id as int64. Unioning it with another Dataset whose id is also int64 passes planning-time validation, but fails during execution in AlignToSchema.
Minimal reproduction:
import ray
import pyarrow as pa
old = ray.data.from_arrow([
pa.table({"id": pa.array([1], type=pa.int32()), "source": ["old32"]}),
pa.table({"id": pa.array([2], type=pa.int64()), "source": ["old64"]}),
])
new = ray.data.from_arrow(
pa.table({"id": pa.array([3], type=pa.int64()), "extra": ["new"]})
)
combined = old.union(new, allow_missing_columns=True)
combined.take_all()This raises:
ValueError: Expected type int64 for union input column 'id', but found int32.
The original old.take_all() succeeds, so it appears that the Dataset-level schema inference permits type promotion, while the new block-level alignment requires exact type equality.
Could we support safely promotable block types during alignment, or otherwise reconcile the planning and execution behavior?
There was a problem hiding this comment.
Thanks for the clear reproduction. AlignToSchema now uses the same Arrow schema unification as Dataset schema inference to check whether a block can be promoted to the planned type, then applies a safe cast. Shared columns must still have matching types across the input Dataset schemas. Fix in e2b9e86181
The regression tests cover your int32/int64 case, floating-point and nested struct promotion, and rejection of a cast that would lose precision. All 18 tests in test_union.py passed locally using the Ray 2.60.0 native runtime with a compatibility shim.
Signed-off-by: WenDing-Y <[email protected]>
c0dc691 to
e2b9e86
Compare
Signed-off-by: WenDing-Y <[email protected]>
Signed-off-by: WenDing-Y <[email protected]>
|
Hi @Yin-1022, thanks again for the repro! The fix and regression test for the mixed int32/ |
Yin-1022
left a comment
There was a problem hiding this comment.
Thanks for the follow-up! I checked the fix and the added regression tests. The schema unification and safe casting approach addresses my original concern. The changes look good to me.
Thanks for confirming the fix. Could you submit an approval if you have the required permission? If not, could you point me to a Ray Data committer or the PR assignee who can review and approve it? @Yin-1022 |
Description
Add
Dataset.union(..., allow_missing_columns=True)so pipelines can combine inputs with evolving columns and feed a consistent schema into batch transforms and filters.Before
Dataset.union()expects matching input schemas. If columns differ, schema inference can list a field that some output blocks lack. Callers have to align the inputs before unioning them.After
The opt-in path requires a known Arrow schema for each input. Planning chooses columns in first-seen order and validates that shared columns have matching types. Each input block is aligned to that schema, with typed nulls for missing fields. The streaming union preserves all rows, including duplicates. The option defaults to
False.flowchart LR subgraph Before B1[Input blocks] --> B2[Streaming Union] --> B3[Output blocks with input schemas] end subgraph After[After with allow_missing_columns enabled] A1[Input blocks] --> A2[Align each block to the target Arrow schema] A2 --> A3[Streaming Union] --> A4[Output blocks with the target schema] A0[Logical plan computes the target schema] --> A2 end classDef added fill:#dcfce7,stroke:#15803d,color:#111827 class A0,A2 addedRelated issues
Related to #52939, which reports a missing-column failure during struct alignment and identifies cross-schema union as a possible enhancement. Searches for the proposed API and related union/schema work found no open PR implementing it.
Subsystems
API, logical planning, and physical planning. The physical planner uses the existing map execution path to align blocks before the streaming union.
Testing
python -m pytest -q --tb=short python/ray/data/tests/test_union.pypassed all 12 tests in the cloud workspace using the branch's Python source with the Ray 2.60.0 native runtime. Coverage includes Parquet combined with CSV, JSON, JSONL, and ORC, plus typed nulls, output column order, row preservation, and downstream filtering.AI assistance was used for implementation, tests, and drafting this description.