Repository navigation
Parquet: map the FILE logical type to the arrow.parquet.file extension type - #11877
Conversation
…n type Co-authored-by: Isaac <[email protected]>
…tension Co-authored-by: Isaac <[email protected]>
|
Hi @dejankrak-db, thanks for the submission. We've been pretty swamped lately by AI slop, so I've been slow to get deep in my queue. I'll try to give this a look soon. |
etseidl
left a comment
There was a problem hiding this comment.
Thanks @dejankrak-db, this looks good to me, but I'll admit to not being super familiar with this part of the code.
@sdf-jkl or @Rich-T-kid perhaps one of you have a few free cycles to take a look 🙏
| /// When reading, a `FILE`-annotated group is returned as a struct with this | ||
| /// extension type. When writing, a struct field with this extension type is | ||
| /// written as a `FILE`-annotated group. |
There was a problem hiding this comment.
Small doc nit my agent brought up, it's possible that a parquet file could have the FILE annotation in the parquet schema, but the embedded arrow schema says it's a plain struct. On read, if the embedded schema is used, the FILE annotation is lost. This isn't anything new or unique to this extension, but it is a caveat that might be worth mentioning here. The workaround is to read with skip_arrow_metadata set to true.
There was a problem hiding this comment.
Good point, added a note to the FileType docs with the skip_arrow_metadata workaround.
|
taking a look right now |
|
seeing as there are a few issues/prs that im missing context on I wont be able to finish reviewing this until tonight if you'd like to hold off on merging |
|
Thanks @Rich-T-kid. No rush. |
Co-authored-by: Isaac <[email protected]> Signed-off-by: Dejan Krakovic <[email protected]>
Rich-T-kid
left a comment
There was a problem hiding this comment.
Looks good to me, left two minor comments. thanks @dejankrak-db & @etseidl for the ping
| fn deserialize_metadata(_metadata: Option<&str>) -> Result<Self::Metadata, ArrowError> { | ||
| Ok("") | ||
| } |
There was a problem hiding this comment.
FileType serializes its metadata as an empty string, but this accepts every metadata value. Since logical_type_for_struct relies on has_valid_extension_type, a field carrying arbitrary or potentially incompatible future metadata is still written as Parquet FILE.
There was a problem hiding this comment.
Good catch. deserialize_metadata now rejects anything but empty metadata, as Uuid does, so such a field is written as a plain group. Added a test.
| /// files whose annotation does not carry version 1. The value written is | ||
| /// [`parquet_variant::VARIANT_SPEC_VERSION`], the same version stamped into | ||
| /// every metadata header. | ||
| #[cfg(feature = "variant_experimental")] | ||
| #[cfg(any(feature = "variant_experimental", feature = "file_experimental"))] |
There was a problem hiding this comment.
should we also update the doc comment here or is it still accurate?
There was a problem hiding this comment.
Oh, good catch. I think the variant bits should be separately gated now. Although reading it now, I wonder if that level of detail even belongs in the docs 🤷
There was a problem hiding this comment.
Made the doc general and moved the Variant version detail into a comment on the Variant branch.
…ruct docs Co-authored-by: Isaac <[email protected]> Signed-off-by: Dejan Krakovic <[email protected]>
Rich-T-kid
left a comment
There was a problem hiding this comment.
nice work @dejankrak-db
|
Thanks @etseidl and @Rich-T-kid! I have addressed all the comments, can we merge this change? |
| /// every metadata header. | ||
| #[cfg(feature = "variant_experimental")] | ||
| /// Return the Parquet logical type to use for the specified Arrow Struct field, if any: | ||
| /// `VARIANT` for the Variant extension type and `FILE` for `FileType`. |
There was a problem hiding this comment.
Not going to delay any longer on this, but if we add a third extension I think I'd not mention any return types here and instead enumerate them in the module docstring.
Which issue does this PR close?
Rationale for this change
#10109 added the Parquet
FILElogical type, but not its Arrow mapping. AFILEgroup reads as a plain struct, andArrowWritercannot write the annotation, so Arrow-based writers cannot produce conformingFILEcolumns.What changes are included in this PR?
Following the Variant precedent:
parquet::arrow::file_type::FileTypeextension type, namedarrow.parquet.file, with no metadata. Its storage is a struct whose fields are any subset ofuri,offset,size,content_type,checksum,inline, each nullable, matching the Parquet-side validation from parquet: introduceFILElogical type #10109 (string fields acceptUtf8/LargeUtf8/Utf8View,inlineaccepts any binary type).try_add_extension_type/has_extension_typetag aFILEgroup withFileType.logical_type_for_structreturnsLogicalType::Filefor a struct field withFileType; its gating now covers eithervariant_experimentalorfile_experimental. Sub-field ids come from the existingPARQUET:field_idmetadata.file_experimentalfeature (also part ofexperimental), documented in the README and crate docs, and a CI compile check with--no-default-features --features file_experimental.Are these changes tested?
Yes, in
parquet/src/arrow/file_type.rs: accepted and rejected struct shapes, an Arrow to Parquet to Arrow schema round trip (annotation and field ids), a struct without the extension staying unannotated, andArrowWriterwrite and read round trips at the top level and as a list element.Locally:
cargo test -p parquet --all-features --libpasses,cargo clippy -p parquet --all-targets --all-features -- -D warningsis clean, docs build with-D warnings, andcargo check -p parquetpasses with default features,variant_experimentalonly, andfile_experimentalonly.Are there any user-facing changes?
A new, experimental, opt-in
file_experimentalfeature andFileTypeextension type. No change without the feature.The code, tests, and this description were drafted with an AI assistant and reviewed by me before submitting.
This pull request and its description were written by Isaac.