OmniSciDB  ca0c39ec8f
 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,
109 };
110 
112 
114  public:
115  ExtensionFunction(const std::string& name,
116  const std::vector<ExtArgumentType>& args,
117  const ExtArgumentType ret,
118  const bool is_runtime)
119  : name_(name), args_(args), ret_(ret), is_runtime_(is_runtime) {}
120 
121  const std::string getName(bool keep_suffix = true) const;
122 
123  const std::vector<ExtArgumentType>& getInputArgs() const { return args_; }
124  const ExtArgumentType getRet() const { return ret_; }
125 
126  std::string toString() const;
127  std::string toStringSQL() const;
128  std::string toSignature() const;
129 
130  inline bool isGPU() const {
131  return (name_.find("_cpu_", name_.find("__")) == std::string::npos);
132  }
133 
134  inline bool isCPU() const {
135  return (name_.find("_gpu_", name_.find("__")) == std::string::npos);
136  }
137 
138  inline bool isRuntime() const { return is_runtime_; }
139 
140  private:
141  const std::string name_;
142  const std::vector<ExtArgumentType> args_;
144  const bool is_runtime_;
145 };
146 
148  public:
149  static void add(const std::string& json_func_sigs);
150 
151  static void addUdfs(const std::string& json_func_sigs);
152 
153  static void clearRTUdfs();
154  static void addRTUdfs(const std::string& json_func_sigs);
155 
156  static std::vector<ExtensionFunction>* get(const std::string& name);
157 
158  static std::vector<ExtensionFunction>* get_udf(const std::string& name);
159 
160  static std::unordered_set<std::string> get_udfs_name(const bool is_runtime);
161 
162  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name);
163 
164  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
165  const bool is_gpu);
166 
167  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
168  size_t arity);
169 
170  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
171  size_t arity,
172  const SQLTypeInfo& rtype);
173 
174  static std::string toString(const std::vector<ExtensionFunction>& ext_funcs,
175  std::string tab = "");
176  static std::string toString(const std::vector<SQLTypeInfo>& arg_types);
177  static std::string toString(const std::vector<ExtArgumentType>& sig_types);
178  static std::string toStringSQL(const std::vector<ExtArgumentType>& sig_types);
179  static std::string toString(const ExtArgumentType& sig_type);
180  static std::string toStringSQL(const ExtArgumentType& sig_type);
181 
182  static std::vector<std::string> getLLVMDeclarations(
183  const std::unordered_set<std::string>& udf_decls,
184  const bool is_gpu = false);
185 
186  private:
187  static void addCommon(
188  std::unordered_map<std::string, std::vector<ExtensionFunction>>& sigs,
189  const std::string& json_func_sigs,
190  const bool is_runtime);
191 
192  private:
193  // Compiletime UDFs defined in ExtensionFunctions.hpp
194  static std::unordered_map<std::string, std::vector<ExtensionFunction>> functions_;
195  // Loadtime UDFs defined via omnisci server --udf argument
196  static std::unordered_map<std::string, std::vector<ExtensionFunction>> udf_functions_;
197  // Runtime UDFs defined via thrift interface.
198  static std::unordered_map<std::string, std::vector<ExtensionFunction>>
200 };
201 
202 std::string toString(const ExtArgumentType& sig_type);
203 
204 #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)
ExtensionFunction(const std::string &name, const std::vector< ExtArgumentType > &args, const ExtArgumentType ret, 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< ExtArgumentType > & getInputArgs() const
const ExtArgumentType ret_
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
string name
Definition: setup.in.py:72
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)