OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtensionFunctionsWhitelist.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
23 #ifndef QUERYENGINE_EXTENSIONFUNCTIONSWHITELIST_H
24 #define QUERYENGINE_EXTENSIONFUNCTIONSWHITELIST_H
25 
26 #include <string>
27 #include <unordered_map>
28 #include <unordered_set>
29 #include <vector>
30 
31 #include "Shared/sqltypes.h"
32 #include "Shared/toString.h"
33 
34 // NOTE: To maintain backwards compatibility:
35 // New types should always be appended to the end of the type list
36 // Existing types should never be removed!
37 enum class ExtArgumentType {
38  Int8,
39  Int16,
40  Int32,
41  Int64,
42  Float,
43  Double,
44  Void,
45  PInt8,
46  PInt16,
47  PInt32,
48  PInt64,
49  PFloat,
50  PDouble,
51  PBool,
52  Bool,
53  ArrayInt8,
54  ArrayInt16,
55  ArrayInt32,
56  ArrayInt64,
57  ArrayFloat,
59  ArrayBool,
60  GeoPoint,
62  Cursor,
63  GeoPolygon,
65  ColumnInt8,
71  ColumnBool,
84  Timestamp,
111 };
112 
114 
116  public:
117  ExtensionFunction(const std::string& name,
118  const std::vector<ExtArgumentType>& args,
119  const ExtArgumentType ret,
120  const std::vector<std::map<std::string, std::string>>& annotations,
121  const bool is_runtime)
122  : name_(name)
123  , args_(args)
124  , ret_(ret)
125  , annotations_(annotations)
126  , is_runtime_(is_runtime) {}
127 
128  const std::string getName(bool keep_suffix = true) const;
129 
130  const std::vector<ExtArgumentType>& getInputArgs() const { return args_; }
131  const ExtArgumentType getRet() const { return ret_; }
132  const std::vector<std::map<std::string, std::string>>& getAnnotations() const {
133  return annotations_;
134  }
135 
136  bool usesManager() const;
137  std::string toString() const;
138  std::string toStringSQL() const;
139  std::string toSignature() const;
140 
141  inline bool isGPU() const {
142  return (name_.find("_cpu_", name_.find("__")) == std::string::npos);
143  }
144 
145  inline bool isCPU() const {
146  return (name_.find("_gpu_", name_.find("__")) == std::string::npos);
147  }
148 
149  inline bool isRuntime() const { return is_runtime_; }
150 
151  private:
152  const std::string name_;
153  const std::vector<ExtArgumentType> args_;
155  const std::vector<std::map<std::string, std::string>> annotations_;
156  const bool is_runtime_;
157 };
158 
160  public:
161  static void add(const std::string& json_func_sigs);
162 
163  static void addUdfs(const std::string& json_func_sigs);
164 
165  static void clearRTUdfs();
166  static void addRTUdfs(const std::string& json_func_sigs);
167 
168  static std::vector<ExtensionFunction>* get(const std::string& name);
169 
170  static std::vector<ExtensionFunction>* get_udf(const std::string& name);
171 
172  static std::unordered_set<std::string> get_udfs_name(const bool is_runtime);
173 
174  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name);
175 
176  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
177  const bool is_gpu);
178 
179  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
180  size_t arity);
181 
182  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
183  size_t arity,
184  const SQLTypeInfo& rtype);
185 
186  static std::string toString(const std::vector<ExtensionFunction>& ext_funcs,
187  std::string tab = "");
188  static std::string toString(const std::vector<SQLTypeInfo>& arg_types);
189  static std::string toString(const std::vector<ExtArgumentType>& sig_types);
190  static std::string toStringSQL(const std::vector<ExtArgumentType>& sig_types);
191  static std::string toString(const ExtArgumentType& sig_type);
192  static std::string toStringSQL(const ExtArgumentType& sig_type);
193 
194  static std::vector<std::string> getLLVMDeclarations(
195  const std::unordered_set<std::string>& udf_decls,
196  const bool is_gpu = false);
197 
198  private:
199  static void addCommon(
200  std::unordered_map<std::string, std::vector<ExtensionFunction>>& sigs,
201  const std::string& json_func_sigs,
202  const bool is_runtime);
203 
204  private:
205  // Compiletime UDFs defined in ExtensionFunctions.hpp
206  static std::unordered_map<std::string, std::vector<ExtensionFunction>> functions_;
207  // Loadtime UDFs defined via omnisci server --udf argument
208  static std::unordered_map<std::string, std::vector<ExtensionFunction>> udf_functions_;
209  // Runtime UDFs defined via thrift interface.
210  static std::unordered_map<std::string, std::vector<ExtensionFunction>>
212 };
213 
214 std::string toString(const ExtArgumentType& sig_type);
215 
216 #endif // QUERYENGINE_EXTENSIONFUNCTIONSWHITELIST_H
static void addUdfs(const std::string &json_func_sigs)
static void addCommon(std::unordered_map< std::string, std::vector< ExtensionFunction >> &sigs, const std::string &json_func_sigs, const bool is_runtime)
static std::vector< ExtensionFunction > get_ext_funcs(const std::string &name)
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
const ExtArgumentType getRet() const
std::string toSignature() const
static std::unordered_map< std::string, std::vector< ExtensionFunction > > rt_udf_functions_
const std::vector< ExtArgumentType > args_
static void add(const std::string &json_func_sigs)
Constants for Builtin SQL Types supported by HEAVY.AI.
const std::string getName(bool keep_suffix=true) const
std::string toStringSQL() const
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
static std::vector< ExtensionFunction > * get_udf(const std::string &name)
static std::unordered_set< std::string > get_udfs_name(const bool is_runtime)
std::string toString(const ExecutorDeviceType &device_type)
const std::vector< std::map< std::string, std::string > > annotations_
const std::vector< ExtArgumentType > & getInputArgs() const
const ExtArgumentType ret_
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
ExtensionFunction(const std::string &name, const std::vector< ExtArgumentType > &args, const ExtArgumentType ret, const std::vector< std::map< std::string, std::string >> &annotations, const bool is_runtime)
string name
Definition: setup.in.py:72
const std::vector< std::map< std::string, std::string > > & getAnnotations() const
static std::vector< std::string > getLLVMDeclarations(const std::unordered_set< std::string > &udf_decls, const bool is_gpu=false)
SQLTypeInfo ext_arg_type_to_type_info(const ExtArgumentType ext_arg_type)
static std::string toStringSQL(const std::vector< ExtArgumentType > &sig_types)
static void addRTUdfs(const std::string &json_func_sigs)