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

Add PrimitiveArray::try_new (#3879) #4067

Merged
merged 3 commits into from
Apr 18, 2023

Conversation

tustvold
Copy link
Contributor

@tustvold tustvold commented Apr 12, 2023

Which issue does this PR close?

Part of #3879

Rationale for this change

Some codebases may want to avoid panicking, and whilst for PrimitiveArray the necessary checks are pretty inconsequential, for consistency we should provide a try_new method for all arrays.

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Apr 12, 2023
@tustvold tustvold force-pushed the primitive-array-try-new branch from d74b35e to b50bc34 Compare April 12, 2023 15:44
@tustvold tustvold marked this pull request as draft April 12, 2023 15:44
@tustvold tustvold force-pushed the primitive-array-try-new branch from b50bc34 to 1f869af Compare April 12, 2023 19:31
@tustvold tustvold marked this pull request as ready for review April 12, 2023 19:45
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Can you please add a test of this new code, ideally also exercising the error path as well?

if let Some(n) = nulls.as_ref() {
assert_eq!(values.len(), n.len());
if n.len() != values.len() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this redundant with checks from ArrayData. Is it inevitable that we'll have redundancy between the checks?

I am thinking of https://docs.rs/arrow/latest/arrow/array/struct.ArrayData.html#method.validate and friends

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the long-run we may be able to share code, but as the types of the buffers and the already validated constraints are different, I think some redundancy is inevitable. Fortunately most of this logic is fairly straightforward

assert_eq!(values.len(), n.len());
if n.len() != values.len() {
return Err(ArrowError::InvalidArgumentError(format!(
"Incorrect number of nulls for PrimitiveArray, expected {} got {}",
Copy link
Member

Choose a reason for hiding this comment

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

number of nulls could be confused.

Suggested change
"Incorrect number of nulls for PrimitiveArray, expected {} got {}",
"Incorrect length of null buffer for PrimitiveArray, expected {} got {}",

@tustvold tustvold merged commit 5323679 into apache:master Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants