Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions datafusion/common/src/types/canonical_extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod bool8;
mod fixed_shape_tensor;
mod json;
mod opaque;
mod parquet_variant;
mod timestamp_with_offset;
mod uuid;
mod variable_shape_tensor;
Expand All @@ -14,6 +15,7 @@ pub use bool8::DFBool8;
pub use fixed_shape_tensor::DFFixedShapeTensor;
pub use json::DFJson;
pub use opaque::DFOpaque;
pub use parquet_variant::DFVariant;
pub use timestamp_with_offset::DFTimestampWithOffset;
pub use uuid::DFUuid;
pub use variable_shape_tensor::DFVariableShapeTensor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements

use crate::Result;
use crate::types::extension::DFExtensionType;
use arrow::datatypes::DataType;
use arrow_schema::extension::{ExtensionType, VariantType};
use std::borrow::Cow;

/// Defines the extension type logic for the canonical `arrow.parquet.variant` extension type.
///
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism. See also
/// [`VariantType`] for the implementation of arrow-rs, which this type uses internally.
///
/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#parquet-variant>
#[derive(Debug, Clone)]
pub struct DFVariant {
storage_type: DataType,
}

impl DFVariant {
/// Creates a new [`DFVariant`], validating that the storage type is compatible with the
/// extension type.
pub fn try_new(
data_type: &DataType,
metadata: <VariantType as ExtensionType>::Metadata,
) -> Result<Self> {
VariantType::try_new(data_type, metadata)?;
Ok(Self {
storage_type: data_type.clone(),
})
}
}

impl DFExtensionType for DFVariant {
fn storage_type(&self) -> DataType {
self.storage_type.clone()
}

fn serialize_metadata(&self) -> Option<String> {
VariantType.serialize_metadata()
}

fn display_name(&self) -> Option<Cow<'_, str>> {
Some(Cow::Borrowed("VARIANT"))
}
}
13 changes: 11 additions & 2 deletions datafusion/expr/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use arrow::datatypes::Field;
use arrow_schema::DataType;
use arrow_schema::extension::{
Bool8, ExtensionType, FixedShapeTensor, Json, Opaque, TimestampWithOffset, Uuid,
VariableShapeTensor,
VariableShapeTensor, VariantType,
};
use datafusion_common::types::{
DFBool8, DFExtensionTypeRef, DFFixedShapeTensor, DFJson, DFOpaque,
DFTimestampWithOffset, DFUuid, DFVariableShapeTensor,
DFTimestampWithOffset, DFUuid, DFVariableShapeTensor, DFVariant,
};
use datafusion_common::{HashMap, Result, not_impl_err, plan_datafusion_err};
use std::collections::HashSet;
Expand Down Expand Up @@ -480,6 +480,15 @@ impl MemoryExtensionTypeRegistry {
Bool8::deserialize_metadata(metadata)?,
)?))
}),
ExtensionTypeRegistration::new_arc(
VariantType::NAME,
|storage_type, metadata| {
Ok(Arc::new(DFVariant::try_new(
storage_type,
VariantType::deserialize_metadata(metadata)?,
)?))
},
),
ExtensionTypeRegistration::new_arc(
TimestampWithOffset::NAME,
|storage_type, metadata| {
Expand Down