datatypes/
type_id.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/// Unique identifier for logical data type.
16#[derive(Clone, Copy, Debug, PartialEq, Eq)]
17pub enum LogicalTypeId {
18    Null,
19
20    // Numeric types:
21    Boolean,
22    Int8,
23    Int16,
24    Int32,
25    Int64,
26    UInt8,
27    UInt16,
28    UInt32,
29    UInt64,
30    Float32,
31    Float64,
32
33    Decimal128,
34
35    // String types:
36    String,
37    Binary,
38
39    // Date & Time types:
40    /// Date representing the elapsed time since UNIX epoch (1970-01-01)
41    /// in days (32 bits).
42    Date,
43
44    TimestampSecond,
45    TimestampMillisecond,
46    TimestampMicrosecond,
47    TimestampNanosecond,
48    /// A 64-bit time representing the elapsed time since midnight in the unit of `TimeUnit`.
49    TimeSecond,
50    TimeMillisecond,
51    TimeMicrosecond,
52    TimeNanosecond,
53    /// A 64-bit duration representing the elapsed time in either seconds,
54    /// milliseconds, microseconds or nanoseconds.
55    DurationSecond,
56    DurationMillisecond,
57    DurationMicrosecond,
58    DurationNanosecond,
59    /// A 32-bit interval representing the elapsed time in months.
60    IntervalYearMonth,
61    /// A 64-bit interval representing the elapsed time in days and milliseconds.
62    IntervalDayTime,
63    /// A 128-bit interval representing the elapsed time in months, days and nanoseconds.
64    IntervalMonthDayNano,
65
66    List,
67    Dictionary,
68    Struct,
69
70    Json,
71
72    Vector,
73}
74
75impl LogicalTypeId {
76    /// Create ConcreteDataType based on this id. This method is for test only as it
77    /// would lost some info.
78    ///
79    /// # Panics
80    /// Panics if data type is not supported.
81    #[cfg(any(test, feature = "test"))]
82    pub fn data_type(&self) -> crate::data_type::ConcreteDataType {
83        use crate::data_type::ConcreteDataType;
84
85        match self {
86            LogicalTypeId::Null => ConcreteDataType::null_datatype(),
87            LogicalTypeId::Boolean => ConcreteDataType::boolean_datatype(),
88            LogicalTypeId::Int8 => ConcreteDataType::int8_datatype(),
89            LogicalTypeId::Int16 => ConcreteDataType::int16_datatype(),
90            LogicalTypeId::Int32 => ConcreteDataType::int32_datatype(),
91            LogicalTypeId::Int64 => ConcreteDataType::int64_datatype(),
92            LogicalTypeId::UInt8 => ConcreteDataType::uint8_datatype(),
93            LogicalTypeId::UInt16 => ConcreteDataType::uint16_datatype(),
94            LogicalTypeId::UInt32 => ConcreteDataType::uint32_datatype(),
95            LogicalTypeId::UInt64 => ConcreteDataType::uint64_datatype(),
96            LogicalTypeId::Float32 => ConcreteDataType::float32_datatype(),
97            LogicalTypeId::Float64 => ConcreteDataType::float64_datatype(),
98            LogicalTypeId::String => ConcreteDataType::string_datatype(),
99            LogicalTypeId::Binary => ConcreteDataType::binary_datatype(),
100            LogicalTypeId::Date => ConcreteDataType::date_datatype(),
101            LogicalTypeId::TimestampSecond => ConcreteDataType::timestamp_second_datatype(),
102            LogicalTypeId::TimestampMillisecond => {
103                ConcreteDataType::timestamp_millisecond_datatype()
104            }
105            LogicalTypeId::TimestampMicrosecond => {
106                ConcreteDataType::timestamp_microsecond_datatype()
107            }
108            LogicalTypeId::TimestampNanosecond => ConcreteDataType::timestamp_nanosecond_datatype(),
109            LogicalTypeId::List => {
110                ConcreteDataType::list_datatype(ConcreteDataType::null_datatype())
111            }
112            LogicalTypeId::Struct => ConcreteDataType::struct_datatype(vec![].into()),
113            LogicalTypeId::Dictionary => ConcreteDataType::dictionary_datatype(
114                ConcreteDataType::null_datatype(),
115                ConcreteDataType::null_datatype(),
116            ),
117            LogicalTypeId::TimeSecond => ConcreteDataType::time_second_datatype(),
118            LogicalTypeId::TimeMillisecond => ConcreteDataType::time_millisecond_datatype(),
119            LogicalTypeId::TimeMicrosecond => ConcreteDataType::time_microsecond_datatype(),
120            LogicalTypeId::TimeNanosecond => ConcreteDataType::time_nanosecond_datatype(),
121            LogicalTypeId::IntervalYearMonth => ConcreteDataType::interval_year_month_datatype(),
122            LogicalTypeId::IntervalDayTime => ConcreteDataType::interval_day_time_datatype(),
123            LogicalTypeId::IntervalMonthDayNano => {
124                ConcreteDataType::interval_month_day_nano_datatype()
125            }
126            LogicalTypeId::DurationSecond => ConcreteDataType::duration_second_datatype(),
127            LogicalTypeId::DurationMillisecond => ConcreteDataType::duration_millisecond_datatype(),
128            LogicalTypeId::DurationMicrosecond => ConcreteDataType::duration_microsecond_datatype(),
129            LogicalTypeId::DurationNanosecond => ConcreteDataType::duration_nanosecond_datatype(),
130            LogicalTypeId::Decimal128 => ConcreteDataType::decimal128_default_datatype(),
131            LogicalTypeId::Json => ConcreteDataType::json_datatype(),
132            LogicalTypeId::Vector => ConcreteDataType::vector_default_datatype(),
133        }
134    }
135}