-
Notifications
You must be signed in to change notification settings - Fork 1k
Support reading/writing VariantArray to parquet with Variant LogicalType
#8408
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
Changes from 5 commits
8f16381
c35d758
e40d275
68ffd32
d19e72f
ddd5fb8
a75e4ca
e6cacd8
77f0d93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| //! Arrow Extension Type Support for Parquet | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I plan to consolidate the rest of the extension type handling in this module, to try and improve the current situation where
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| //! | ||
| //! This module contains mapping code to map Parquet [`LogicalType`]s to/from | ||
| //! Arrow [`ExtensionType`]s. | ||
| //! | ||
| //! Extension types are represented using the metadata from Arrow [`Field`]s | ||
| //! with the key "ARROW:extension:name". | ||
| use crate::basic::LogicalType; | ||
| use crate::schema::types::Type; | ||
| use arrow_schema::extension::ExtensionType; | ||
| use arrow_schema::Field; | ||
|
|
||
| /// Adds extension type metadata, if necessary, based on the Parquet field's | ||
| /// [`LogicalType`] | ||
| /// | ||
| /// Some Parquet logical types, such as Variant, do not map directly to an | ||
| /// Arrow DataType, and instead are represented by an Arrow ExtensionType. | ||
| /// Extension types are attached to Arrow Fields via metadata. | ||
| pub(crate) fn add_extension_type(arrow_field: Field, parquet_type: &Type) -> Field { | ||
| let result = match parquet_type.get_basic_info().logical_type() { | ||
| #[cfg(feature = "variant_experimental")] | ||
| Some(LogicalType::Variant) => { | ||
| arrow_field.with_extension_type(parquet_variant_compute::VariantType) | ||
alamb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| // TODO add other LogicalTypes here | ||
| _ => arrow_field, | ||
| }; | ||
| result | ||
alamb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// Return the Parquet logical type to use for the specified Arrow field, if any. | ||
| #[cfg(feature = "variant_experimental")] | ||
| pub(crate) fn logical_type_for_struct(field: &Field) -> Option<LogicalType> { | ||
| use parquet_variant_compute::VariantType; | ||
| // Check the name (= quick and cheap) and only try_extension_type if the name matches | ||
| // to avoid unnecessary String allocations in ArrowError | ||
mbrobbel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if field.extension_type_name()? != VariantType::NAME { | ||
| return None; | ||
| } | ||
| match field.try_extension_type::<VariantType>() { | ||
| Ok(VariantType) => Some(LogicalType::Variant), | ||
| // Given check above, this should not error, but if it does ignore | ||
| Err(_e) => None, | ||
| } | ||
|
Comment on lines
+57
to
+66
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you're working to make this more generic, but as a pattern this is also how Arrow C++ does the conversion (except in Arrow C++ we can just look at the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think it is a fine line to decide how much of the canonical extension types end up in the core parquet/Arrow API Including them all by default makes the initial developer experience nicer perhaps and keeps the code cleaner, but it makes it harder to customize the binary size / feature set In my mind I am trying to follow the existing pattern / guidelines (set by @tustvold I think) and I do think it makes sense, but I do understand there are tradeoffs involved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sorry, I think I was reflecting in my comment that you're doing exactly what Arrow C++ is doing here (canonical extension type support there is also controlled by compile-time flags, they're just on by default and it just manifests as missing field metadata). |
||
| } | ||
|
|
||
| #[cfg(not(feature = "variant_experimental"))] | ||
| pub(crate) fn logical_type_for_struct(field: &Field) -> Option<LogicalType> { | ||
| None | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is somewhat confusing to me in that the arrow type is encoded twice -- once on a
ParquetField(which has an arrowFieldin it) and once in thisValueField.Any help simplifing this would be most appreciated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't think I understand this part of the code well enough to suggest anything :(