Skip to content
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

fix handling of null values in arrow vectors #2195

Merged
merged 3 commits into from
Oct 11, 2024
Merged

fix handling of null values in arrow vectors #2195

merged 3 commits into from
Oct 11, 2024

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Oct 10, 2024

Call vector.toJSON instead of vector.toArray when there are null values.

closes #2194

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

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

To me this suggests that we can’t/shouldn’t use vector.toArray at all, and instead we should use the “slow” version vector.toJSON to let Arrow handle the conversion into usable JavaScript values. Maybe we could optimize it to allow vector.toArray if vector.nullCount is zero, though. But the type-specific handling of invalid values here seems likely to be wrong and not something that we want to replicate outside of Arrow.

src/options.js Outdated
const values = vector.toArray();
if (values.nullCount) {
const NULL = vector.type?.typeId === 5 /* Utf8 */ ? null : undefined;
for (let i = 0; i < values.length; ++i) if (!values.isValid(i)) values[i] = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

We can’t use assignment (mutation) here because this might not be a copy. According to the docs:

If this Vector contains a single Data chunk and the Vector's type is a primitive numeric type corresponding to one of the JavaScript TypedArrays, this method returns a zero-copy slice of the underlying TypedArray values. If there's more than one chunk, the resulting TypedArray will be a copy of the data from each chunk's underlying TypedArray values.

@Fil
Copy link
Contributor Author

Fil commented Oct 11, 2024

ok that's simpler 😓

@Fil Fil merged commit d707835 into main Oct 11, 2024
1 check passed
@Fil Fil deleted the fil/null-arrow branch October 11, 2024 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mishandling of Arrow's null values
2 participants