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
69    Json,
70
71    Vector,
72}
73
74impl LogicalTypeId {
75    /// Create ConcreteDataType based on this id. This method is for test only as it
76    /// would lost some info.
77    ///
78    /// # Panics
79    /// Panics if data type is not supported.
80    #[cfg(any(test, feature = "test"))]
81    pub fn data_type(&self) -> crate::data_type::ConcreteDataType {
82        use crate::data_type::ConcreteDataType;
83
84        match self {
85            LogicalTypeId::Null => ConcreteDataType::null_datatype(),
86            LogicalTypeId::Boolean => ConcreteDataType::boolean_datatype(),
87            LogicalTypeId::Int8 => ConcreteDataType::int8_datatype(),
88            LogicalTypeId::Int16 => ConcreteDataType::int16_datatype(),
89            LogicalTypeId::Int32 => ConcreteDataType::int32_datatype(),
90            LogicalTypeId::Int64 => ConcreteDataType::int64_datatype(),
91            LogicalTypeId::UInt8 => ConcreteDataType::uint8_datatype(),
92            LogicalTypeId::UInt16 => ConcreteDataType::uint16_datatype(),
93            LogicalTypeId::UInt32 => ConcreteDataType::uint32_datatype(),
94            LogicalTypeId::UInt64 => ConcreteDataType::uint64_datatype(),
95            LogicalTypeId::Float32 => ConcreteDataType::float32_datatype(),
96            LogicalTypeId::Float64 => ConcreteDataType::float64_datatype(),
97            LogicalTypeId::String => ConcreteDataType::string_datatype(),
98            LogicalTypeId::Binary => ConcreteDataType::binary_datatype(),
99            LogicalTypeId::Date => ConcreteDataType::date_datatype(),
100            LogicalTypeId::TimestampSecond => ConcreteDataType::timestamp_second_datatype(),
101            LogicalTypeId::TimestampMillisecond => {
102                ConcreteDataType::timestamp_millisecond_datatype()
103            }
104            LogicalTypeId::TimestampMicrosecond => {
105                ConcreteDataType::timestamp_microsecond_datatype()
106            }
107            LogicalTypeId::TimestampNanosecond => ConcreteDataType::timestamp_nanosecond_datatype(),
108            LogicalTypeId::List => {
109                ConcreteDataType::list_datatype(ConcreteDataType::null_datatype())
110            }
111            LogicalTypeId::Dictionary => ConcreteDataType::dictionary_datatype(
112                ConcreteDataType::null_datatype(),
113                ConcreteDataType::null_datatype(),
114            ),
115            LogicalTypeId::TimeSecond => ConcreteDataType::time_second_datatype(),
116            LogicalTypeId::TimeMillisecond => ConcreteDataType::time_millisecond_datatype(),
117            LogicalTypeId::TimeMicrosecond => ConcreteDataType::time_microsecond_datatype(),
118            LogicalTypeId::TimeNanosecond => ConcreteDataType::time_nanosecond_datatype(),
119            LogicalTypeId::IntervalYearMonth => ConcreteDataType::interval_year_month_datatype(),
120            LogicalTypeId::IntervalDayTime => ConcreteDataType::interval_day_time_datatype(),
121            LogicalTypeId::IntervalMonthDayNano => {
122                ConcreteDataType::interval_month_day_nano_datatype()
123            }
124            LogicalTypeId::DurationSecond => ConcreteDataType::duration_second_datatype(),
125            LogicalTypeId::DurationMillisecond => ConcreteDataType::duration_millisecond_datatype(),
126            LogicalTypeId::DurationMicrosecond => ConcreteDataType::duration_microsecond_datatype(),
127            LogicalTypeId::DurationNanosecond => ConcreteDataType::duration_nanosecond_datatype(),
128            LogicalTypeId::Decimal128 => ConcreteDataType::decimal128_default_datatype(),
129            LogicalTypeId::Json => ConcreteDataType::json_datatype(),
130            LogicalTypeId::Vector => ConcreteDataType::vector_default_datatype(),
131        }
132    }
133}