Skip to content

Commit 754a8d7

Browse files
committed
Split tensor extension types into multiple files
1 parent a3604ff commit 754a8d7

4 files changed

Lines changed: 83 additions & 58 deletions

File tree

datafusion/common/src/types/canonical_extensions/tensor.rs renamed to datafusion/common/src/types/canonical_extensions/fixed_shape_tensor.rs

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use crate::types::extension::DFExtensionType;
1919
use arrow::datatypes::DataType;
2020
use arrow_schema::ArrowError;
21-
use arrow_schema::extension::{ExtensionType, FixedShapeTensor, VariableShapeTensor};
21+
use arrow_schema::extension::{ExtensionType, FixedShapeTensor};
2222

2323
/// Defines the extension type logic for the canonical `arrow.fixed_shape_tensor` extension type.
2424
///
@@ -76,58 +76,3 @@ impl DFExtensionType for DFFixedShapeTensor {
7676
self.inner.serialize_metadata()
7777
}
7878
}
79-
80-
/// Defines the extension type logic for the canonical `arrow.variable_shape_tensor` extension type.
81-
///
82-
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism.
83-
#[derive(Debug, Clone)]
84-
pub struct DFVariableShapeTensor {
85-
inner: VariableShapeTensor,
86-
/// While we could reconstruct the storage type from the inner [`VariableShapeTensor`], we may
87-
/// choose a different name for the field within the [`DataType::List`] which can cause problems
88-
/// down the line (e.g., checking for equality).
89-
storage_type: DataType,
90-
}
91-
92-
impl ExtensionType for DFVariableShapeTensor {
93-
const NAME: &'static str = VariableShapeTensor::NAME;
94-
type Metadata = <VariableShapeTensor as ExtensionType>::Metadata;
95-
96-
fn metadata(&self) -> &Self::Metadata {
97-
self.inner.metadata()
98-
}
99-
100-
fn serialize_metadata(&self) -> Option<String> {
101-
self.inner.serialize_metadata()
102-
}
103-
104-
fn deserialize_metadata(
105-
metadata: Option<&str>,
106-
) -> Result<Self::Metadata, ArrowError> {
107-
VariableShapeTensor::deserialize_metadata(metadata)
108-
}
109-
110-
fn supports_data_type(&self, data_type: &DataType) -> Result<(), ArrowError> {
111-
self.inner.supports_data_type(data_type)
112-
}
113-
114-
fn try_new(
115-
data_type: &DataType,
116-
metadata: Self::Metadata,
117-
) -> Result<Self, ArrowError> {
118-
Ok(Self {
119-
inner: <VariableShapeTensor as ExtensionType>::try_new(data_type, metadata)?,
120-
storage_type: data_type.clone(),
121-
})
122-
}
123-
}
124-
125-
impl DFExtensionType for DFVariableShapeTensor {
126-
fn storage_type(&self) -> DataType {
127-
self.storage_type.clone()
128-
}
129-
130-
fn serialize_metadata(&self) -> Option<String> {
131-
self.inner.serialize_metadata()
132-
}
133-
}

datafusion/common/src/types/canonical_extensions/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@
2121
// under the License.
2222

2323
mod bool8;
24+
mod fixed_shape_tensor;
2425
mod json;
2526
mod opaque;
26-
mod tensor;
2727
mod timestamp_with_offset;
2828
mod uuid;
29+
mod variable_shape_tensor;
2930

3031
pub use bool8::DFBool8;
32+
pub use fixed_shape_tensor::DFFixedShapeTensor;
3133
pub use json::DFJson;
3234
pub use opaque::DFOpaque;
33-
pub use tensor::{DFFixedShapeTensor, DFVariableShapeTensor};
3435
pub use timestamp_with_offset::DFTimestampWithOffset;
3536
pub use uuid::DFUuid;
37+
pub use variable_shape_tensor::DFVariableShapeTensor;

datafusion/common/src/types/canonical_extensions/timestamp_with_offset.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ fn format_offset(minutes: i16) -> String {
186186
#[cfg(test)]
187187
mod tests {
188188
use super::*;
189+
use arrow::array::{StructArray, TimestampSecondArray};
189190
use arrow::datatypes::{Field, Fields};
190191
use chrono::{TimeZone, Utc};
192+
use std::sync::Arc;
191193

192194
#[test]
193195
fn test_pretty_print_timestamp_with_offset() -> Result<(), ArrowError> {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use crate::types::extension::DFExtensionType;
19+
use arrow::datatypes::DataType;
20+
use arrow_schema::ArrowError;
21+
use arrow_schema::extension::{ExtensionType, VariableShapeTensor};
22+
23+
/// Defines the extension type logic for the canonical `arrow.variable_shape_tensor` extension type.
24+
///
25+
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism.
26+
#[derive(Debug, Clone)]
27+
pub struct DFVariableShapeTensor {
28+
inner: VariableShapeTensor,
29+
/// While we could reconstruct the storage type from the inner [`VariableShapeTensor`], we may
30+
/// choose a different name for the field within the [`DataType::List`] which can cause problems
31+
/// down the line (e.g., checking for equality).
32+
storage_type: DataType,
33+
}
34+
35+
impl ExtensionType for DFVariableShapeTensor {
36+
const NAME: &'static str = VariableShapeTensor::NAME;
37+
type Metadata = <VariableShapeTensor as ExtensionType>::Metadata;
38+
39+
fn metadata(&self) -> &Self::Metadata {
40+
self.inner.metadata()
41+
}
42+
43+
fn serialize_metadata(&self) -> Option<String> {
44+
self.inner.serialize_metadata()
45+
}
46+
47+
fn deserialize_metadata(
48+
metadata: Option<&str>,
49+
) -> Result<Self::Metadata, ArrowError> {
50+
VariableShapeTensor::deserialize_metadata(metadata)
51+
}
52+
53+
fn supports_data_type(&self, data_type: &DataType) -> Result<(), ArrowError> {
54+
self.inner.supports_data_type(data_type)
55+
}
56+
57+
fn try_new(
58+
data_type: &DataType,
59+
metadata: Self::Metadata,
60+
) -> Result<Self, ArrowError> {
61+
Ok(Self {
62+
inner: <VariableShapeTensor as ExtensionType>::try_new(data_type, metadata)?,
63+
storage_type: data_type.clone(),
64+
})
65+
}
66+
}
67+
68+
impl DFExtensionType for DFVariableShapeTensor {
69+
fn storage_type(&self) -> DataType {
70+
self.storage_type.clone()
71+
}
72+
73+
fn serialize_metadata(&self) -> Option<String> {
74+
self.inner.serialize_metadata()
75+
}
76+
}

0 commit comments

Comments
 (0)