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

Ensure StructArrays check nullability of fields #3205

Merged
merged 1 commit into from
Nov 29, 2022

Conversation

Jefffrey
Copy link
Contributor

Which issue does this PR close?

Closes #1167

Rationale for this change

What changes are included in this PR?

Main fix: when building using StructArray::from, check that if child fields are set as non-nullable, then their values respect this; if they don't then will panic

Other fixes to StructArray::from:

  • Fix issue where if pass empty vector then it panics (since used to index [0] to get length to compare)
  • Fix issue where not checking datatype of field against values if vector is of size 1

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Nov 27, 2022
@Jefffrey
Copy link
Contributor Author

Jefffrey commented Nov 27, 2022

I was under the impression that child fields of a StructArray must have their values respect their nullability (given the linked issue), however given how many tests I needed to fix (particularly MapBuilder) I'm a bit more uncertain on this now... Would appreciate some clarification on expected behaviour.

@@ -916,7 +916,7 @@ mod tests {
#[test]
fn test_null_struct() {
let struct_type =
DataType::Struct(vec![Field::new("data", DataType::Int64, false)]);
DataType::Struct(vec![Field::new("data", DataType::Int64, true)]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This actually highlights a somewhat fun issue that I'm also running into with the row format (#3159), namely how to create a null StructArray with children that aren't nullable. I think new_null_array should discard the null mask for its children, but I'm not 100% sure. I need to think a bit more on this

@@ -286,8 +286,8 @@ mod tests {

let string_builder = builder.keys();
string_builder.append_value("joe");
string_builder.append_null();
string_builder.append_null();
string_builder.append_value("n1");
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably add an error to MapArrayBuilder so that it returns a meaningful error if you try to create a keys array with nulls. I believe this may overlap somewhat with #1697

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can give this a shot, but probably won't get much progress until the weekend, so can open a separate PR if needed

Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

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

Thank you for this, I believe this will likely cause some churn as this has not been being consistently handled previously, but as with when we started enforcing this on RecordBatch, I believe this will shake out for the better

@tustvold tustvold merged commit 1d6b5ab into apache:master Nov 29, 2022
@Jefffrey Jefffrey deleted the 1167_structarray_nullability branch November 29, 2022 10:24
@ursabot
Copy link

ursabot commented Nov 29, 2022

Benchmark runs are scheduled for baseline = 4926bad and contender = 1d6b5ab. 1d6b5ab is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

tustvold added a commit to tustvold/arrow-rs that referenced this pull request Nov 30, 2022
tustvold added a commit to tustvold/arrow-rs that referenced this pull request Nov 30, 2022
tustvold added a commit that referenced this pull request Dec 5, 2022
* Loosen nullability restrictions added in #3205 (#3226)

* Fix tests

* More test fixes

* Yet more incorrect tests

* Review feedback
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.

StructArray Nullability
3 participants