datafusion_substrait/variation_const.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
18//! Type variation constants
19//!
20//! To add support for types not in the [core specification](https://substrait.io/types/type_classes/),
21//! we make use of the [simple extensions] of substrait type. This module contains the constants used
22//! to identify the type variation.
23//!
24//! The rules of type variations here are:
25//! - Default type reference is 0. It is used when the actual type is the same with the original type.
26//! - Extended variant type references start from 1, and usually increase by 1.
27//!
28//! TODO: Definitions here are not the final form. All the non-system-preferred variations will be defined
29//! using [simple extensions] as per the [spec of type_variations](https://substrait.io/types/type_variations/)
30//! <https://github.com/apache/datafusion/issues/11545>
31//!
32//! [simple extensions]: (https://substrait.io/extensions/#simple-extensions)
33
34// For [type variations](https://substrait.io/types/type_variations/#type-variations) in substrait.
35// Type variations are used to represent different types based on one type class.
36// TODO: Define as extensions: <https://github.com/apache/datafusion/issues/11544>
37
38/// The "system-preferred" variation (i.e., no variation).
39pub const DEFAULT_TYPE_VARIATION_REF: u32 = 0;
40pub const UNSIGNED_INTEGER_TYPE_VARIATION_REF: u32 = 1;
41
42#[deprecated(since = "42.0.0", note = "Use `PrecisionTimestamp(Tz)` type instead")]
43pub const TIMESTAMP_SECOND_TYPE_VARIATION_REF: u32 = 0;
44#[deprecated(since = "42.0.0", note = "Use `PrecisionTimestamp(Tz)` type instead")]
45pub const TIMESTAMP_MILLI_TYPE_VARIATION_REF: u32 = 1;
46#[deprecated(since = "42.0.0", note = "Use `PrecisionTimestamp(Tz)` type instead")]
47pub const TIMESTAMP_MICRO_TYPE_VARIATION_REF: u32 = 2;
48#[deprecated(since = "42.0.0", note = "Use `PrecisionTimestamp(Tz)` type instead")]
49pub const TIMESTAMP_NANO_TYPE_VARIATION_REF: u32 = 3;
50
51pub const DATE_32_TYPE_VARIATION_REF: u32 = 0;
52pub const DATE_64_TYPE_VARIATION_REF: u32 = 1;
53pub const TIME_32_TYPE_VARIATION_REF: u32 = 0;
54pub const TIME_64_TYPE_VARIATION_REF: u32 = 1;
55pub const DEFAULT_CONTAINER_TYPE_VARIATION_REF: u32 = 0;
56pub const LARGE_CONTAINER_TYPE_VARIATION_REF: u32 = 1;
57pub const VIEW_CONTAINER_TYPE_VARIATION_REF: u32 = 2;
58pub const DEFAULT_MAP_TYPE_VARIATION_REF: u32 = 0;
59pub const DICTIONARY_MAP_TYPE_VARIATION_REF: u32 = 1;
60pub const DECIMAL_128_TYPE_VARIATION_REF: u32 = 0;
61pub const DECIMAL_256_TYPE_VARIATION_REF: u32 = 1;
62/// Used for the arrow type [`DataType::Interval`] with [`IntervalUnit::DayTime`].
63///
64/// [`DataType::Interval`]: datafusion::arrow::datatypes::DataType::Interval
65/// [`IntervalUnit::DayTime`]: datafusion::arrow::datatypes::IntervalUnit::DayTime
66pub const DEFAULT_INTERVAL_DAY_TYPE_VARIATION_REF: u32 = 0;
67/// Used for the arrow type [`DataType::Duration`].
68///
69/// [`DataType::Duration`]: datafusion::arrow::datatypes::DataType::Duration
70pub const DURATION_INTERVAL_DAY_TYPE_VARIATION_REF: u32 = 1;
71
72// For [user-defined types](https://substrait.io/types/type_classes/#user-defined-types).
73/// For [`DataType::Interval`] with [`IntervalUnit::YearMonth`].
74///
75/// An `i32` for elapsed whole months. See also [`ScalarValue::IntervalYearMonth`]
76/// for the literal definition in DataFusion.
77///
78/// [`DataType::Interval`]: datafusion::arrow::datatypes::DataType::Interval
79/// [`IntervalUnit::YearMonth`]: datafusion::arrow::datatypes::IntervalUnit::YearMonth
80/// [`ScalarValue::IntervalYearMonth`]: datafusion::common::ScalarValue::IntervalYearMonth
81#[deprecated(since = "41.0.0", note = "Use Substrait `IntervalYear` type instead")]
82pub const INTERVAL_YEAR_MONTH_TYPE_REF: u32 = 1;
83
84/// For [`DataType::Interval`] with [`IntervalUnit::DayTime`].
85///
86/// An `i64` as:
87/// - days: `i32`
88/// - milliseconds: `i32`
89///
90/// See also [`ScalarValue::IntervalDayTime`] for the literal definition in DataFusion.
91///
92/// [`DataType::Interval`]: datafusion::arrow::datatypes::DataType::Interval
93/// [`IntervalUnit::DayTime`]: datafusion::arrow::datatypes::IntervalUnit::DayTime
94/// [`ScalarValue::IntervalDayTime`]: datafusion::common::ScalarValue::IntervalDayTime
95#[deprecated(since = "41.0.0", note = "Use Substrait `IntervalDay` type instead")]
96pub const INTERVAL_DAY_TIME_TYPE_REF: u32 = 2;
97
98/// For [`DataType::Interval`] with [`IntervalUnit::MonthDayNano`].
99///
100/// An `i128` as:
101/// - months: `i32`
102/// - days: `i32`
103/// - nanoseconds: `i64`
104///
105/// See also [`ScalarValue::IntervalMonthDayNano`] for the literal definition in DataFusion.
106///
107/// [`DataType::Interval`]: datafusion::arrow::datatypes::DataType::Interval
108/// [`IntervalUnit::MonthDayNano`]: datafusion::arrow::datatypes::IntervalUnit::MonthDayNano
109/// [`ScalarValue::IntervalMonthDayNano`]: datafusion::common::ScalarValue::IntervalMonthDayNano
110#[deprecated(
111 since = "41.0.0",
112 note = "Use Substrait `IntervalCompound` type instead"
113)]
114pub const INTERVAL_MONTH_DAY_NANO_TYPE_REF: u32 = 3;
115
116/// For [`DataType::Interval`] with [`IntervalUnit::MonthDayNano`].
117///
118/// [`DataType::Interval`]: datafusion::arrow::datatypes::DataType::Interval
119/// [`IntervalUnit::MonthDayNano`]: datafusion::arrow::datatypes::IntervalUnit::MonthDayNano
120#[deprecated(
121 since = "43.0.0",
122 note = "Use Substrait `IntervalCompound` type instead"
123)]
124pub const INTERVAL_MONTH_DAY_NANO_TYPE_NAME: &str = "interval-month-day-nano";
125
126/// Defined in <https://github.com/apache/arrow/blame/main/format/substrait/extension_types.yaml>
127pub const FLOAT_16_TYPE_NAME: &str = "fp16";
128
129/// For [`DataType::Null`]
130///
131/// [`DataType::Null`]: datafusion::arrow::datatypes::DataType::Null
132pub const NULL_TYPE_NAME: &str = "null";