]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/cpp/src/gandiva/expression_registry.cc
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / gandiva / expression_registry.cc
CommitLineData
1d09f67e
TL
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#include "gandiva/expression_registry.h"
19
20#include "gandiva/function_registry.h"
21#include "gandiva/llvm_types.h"
22
23namespace gandiva {
24
25ExpressionRegistry::ExpressionRegistry() {
26 function_registry_.reset(new FunctionRegistry());
27}
28
29ExpressionRegistry::~ExpressionRegistry() {}
30
31// to be used only to create function_signature_start
32ExpressionRegistry::FunctionSignatureIterator::FunctionSignatureIterator(
33 native_func_iterator_type nf_it, native_func_iterator_type nf_it_end)
34 : native_func_it_{nf_it},
35 native_func_it_end_{nf_it_end},
36 func_sig_it_{&(nf_it->signatures().front())} {}
37
38// to be used only to create function_signature_end
39ExpressionRegistry::FunctionSignatureIterator::FunctionSignatureIterator(
40 func_sig_iterator_type fs_it)
41 : native_func_it_{nullptr}, native_func_it_end_{nullptr}, func_sig_it_{fs_it} {}
42
43const ExpressionRegistry::FunctionSignatureIterator
44ExpressionRegistry::function_signature_begin() {
45 return FunctionSignatureIterator(function_registry_->begin(),
46 function_registry_->end());
47}
48
49const ExpressionRegistry::FunctionSignatureIterator
50ExpressionRegistry::function_signature_end() const {
51 return FunctionSignatureIterator(&(*(function_registry_->back()->signatures().end())));
52}
53
54bool ExpressionRegistry::FunctionSignatureIterator::operator!=(
55 const FunctionSignatureIterator& func_sign_it) {
56 return func_sign_it.func_sig_it_ != this->func_sig_it_;
57}
58
59FunctionSignature ExpressionRegistry::FunctionSignatureIterator::operator*() {
60 return *func_sig_it_;
61}
62
63ExpressionRegistry::func_sig_iterator_type ExpressionRegistry::FunctionSignatureIterator::
64operator++(int increment) {
65 ++func_sig_it_;
66 // point func_sig_it_ to first signature of next nativefunction if func_sig_it_ is
67 // pointing to end
68 if (func_sig_it_ == &(*native_func_it_->signatures().end())) {
69 ++native_func_it_;
70 if (native_func_it_ == native_func_it_end_) { // last native function
71 return func_sig_it_;
72 }
73 func_sig_it_ = &(native_func_it_->signatures().front());
74 }
75 return func_sig_it_;
76}
77
78static void AddArrowTypesToVector(arrow::Type::type type, DataTypeVector& vector);
79
80static DataTypeVector InitSupportedTypes() {
81 DataTypeVector data_type_vector;
82 llvm::LLVMContext llvm_context;
83 LLVMTypes llvm_types(llvm_context);
84 auto supported_arrow_types = llvm_types.GetSupportedArrowTypes();
85 for (auto& type_id : supported_arrow_types) {
86 AddArrowTypesToVector(type_id, data_type_vector);
87 }
88 return data_type_vector;
89}
90
91DataTypeVector ExpressionRegistry::supported_types_ = InitSupportedTypes();
92
93static void AddArrowTypesToVector(arrow::Type::type type, DataTypeVector& vector) {
94 switch (type) {
95 case arrow::Type::type::BOOL:
96 vector.push_back(arrow::boolean());
97 break;
98 case arrow::Type::type::UINT8:
99 vector.push_back(arrow::uint8());
100 break;
101 case arrow::Type::type::INT8:
102 vector.push_back(arrow::int8());
103 break;
104 case arrow::Type::type::UINT16:
105 vector.push_back(arrow::uint16());
106 break;
107 case arrow::Type::type::INT16:
108 vector.push_back(arrow::int16());
109 break;
110 case arrow::Type::type::UINT32:
111 vector.push_back(arrow::uint32());
112 break;
113 case arrow::Type::type::INT32:
114 vector.push_back(arrow::int32());
115 break;
116 case arrow::Type::type::UINT64:
117 vector.push_back(arrow::uint64());
118 break;
119 case arrow::Type::type::INT64:
120 vector.push_back(arrow::int64());
121 break;
122 case arrow::Type::type::HALF_FLOAT:
123 vector.push_back(arrow::float16());
124 break;
125 case arrow::Type::type::FLOAT:
126 vector.push_back(arrow::float32());
127 break;
128 case arrow::Type::type::DOUBLE:
129 vector.push_back(arrow::float64());
130 break;
131 case arrow::Type::type::STRING:
132 vector.push_back(arrow::utf8());
133 break;
134 case arrow::Type::type::BINARY:
135 vector.push_back(arrow::binary());
136 break;
137 case arrow::Type::type::DATE32:
138 vector.push_back(arrow::date32());
139 break;
140 case arrow::Type::type::DATE64:
141 vector.push_back(arrow::date64());
142 break;
143 case arrow::Type::type::TIMESTAMP:
144 vector.push_back(arrow::timestamp(arrow::TimeUnit::SECOND));
145 vector.push_back(arrow::timestamp(arrow::TimeUnit::MILLI));
146 vector.push_back(arrow::timestamp(arrow::TimeUnit::NANO));
147 vector.push_back(arrow::timestamp(arrow::TimeUnit::MICRO));
148 break;
149 case arrow::Type::type::TIME32:
150 vector.push_back(arrow::time32(arrow::TimeUnit::SECOND));
151 vector.push_back(arrow::time32(arrow::TimeUnit::MILLI));
152 break;
153 case arrow::Type::type::TIME64:
154 vector.push_back(arrow::time64(arrow::TimeUnit::MICRO));
155 vector.push_back(arrow::time64(arrow::TimeUnit::NANO));
156 break;
157 case arrow::Type::type::NA:
158 vector.push_back(arrow::null());
159 break;
160 case arrow::Type::type::DECIMAL:
161 vector.push_back(arrow::decimal(38, 0));
162 break;
163 case arrow::Type::type::INTERVAL_MONTHS:
164 vector.push_back(arrow::month_interval());
165 break;
166 case arrow::Type::type::INTERVAL_DAY_TIME:
167 vector.push_back(arrow::day_time_interval());
168 break;
169 default:
170 // Unsupported types. test ensures that
171 // when one of these are added build breaks.
172 DCHECK(false);
173 }
174}
175
176std::vector<std::shared_ptr<FunctionSignature>> GetRegisteredFunctionSignatures() {
177 ExpressionRegistry registry;
178 std::vector<std::shared_ptr<FunctionSignature>> signatures;
179 for (auto iter = registry.function_signature_begin();
180 iter != registry.function_signature_end(); iter++) {
181 signatures.push_back(std::make_shared<FunctionSignature>(
182 (*iter).base_name(), (*iter).param_types(), (*iter).ret_type()));
183 }
184 return signatures;
185}
186
187} // namespace gandiva