OmniSciDB  085a039ca4
 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 2017 MapD Technologies, 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 
17 /*
18  * @file ExtensionFunctionsWhitelist.h
19  * @author Alex Suhan <alex@mapd.com>
20  * @brief Supported runtime functions management and retrieval.
21  *
22  * Copyright (c) 2016 MapD Technologies, Inc. All rights reserved.
23  */
24 
25 #ifndef QUERYENGINE_EXTENSIONFUNCTIONSWHITELIST_H
26 #define QUERYENGINE_EXTENSIONFUNCTIONSWHITELIST_H
27 
28 #include <string>
29 #include <unordered_map>
30 #include <unordered_set>
31 #include <vector>
32 
33 #include "Shared/sqltypes.h"
34 #include "Shared/toString.h"
35 
36 // NOTE: To maintain backwards compatibility:
37 // New types should always be appended to the end of the type list
38 // Existing types should never be removed!
39 enum class ExtArgumentType {
40  Int8,
41  Int16,
42  Int32,
43  Int64,
44  Float,
45  Double,
46  Void,
47  PInt8,
48  PInt16,
49  PInt32,
50  PInt64,
51  PFloat,
52  PDouble,
53  PBool,
54  Bool,
55  ArrayInt8,
56  ArrayInt16,
57  ArrayInt32,
58  ArrayInt64,
59  ArrayFloat,
61  ArrayBool,
62  GeoPoint,
64  Cursor,
65  GeoPolygon,
67  ColumnInt8,
73  ColumnBool,
86  Timestamp,
87 };
88 
90 
92  public:
93  ExtensionFunction(const std::string& name,
94  const std::vector<ExtArgumentType>& args,
95  const ExtArgumentType ret)
96  : name_(name), args_(args), ret_(ret) {}
97 
98  const std::string getName(bool keep_suffix = true) const;
99 
100  const std::vector<ExtArgumentType>& getArgs() const { return args_; }
101  const std::vector<ExtArgumentType>& getInputArgs() const { return args_; }
102 
103  const ExtArgumentType getRet() const { return ret_; }
104  std::string toString() const;
105  std::string toStringSQL() const;
106 
107  inline bool isGPU() const {
108  return (name_.find("_cpu_", name_.find("__")) == std::string::npos);
109  }
110  inline bool isCPU() const {
111  return (name_.find("_gpu_", name_.find("__")) == std::string::npos);
112  }
113 
114  private:
115  const std::string name_;
116  const std::vector<ExtArgumentType> args_;
118 };
119 
121  public:
122  static void add(const std::string& json_func_sigs);
123 
124  static void addUdfs(const std::string& json_func_sigs);
125 
126  static void clearRTUdfs();
127  static void addRTUdfs(const std::string& json_func_sigs);
128 
129  static std::vector<ExtensionFunction>* get(const std::string& name);
130 
131  static std::vector<ExtensionFunction>* get_udf(const std::string& name);
132 
133  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
134  const bool is_gpu);
135 
136  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
137  size_t arity);
138 
139  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
140  size_t arity,
141  const SQLTypeInfo& rtype);
142 
143  static std::string toString(const std::vector<ExtensionFunction>& ext_funcs,
144  std::string tab = "");
145  static std::string toString(const std::vector<SQLTypeInfo>& arg_types);
146  static std::string toString(const std::vector<ExtArgumentType>& sig_types);
147  static std::string toStringSQL(const std::vector<ExtArgumentType>& sig_types);
148  static std::string toString(const ExtArgumentType& sig_type);
149  static std::string toStringSQL(const ExtArgumentType& sig_type);
150 
151  static std::vector<std::string> getLLVMDeclarations(
152  const std::unordered_set<std::string>& udf_decls,
153  const bool is_gpu = false);
154 
155  private:
156  static void addCommon(
157  std::unordered_map<std::string, std::vector<ExtensionFunction>>& sigs,
158  const std::string& json_func_sigs);
159 
160  private:
161  // Compiletime UDFs defined in ExtensionFunctions.hpp
162  static std::unordered_map<std::string, std::vector<ExtensionFunction>> functions_;
163  // Loadtime UDFs defined via omnisci server --udf argument
164  static std::unordered_map<std::string, std::vector<ExtensionFunction>> udf_functions_;
165  // Runtime UDFs defined via thrift interface.
166  static std::unordered_map<std::string, std::vector<ExtensionFunction>>
168 };
169 
170 std::string toString(const ExtArgumentType& sig_type);
171 
172 #endif // QUERYENGINE_EXTENSIONFUNCTIONSWHITELIST_H
static std::vector< ExtensionFunction > get_ext_funcs(const std::string &name, const bool is_gpu)
static void addUdfs(const std::string &json_func_sigs)
const std::vector< ExtArgumentType > & getArgs() const
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
const ExtArgumentType getRet() 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 OmniSci.
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)
ExtensionFunction(const std::string &name, const std::vector< ExtArgumentType > &args, const ExtArgumentType ret)
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1453
static void addCommon(std::unordered_map< std::string, std::vector< ExtensionFunction >> &sigs, const std::string &json_func_sigs)
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)