jayzhan211 commented on code in PR #12853: URL: https://github.com/apache/datafusion/pull/12853#discussion_r1817701192
########## datafusion/common/src/types/logical.rs: ########## @@ -0,0 +1,128 @@ +// 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 super::NativeType; +use crate::error::Result; +use arrow_schema::DataType; +use core::fmt; +use std::{cmp::Ordering, hash::Hash, sync::Arc}; + +/// Signature that uniquely identifies a type among other types. +#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub enum TypeSignature<'a> { + /// Represents a built-in native type. + Native(&'a NativeType), + /// Represents an arrow-compatible extension type. + /// (<https://arrow.apache.org/docs/format/Columnar.html#extension-types>) + /// + /// The `name` should contain the same value as 'ARROW:extension:name'. + Extension { + name: &'a str, + parameters: &'a [TypeParameter<'a>], + }, +} + +#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub enum TypeParameter<'a> { + Type(TypeSignature<'a>), + Number(i128), +} + +/// A reference counted [`LogicalType`]. +pub type LogicalTypeRef = Arc<dyn LogicalType>; Review Comment: I think we need function to get `LogicalTypeRef` as a singleton overall the datafusion. Something like ```rust // Singleton instances // TODO: Replace with LazyLock pub static LOGICAL_STRING: OnceLock<LogicalTypeRef> = OnceLock::new(); pub static LOGICAL_FLOAT16: OnceLock<LogicalTypeRef> = OnceLock::new(); // Usage functions pub fn logical_string() -> LogicalTypeRef { Arc::clone(LOGICAL_STRING.get_or_init(|| Arc::new(String))) } pub fn logical_float16() -> LogicalTypeRef { Arc::clone(LOGICAL_FLOAT16.get_or_init(|| Arc::new(Float16))) } ``` -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org