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 example for ScalarStructBuilder::new_null, fix display for null ScalarValue::Struct #9238

Merged
merged 4 commits into from
Feb 16, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Feb 15, 2024

Which issue does this PR close?

Follow on to #9229
related to #9227

Rationale for this change

@NGA-TRAN asked internally about exactly what ScalarStructBuilder::new_null internally so I wanted to document it in an example here.

When I did the PR the display didn't match what I thought new_null did, so I fixed a bug in null display as well

What changes are included in this PR?

  1. Add a doc example for ScalarStructBuilder::new_null
  2. Fix bug in ScalarValue::Struct null display
  3. Add test for ScalarValue::Struct display
  4. Fix a typo

Are these changes tested?

Yes, new test and by CI

Are there any user-facing changes?

@alamb alamb changed the title Minor: Add example for ScalarStructBuilder::new_null Minor: Add example for ScalarStructBuilder::new_null, fix display for null ScalarValue::Struct Feb 15, 2024
@alamb alamb changed the title Minor: Add example for ScalarStructBuilder::new_null, fix display for null ScalarValue::Struct Add example for ScalarStructBuilder::new_null, fix display for null ScalarValue::Struct Feb 15, 2024
Comment on lines +44 to +46
/// Note this is different from a struct where each of the specified fields
/// are null (e.g. `{a: NULL}`)
///
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

@viirya viirya left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@alamb alamb marked this pull request as ready for review February 16, 2024 10:21
@@ -3103,6 +3103,11 @@ impl fmt::Display for ScalarValue {
// ScalarValue Struct should always have a single element
assert_eq!(struct_arr.len(), 1);

if struct_arr.null_count() == struct_arr.len() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the bug fix

let batch = RecordBatch::try_from_iter(vec![("s", arr as _)]).unwrap();

#[rustfmt::skip]
let expected = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This shows that new_null really does create a null value (and thus the change to impl Display is correct)

@alamb
Copy link
Contributor Author

alamb commented Feb 16, 2024

FYI @jayzhan211

Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

LGTM

@alamb alamb merged commit 14cb962 into apache:main Feb 16, 2024
23 checks passed
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.

4 participants