-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix nullable Array columns in partitioned DataFrameScan #24131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -227,26 +227,31 @@ async def dataframescan_node( | |
|
|
||
| # Build list of IR slices to read | ||
| ir_slices = [] | ||
| # Partial workaround for | ||
| # https://github.com/pola-rs/polars/issues/23214 If a struct column | ||
| # has nulls and is sliced then polars exports invalid validity | ||
| # buffers. We can't detect this exact state because we can't know | ||
| # when the column is sliced. | ||
| copy_slice = any( | ||
| # Partial workarounds for sliced nested columns. Polars exports invalid | ||
| # validity buffers for struct columns with nulls | ||
| # (https://github.com/pola-rs/polars/issues/23214), and double-counts | ||
| # offsets for Array columns with outer nulls | ||
| # (https://github.com/pola-rs/polars/pull/28602). | ||
| dtypes = ir.df.dtypes() | ||
| has_struct = any( | ||
| isinstance(dt, pl.Struct) | ||
| for dt in pl.datatypes.unpack_dtypes(ir.df.dtypes(), include_compound=True) | ||
| for dt in pl.datatypes.unpack_dtypes(dtypes, include_compound=True) | ||
| ) | ||
| array_columns = tuple( | ||
| name | ||
| for name, dtype in zip(ir.df.columns(), dtypes, strict=True) | ||
| if isinstance(dtype, pl.Array) | ||
| ) | ||
|
|
||
| for seq_num in range(local_count): | ||
| offset = local_offset * rows_per_partition + seq_num * rows_per_partition | ||
| if offset >= nrows: | ||
| break | ||
| sliced = ir.df.slice(offset, rows_per_partition) | ||
| if copy_slice: | ||
| # OK, we have structs that might have nulls, and we're | ||
| # slicing. So let's copy to contiguous storage. This is | ||
| # hacky and doesn't handle the case where we didn't slice | ||
| # but the user sliced the input. | ||
| if has_struct or any( | ||
| sliced.get_column(name).null_count() > 0 for name in array_columns | ||
| ): | ||
| # Copy the affected slice to contiguous storage before Arrow export. | ||
|
coderabbitai[bot] marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably worth keeping the "doesn't handle the case where ..." caveat, assuming that's still true.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked this with pre-sliced, nonzero-offset Struct and Array inputs. Even when streaming creates single partition, this path still serializes and deserializes the slice, which compacts input correctly. Old caveat is not true, I'd prefer not to restore it. |
||
| f = io.BytesIO() | ||
| sliced.serialize_binary(f) | ||
| f.seek(0) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to avoid looping over
df.columns()/dtypestwice. Roughly:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes sense.
unpack_dtypesreturns a set, I'll useany(...)for Struct check while combining both checks into one loop.