tobixdev commented on code in PR #21291:
URL: https://github.com/apache/datafusion/pull/21291#discussion_r3021286675


##########
datafusion/common/src/types/canonical_extensions/timestamp_with_offset.rs:
##########
@@ -0,0 +1,241 @@
+// 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.
+
+use crate::ScalarValue;
+use crate::error::_internal_err;
+use crate::types::extension::DFExtensionType;
+use arrow::array::{Array, AsArray, Int16Array};
+use arrow::buffer::NullBuffer;
+use arrow::datatypes::{
+    DataType, Int16Type, TimeUnit, TimestampMicrosecondType, 
TimestampMillisecondType,
+    TimestampNanosecondType, TimestampSecondType,
+};
+use arrow::util::display::{ArrayFormatter, DisplayIndex, FormatOptions, 
FormatResult};
+use arrow_schema::ArrowError;
+use arrow_schema::extension::{ExtensionType, TimestampWithOffset};
+use std::fmt::Write;
+
+/// Defines the extension type logic for the canonical 
`arrow.timestamp_with_offset` extension type.
+///
+/// See [`DFExtensionType`] for information on DataFusion's extension type 
mechanism.
+#[derive(Debug, Clone)]
+pub struct DFTimestampWithOffset {
+    inner: TimestampWithOffset,
+    storage_type: DataType,
+}
+
+impl ExtensionType for DFTimestampWithOffset {
+    const NAME: &'static str = TimestampWithOffset::NAME;
+    type Metadata = <TimestampWithOffset as ExtensionType>::Metadata;
+
+    fn metadata(&self) -> &Self::Metadata {
+        self.inner.metadata()
+    }
+
+    fn serialize_metadata(&self) -> Option<String> {
+        self.inner.serialize_metadata()
+    }
+
+    fn deserialize_metadata(
+        metadata: Option<&str>,
+    ) -> Result<Self::Metadata, ArrowError> {
+        TimestampWithOffset::deserialize_metadata(metadata)
+    }
+
+    fn supports_data_type(&self, data_type: &DataType) -> Result<(), 
ArrowError> {
+        self.inner.supports_data_type(data_type)
+    }
+
+    fn try_new(
+        data_type: &DataType,
+        metadata: Self::Metadata,
+    ) -> Result<Self, ArrowError> {
+        Ok(Self {
+            inner: <TimestampWithOffset as ExtensionType>::try_new(data_type, 
metadata)?,
+            storage_type: data_type.clone(),
+        })
+    }
+}
+
+impl DFExtensionType for DFTimestampWithOffset {
+    fn storage_type(&self) -> DataType {
+        self.storage_type.clone()
+    }
+
+    fn serialize_metadata(&self) -> Option<String> {
+        self.inner.serialize_metadata()
+    }
+
+    fn create_array_formatter<'fmt>(
+        &self,
+        array: &'fmt dyn Array,
+        options: &FormatOptions<'fmt>,
+    ) -> crate::Result<Option<ArrayFormatter<'fmt>>> {
+        if array.data_type() != &self.storage_type {
+            return _internal_err!(
+                "Unexpected data type for TimestampWithOffset: {}",
+                array.data_type()
+            );
+        }
+
+        let struct_array = array.as_struct();
+        let timestamp_array = struct_array
+            .column_by_name("timestamp")
+            .expect("Type checked above")
+            .as_ref();
+        let offset_array = struct_array

Review Comment:
   From the spec:
   
   > It is also permissible for the offset_minutes field to be 
dictionary-encoded or run-end-encoded.
   
   TODO Check whether arrow-rs supports that and then implement support for it.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to