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

nullif operating on ArrayRef #510

Closed
bjchambers opened this issue Jun 29, 2021 · 3 comments · Fixed by #2940
Closed

nullif operating on ArrayRef #510

bjchambers opened this issue Jun 29, 2021 · 3 comments · Fixed by #2940
Labels
enhancement Any new improvement worthy of a entry in the changelog

Comments

@bjchambers
Copy link
Contributor

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

The nullif kernel currently only applies to PrimitiveArray<T>. This makes it impossible to use with non-primitive types, which often arise when working with structured / nested data. Additionally, it seems like the nullif kernel should have a similar signature to filter -- where filter selects only the non-true rows, nullif nulls out the true rows.

Describe the solution you'd like
The signature of nullif changed to nullif(values: ArrayRef, condition: BooleanArray) -> Result<ArrayRef>.
Possibly the addition of the complement null_unless.

I have a draft that I think would work (can open a PR), but wanted to make sure that such a kernel is desirable, and understand whether it should use a different name to avoid API breakages (generic_nullif or something like that).

@bjchambers bjchambers added the enhancement Any new improvement worthy of a entry in the changelog label Jun 29, 2021
@jorgecarleitao
Copy link
Member

jorgecarleitao commented Jun 30, 2021

Yep, that aligns well with the other kernels, and it is in general preferable as it avoids others having to do the same.

I would use &dyn Array instead of ArrayRef as its argument, since there is no need to require Arcing an array for using the kernel. With this signature, we can write

let array: PrimtiveArray<i32> = ...;
let array = nullif(&array)?;

instead of

let array: PrimtiveArray<i32> = ...;
let array = nullif(Arc::new(array))?;

@bjchambers
Copy link
Contributor Author

bjchambers commented Jun 30, 2021 via email

bjchambers added a commit to bjchambers/arrow-rs that referenced this issue Jul 3, 2021
@bjchambers
Copy link
Contributor Author

Draft of the updated kernel is up. It still uses ArrayRef because there are a few cases where the reference to the input array is cloned and I'm not sure there is a good way to handle that taking &dyn Array (eg., wouldn't it have to clone the &dyn Arary to produce a new Array)?

Note that one of the added tests is failing for what I believe is a bug in struct equality (#514).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
2 participants