OmniSciDB  72c90bc290
 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,
123 };
124 
126 
128  public:
129  ExtensionFunction(const std::string& name,
130  const std::vector<ExtArgumentType>& args,
131  const ExtArgumentType ret,
132  const std::vector<std::map<std::string, std::string>>& annotations,
133  const bool is_runtime)
134  : name_(name)
135  , args_(args)
136  , ret_(ret)
137  , annotations_(annotations)
138  , is_runtime_(is_runtime) {}
139 
140  const std::string getName(bool keep_suffix = true) const;
141 
142  const std::vector<ExtArgumentType>& getInputArgs() const { return args_; }
143  const ExtArgumentType getRet() const { return ret_; }
144  const std::vector<std::map<std::string, std::string>>& getAnnotations() const {
145  return annotations_;
146  }
147 
148  bool usesManager() const;
149  std::string toString() const;
150  std::string toStringSQL() const;
151  std::string toSignature() const;
152 
153  inline bool isGPU() const {
154  return (name_.find("_cpu_", name_.find("__")) == std::string::npos);
155  }
156 
157  inline bool isCPU() const {
158  return (name_.find("_gpu_", name_.find("__")) == std::string::npos);
159  }
160 
161  inline bool isRuntime() const { return is_runtime_; }
162 
163  private:
164  const std::string name_;
165  const std::vector<ExtArgumentType> args_;
167  const std::vector<std::map<std::string, std::string>> annotations_;
168  const bool is_runtime_;
169 };
170 
172  public:
173  static void add(const std::string& json_func_sigs);
174 
175  static void addUdfs(const std::string& json_func_sigs);
176 
177  static void clearRTUdfs();
178  static void addRTUdfs(const std::string& json_func_sigs);
179 
180  static std::vector<ExtensionFunction>* get(const std::string& name);
181 
182  static std::vector<ExtensionFunction>* get_udf(const std::string& name);
183 
184  static std::unordered_set<std::string> get_udfs_name(const bool is_runtime);
185 
186  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name);
187 
188  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
189  const bool is_gpu);
190 
191  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
192  size_t arity);
193 
194  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
195  size_t arity,
196  const SQLTypeInfo& rtype);
197 
198  static std::string toString(const std::vector<ExtensionFunction>& ext_funcs,
199  std::string tab = "");
200  static std::string toString(const std::vector<SQLTypeInfo>& arg_types);
201  static std::string toString(const std::vector<ExtArgumentType>& sig_types);
202  static std::string toStringSQL(const std::vector<ExtArgumentType>& sig_types);
203  static std::string toString(const ExtArgumentType& sig_type);
204  static std::string toStringSQL(const ExtArgumentType& sig_type);
205 
206  static std::vector<std::string> getLLVMDeclarations(
207  const std::unordered_set<std::string>& udf_decls,
208  const bool is_gpu = false);
209 
210  private:
211  static void addCommon(
212  std::unordered_map<std::string, std::vector<ExtensionFunction>>& sigs,
213  const std::string& json_func_sigs,
214  const bool is_runtime);
215 
216  private:
217  // Compiletime UDFs defined in ExtensionFunctions.hpp
218  static std::unordered_map<std::string, std::vector<ExtensionFunction>> functions_;
219  // Loadtime UDFs defined via omnisci server --udf argument
220  static std::unordered_map<std::string, std::vector<ExtensionFunction>> udf_functions_;
221  // Runtime UDFs defined via thrift interface.
222  static std::unordered_map<std::string, std::vector<ExtensionFunction>>
224 };
225 
226 std::string toString(const ExtArgumentType& sig_type);
227 
228 #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.
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
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)
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)