Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions parquet-variant-compute/src/variant_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ impl ExtensionType for VariantType {
}

fn supports_data_type(&self, data_type: &DataType) -> Result<(), ArrowError> {
// Note don't check for metadata/value fields here because they may be
// absent in shredded variants
if matches!(data_type, DataType::Struct(_)) {
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
Contributor Author

Choose a reason for hiding this comment

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

Yes for sure, however the current implementation only supports BinaryView. Here is a ticket that for supporting other types:

Ok(())
} else {
Expand All @@ -69,9 +67,8 @@ impl ExtensionType for VariantType {
}

fn try_new(data_type: &DataType, _metadata: Self::Metadata) -> Result<Self, ArrowError> {
let new_self = Self;
new_self.supports_data_type(data_type)?;
Ok(new_self)
Self.supports_data_type(data_type)?;
Ok(Self)
}
}

Expand Down Expand Up @@ -446,7 +443,7 @@ impl VariantArray {

/// Is the element at index null?
pub fn is_null(&self, index: usize) -> bool {
self.nulls().map(|n| n.is_null(index)).unwrap_or_default()
self.nulls().is_some_and(|n| n.is_null(index))
}

/// Is the element at index valid (not null)?
Expand Down Expand Up @@ -615,7 +612,7 @@ impl ShreddedVariantFieldArray {
}
/// Is the element at index null?
pub fn is_null(&self, index: usize) -> bool {
self.nulls().map(|n| n.is_null(index)).unwrap_or_default()
self.nulls().is_some_and(|n| n.is_null(index))
}

/// Is the element at index valid (not null)?
Expand Down Expand Up @@ -894,35 +891,31 @@ fn typed_value_to_variant(typed_value: &ArrayRef, index: usize) -> Variant<'_, '
///
/// So cast them to get the right type.
fn cast_to_binary_view_arrays(array: &dyn Array) -> Result<ArrayRef, ArrowError> {
let new_type = map_type(array.data_type());
let new_type = rewrite_to_view_types(array.data_type());
cast(array, &new_type)
}

/// replaces all instances of Binary with BinaryView in a DataType
fn map_type(data_type: &DataType) -> DataType {
fn rewrite_to_view_types(data_type: &DataType) -> DataType {
match data_type {
DataType::Binary => DataType::BinaryView,
DataType::List(field) => {
let new_field = field
.as_ref()
.clone()
.with_data_type(map_type(field.data_type()));
DataType::List(Arc::new(new_field))
}
DataType::List(field) => DataType::List(rewrite_field_type(field)),
DataType::Struct(fields) => {
let new_fields: Fields = fields
.iter()
.map(|f| {
let new_field = f.as_ref().clone().with_data_type(map_type(f.data_type()));
Arc::new(new_field)
})
.collect();
let new_fields: Fields = fields.iter().map(rewrite_field_type).collect();
DataType::Struct(new_fields)
}
_ => data_type.clone(),
}
}

fn rewrite_field_type(field: impl AsRef<Field>) -> Arc<Field> {
let field = field.as_ref();
let new_field = field
.clone()
.with_data_type(rewrite_to_view_types(field.data_type()));
Arc::new(new_field)
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
4 changes: 1 addition & 3 deletions parquet-variant-compute/src/variant_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ pub(crate) fn follow_shredded_path_element(
))
})?;

let shredding_state = ShreddingState::from(struct_array);

Ok(ShreddedPathStep::Success(shredding_state))
Ok(ShreddedPathStep::Success(struct_array.into()))
}
VariantPathElement::Index { .. } => {
// TODO: Support array indexing. Among other things, it will require slicing not
Expand Down
Loading