be/src/exprs/function/function_helpers.h
Line | Count | Source |
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 | | // This file is copied from |
18 | | // https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/FunctionHelpers.h |
19 | | // and modified by Doris |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include <cstddef> |
24 | | #include <tuple> |
25 | | |
26 | | #include "core/assert_cast.h" |
27 | | #include "core/block/block.h" |
28 | | #include "core/block/column_numbers.h" |
29 | | #include "core/column/column.h" |
30 | | #include "core/column/column_const.h" |
31 | | #include "core/data_type/data_type.h" |
32 | | #include "core/field.h" |
33 | | #include "core/typeid_cast.h" |
34 | | #include "core/types.h" |
35 | | |
36 | | namespace doris { |
37 | | |
38 | | class IFunction; |
39 | | |
40 | | /// Methods, that helps dispatching over real column types. |
41 | | |
42 | | template <typename... Type> |
43 | | bool check_data_type(const IDataType* data_type) { |
44 | | return ((typeid_cast<const Type*>(data_type)) || ...); |
45 | | } |
46 | | |
47 | | template <typename Type> |
48 | 228k | const Type* check_and_get_data_type(const IDataType* data_type) { |
49 | 228k | return typeid_cast<const Type*>(data_type); |
50 | 228k | } _ZN5doris23check_and_get_data_typeINS_14DataTypeStringEEEPKT_PKNS_9IDataTypeE Line | Count | Source | 48 | 121k | const Type* check_and_get_data_type(const IDataType* data_type) { | 49 | 121k | return typeid_cast<const Type*>(data_type); | 50 | 121k | } |
_ZN5doris23check_and_get_data_typeINS_13DataTypeArrayEEEPKT_PKNS_9IDataTypeE Line | Count | Source | 48 | 69.0k | const Type* check_and_get_data_type(const IDataType* data_type) { | 49 | 69.0k | return typeid_cast<const Type*>(data_type); | 50 | 69.0k | } |
_ZN5doris23check_and_get_data_typeINS_11DataTypeMapEEEPKT_PKNS_9IDataTypeE Line | Count | Source | 48 | 755 | const Type* check_and_get_data_type(const IDataType* data_type) { | 49 | 755 | return typeid_cast<const Type*>(data_type); | 50 | 755 | } |
_ZN5doris23check_and_get_data_typeINS_14DataTypeStructEEEPKT_PKNS_9IDataTypeE Line | Count | Source | 48 | 3.19k | const Type* check_and_get_data_type(const IDataType* data_type) { | 49 | 3.19k | return typeid_cast<const Type*>(data_type); | 50 | 3.19k | } |
_ZN5doris23check_and_get_data_typeINS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEEEEPKT_PKNS_9IDataTypeE Line | Count | Source | 48 | 7.70k | const Type* check_and_get_data_type(const IDataType* data_type) { | 49 | 7.70k | return typeid_cast<const Type*>(data_type); | 50 | 7.70k | } |
_ZN5doris23check_and_get_data_typeINS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEEEEPKT_PKNS_9IDataTypeE Line | Count | Source | 48 | 7.83k | const Type* check_and_get_data_type(const IDataType* data_type) { | 49 | 7.83k | return typeid_cast<const Type*>(data_type); | 50 | 7.83k | } |
_ZN5doris23check_and_get_data_typeINS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEEEEPKT_PKNS_9IDataTypeE Line | Count | Source | 48 | 1.46k | const Type* check_and_get_data_type(const IDataType* data_type) { | 49 | 1.46k | return typeid_cast<const Type*>(data_type); | 50 | 1.46k | } |
_ZN5doris23check_and_get_data_typeINS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEEEEPKT_PKNS_9IDataTypeE Line | Count | Source | 48 | 10.1k | const Type* check_and_get_data_type(const IDataType* data_type) { | 49 | 10.1k | return typeid_cast<const Type*>(data_type); | 50 | 10.1k | } |
_ZN5doris23check_and_get_data_typeINS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEEEEPKT_PKNS_9IDataTypeE Line | Count | Source | 48 | 7.15k | const Type* check_and_get_data_type(const IDataType* data_type) { | 49 | 7.15k | return typeid_cast<const Type*>(data_type); | 50 | 7.15k | } |
|
51 | | |
52 | | template <typename Type> |
53 | 8.02k | const ColumnConst* check_and_get_column_const(const IColumn* column) { |
54 | 8.02k | if (!column || !is_column_const(*column)) { |
55 | 4.49k | return nullptr; |
56 | 4.49k | } |
57 | | |
58 | 3.53k | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); |
59 | | |
60 | 3.53k | if (!is_column<Type>(&res->get_data_column())) { |
61 | 0 | return nullptr; |
62 | 0 | } |
63 | | |
64 | 3.53k | return res; |
65 | 3.53k | } _ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE8EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 270 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 270 | if (!column || !is_column_const(*column)) { | 55 | 85 | return nullptr; | 56 | 85 | } | 57 | | | 58 | 185 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 185 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 185 | return res; | 65 | 185 | } |
_ZN5doris26check_and_get_column_constINS_13ColumnDecimalILNS_13PrimitiveTypeE28EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 37 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 37 | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 37 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 37 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 37 | return res; | 65 | 37 | } |
_ZN5doris26check_and_get_column_constINS_13ColumnDecimalILNS_13PrimitiveTypeE29EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 195 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 195 | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 195 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 195 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 195 | return res; | 65 | 195 | } |
Unexecuted instantiation: _ZN5doris26check_and_get_column_constINS_13ColumnDecimalILNS_13PrimitiveTypeE20EEEEEPKNS_11ColumnConstEPKNS_7IColumnE _ZN5doris26check_and_get_column_constINS_13ColumnDecimalILNS_13PrimitiveTypeE30EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 1.44k | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 1.44k | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 1.44k | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 1.44k | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 1.44k | return res; | 65 | 1.44k | } |
_ZN5doris26check_and_get_column_constINS_13ColumnDecimalILNS_13PrimitiveTypeE35EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 62 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 62 | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 62 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 62 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 62 | return res; | 65 | 62 | } |
_ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 1.77k | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 1.77k | if (!column || !is_column_const(*column)) { | 55 | 1.47k | return nullptr; | 56 | 1.47k | } | 57 | | | 58 | 292 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 292 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 292 | return res; | 65 | 292 | } |
_ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE3EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 1.06k | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 1.06k | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 1.06k | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 1.06k | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 1.06k | return res; | 65 | 1.06k | } |
_ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE4EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 4 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 4 | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 4 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 4 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 4 | return res; | 65 | 4 | } |
_ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE5EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 42 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 42 | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 42 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 42 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 42 | return res; | 65 | 42 | } |
_ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE6EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 41 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 41 | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 41 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 41 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 41 | return res; | 65 | 41 | } |
_ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE7EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 4 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 4 | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 4 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 4 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 4 | return res; | 65 | 4 | } |
_ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE9EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 85 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 85 | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 85 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 85 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 85 | return res; | 65 | 85 | } |
Unexecuted instantiation: _ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE11EEEEEPKNS_11ColumnConstEPKNS_7IColumnE _ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE25EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 13 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 13 | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 13 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 13 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 13 | return res; | 65 | 13 | } |
_ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE26EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 71 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 71 | if (!column || !is_column_const(*column)) { | 55 | 0 | return nullptr; | 56 | 0 | } | 57 | | | 58 | 71 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 71 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 71 | return res; | 65 | 71 | } |
Unexecuted instantiation: _ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE12EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Unexecuted instantiation: _ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE27EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Unexecuted instantiation: _ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE42EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Unexecuted instantiation: _ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE36EEEEEPKNS_11ColumnConstEPKNS_7IColumnE Unexecuted instantiation: _ZN5doris26check_and_get_column_constINS_12ColumnVectorILNS_13PrimitiveTypeE37EEEEEPKNS_11ColumnConstEPKNS_7IColumnE _ZN5doris26check_and_get_column_constINS_9ColumnMapEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 2.78k | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 2.78k | if (!column || !is_column_const(*column)) { | 55 | 2.78k | return nullptr; | 56 | 2.78k | } | 57 | | | 58 | 0 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | |
| 60 | 0 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 0 | return res; | 65 | 0 | } |
_ZN5doris26check_and_get_column_constINS_9ColumnStrIjEEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 77 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 77 | if (!column || !is_column_const(*column)) { | 55 | 77 | return nullptr; | 56 | 77 | } | 57 | | | 58 | 0 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | |
| 60 | 0 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 0 | return res; | 65 | 0 | } |
_ZN5doris26check_and_get_column_constINS_11ColumnArrayEEEPKNS_11ColumnConstEPKNS_7IColumnE Line | Count | Source | 53 | 77 | const ColumnConst* check_and_get_column_const(const IColumn* column) { | 54 | 77 | if (!column || !is_column_const(*column)) { | 55 | 71 | return nullptr; | 56 | 71 | } | 57 | | | 58 | 6 | const auto* res = assert_cast<const ColumnConst*, TypeCheckOnRelease::DISABLE>(column); | 59 | | | 60 | 6 | if (!is_column<Type>(&res->get_data_column())) { | 61 | 0 | return nullptr; | 62 | 0 | } | 63 | | | 64 | 6 | return res; | 65 | 6 | } |
|
66 | | |
67 | | template <typename Type> |
68 | | const Type* check_and_get_column_constData(const IColumn* column) { |
69 | | const ColumnConst* res = check_and_get_column_const<Type>(column); |
70 | | |
71 | | if (!res) { |
72 | | return nullptr; |
73 | | } |
74 | | |
75 | | return static_cast<const Type*>(&res->get_data_column()); |
76 | | } |
77 | | |
78 | | template <typename Type> |
79 | 2.78k | bool check_column_const(const IColumn* column) { |
80 | 2.78k | return check_and_get_column_const<Type>(column); |
81 | 2.78k | } |
82 | | |
83 | | /// Returns non-nullptr if column is ColumnConst with ColumnString or ColumnFixedString inside. |
84 | | const ColumnConst* check_and_get_column_const_string_or_fixedstring(const IColumn* column); |
85 | | |
86 | | /// Transform anything to Field. |
87 | | template <PrimitiveType T> |
88 | | requires(!is_decimal(T)) |
89 | 44 | Field to_field(const typename PrimitiveTypeTraits<T>::CppType& x) { |
90 | 44 | return Field::create_field<T>(typename PrimitiveTypeTraits<T>::CppType(x)); |
91 | 44 | } Unexecuted instantiation: _ZN5doris8to_fieldILNS_13PrimitiveTypeE2EQntclL_ZNS_10is_decimalES1_ET_EEENS_5FieldERKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE _ZN5doris8to_fieldILNS_13PrimitiveTypeE5EQntclL_ZNS_10is_decimalES1_ET_EEENS_5FieldERKNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Line | Count | Source | 89 | 44 | Field to_field(const typename PrimitiveTypeTraits<T>::CppType& x) { | 90 | 44 | return Field::create_field<T>(typename PrimitiveTypeTraits<T>::CppType(x)); | 91 | 44 | } |
|
92 | | |
93 | | template <PrimitiveType T> |
94 | | requires(is_decimal(T)) |
95 | | Field to_field(const typename PrimitiveTypeTraits<T>::CppType& x, UInt32 scale) { |
96 | | return Field::create_field<T>(typename PrimitiveTypeTraits<T>::CppType(x, scale)); |
97 | | } |
98 | | |
99 | | Columns convert_const_tuple_to_constant_elements(const ColumnConst& column); |
100 | | |
101 | | /// Returns the copy of a tmp block and temp args order same as args |
102 | | /// in which only args column each column specified in the "arguments" |
103 | | /// parameter is replaced with its respective nested column if it is nullable. |
104 | | std::tuple<Block, ColumnNumbers> create_block_with_nested_columns(const Block& block, |
105 | | const ColumnNumbers& args, |
106 | | const bool need_check_same); |
107 | | |
108 | | // Same as above and return the new_res loc in tuple |
109 | | std::tuple<Block, ColumnNumbers, size_t> create_block_with_nested_columns(const Block& block, |
110 | | const ColumnNumbers& args, |
111 | | uint32_t result); |
112 | | |
113 | | /// Checks argument type at specified index with predicate. |
114 | | /// throws if there is no argument at specified index or if predicate returns false. |
115 | | void validate_argument_type(const IFunction& func, const DataTypes& arguments, |
116 | | size_t argument_index, bool (*validator_func)(const IDataType&), |
117 | | const char* expected_type_description); |
118 | | |
119 | | } // namespace doris |