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

feat: support reading OPTIONAL column in parquet_derive #5717

Merged
merged 2 commits into from
Jul 1, 2024

Conversation

double-free
Copy link
Contributor

Which issue does this PR close?

Closes #5716.

Rationale for this change

See details in the issue.

What changes are included in this PR?

Add definition level in macro code.

typed.read_records(num_records, None /*should use a Some(&mut Vec<i16>)*/, None, &mut vals)?;

Are there any user-facing changes?

No API change, extend parquet_derive to handle OPTIONAL columns.

@double-free double-free changed the title feat: support OPTIONAL column in parquet_derive feat: support reading OPTIONAL column in parquet_derive May 4, 2024
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.

Looks good to me -- thank you @double-free and sorry for the delay in review

I had one small request to update the comments. Let me know what you think

@@ -248,7 +248,13 @@ impl Field {
let write_batch_expr = quote! {
let mut vals = Vec::new();
if let #column_reader(mut typed) = column_reader {
typed.read_records(num_records, None, None, &mut vals)?;
let mut definition_levels = Vec::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please also update the documentation above

    /// `Option` types and references not supported

To reflect this change?

Copy link
Contributor Author

@double-free double-free Jun 30, 2024

Choose a reason for hiding this comment

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

Sure, I can make it explicit, but to align our understanding, I want to note that this change does NOT mean it supports Option<T> in the struct to be decoded.
It is to support fields that are marked as "optional" in schema, but in fact all values are non-null. This is very common when parsing parquet files generated by pyarrow, since by default all columns are optional. I reproduced it in unit test, by adding Option<T> in the struct to be encoded.

So this comment is still true, but I can make it explicit for the case I mentioned above:

    /// `Option` types and references not supported, but the column itself can be nullable (i.e., def_level==1), as long as the values are all valid.

How do you think? To update the comment or keep it as it is?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you

@double-free
Copy link
Contributor Author

Looks good to me -- thank you @double-free and sorry for the delay in review

I had one small request to update the comments. Let me know what you think

Thanks for your response! Please check my reply and see if we do need to update the code comment.

@alamb
Copy link
Contributor

alamb commented Jul 1, 2024

Thanks again @double-free

@alamb alamb merged commit 62c1615 into apache:master Jul 1, 2024
11 checks passed
@double-free double-free deleted the yy/nullable-field branch July 1, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[parquet_derive] support OPTIONAL (def_level = 1) columns by default
2 participants