datafusion_common/types/
builtin.rs

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
18use crate::types::{LogicalTypeRef, NativeType};
19use std::sync::{Arc, LazyLock};
20
21macro_rules! singleton {
22    ($name:ident, $getter:ident, $ty:ident) => {
23        static $name: LazyLock<LogicalTypeRef> =
24            LazyLock::new(|| Arc::new(NativeType::$ty));
25
26        #[doc = "Getter for singleton instance of a logical type representing"]
27        #[doc = concat!("[`NativeType::", stringify!($ty), "`].")]
28        pub fn $getter() -> LogicalTypeRef {
29            Arc::clone(&$name)
30        }
31    };
32}
33
34singleton!(LOGICAL_NULL, logical_null, Null);
35singleton!(LOGICAL_BOOLEAN, logical_boolean, Boolean);
36singleton!(LOGICAL_INT8, logical_int8, Int8);
37singleton!(LOGICAL_INT16, logical_int16, Int16);
38singleton!(LOGICAL_INT32, logical_int32, Int32);
39singleton!(LOGICAL_INT64, logical_int64, Int64);
40singleton!(LOGICAL_UINT8, logical_uint8, UInt8);
41singleton!(LOGICAL_UINT16, logical_uint16, UInt16);
42singleton!(LOGICAL_UINT32, logical_uint32, UInt32);
43singleton!(LOGICAL_UINT64, logical_uint64, UInt64);
44singleton!(LOGICAL_FLOAT16, logical_float16, Float16);
45singleton!(LOGICAL_FLOAT32, logical_float32, Float32);
46singleton!(LOGICAL_FLOAT64, logical_float64, Float64);
47singleton!(LOGICAL_DATE, logical_date, Date);
48singleton!(LOGICAL_BINARY, logical_binary, Binary);
49singleton!(LOGICAL_STRING, logical_string, String);