OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 enum class ExtArgumentType {
37  Int8,
38  Int16,
39  Int32,
40  Int64,
41  Float,
42  Double,
43  Void,
44  PInt8,
45  PInt16,
46  PInt32,
47  PInt64,
48  PFloat,
49  PDouble,
50  PBool,
51  Bool,
52  ArrayInt8,
53  ArrayInt16,
54  ArrayInt32,
55  ArrayInt64,
56  ArrayFloat,
58  ArrayBool,
59  GeoPoint,
61  Cursor,
62  GeoPolygon,
64  ColumnInt8,
71 };
72 
74 
76  public:
77  ExtensionFunction(const std::string& name,
78  const std::vector<ExtArgumentType>& args,
79  const ExtArgumentType ret)
80  : name_(name), args_(args), ret_(ret) {}
81 
82  const std::string getName(bool keep_suffix = true) const;
83 
84  const std::vector<ExtArgumentType>& getArgs() const { return args_; }
85  const std::vector<ExtArgumentType>& getInputArgs() const { return args_; }
86 
87  const ExtArgumentType getRet() const { return ret_; }
88  std::string toString() const;
89  std::string toStringSQL() const;
90 
91  bool isGPU() const { return (name_.find("_cpu_") == std::string::npos); }
92  bool isCPU() const { return (name_.find("_gpu_") == std::string::npos); }
93 
94  private:
95  const std::string name_;
96  const std::vector<ExtArgumentType> args_;
98 };
99 
101  public:
102  static void add(const std::string& json_func_sigs);
103 
104  static void addUdfs(const std::string& json_func_sigs);
105 
106  static void clearRTUdfs();
107  static void addRTUdfs(const std::string& json_func_sigs);
108 
109  static std::vector<ExtensionFunction>* get(const std::string& name);
110 
111  static std::vector<ExtensionFunction>* get_udf(const std::string& name);
112 
113  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
114  const bool is_gpu);
115 
116  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
117  size_t arity);
118 
119  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
120  size_t arity,
121  const SQLTypeInfo& rtype);
122 
123  static std::string toString(const std::vector<ExtensionFunction>& ext_funcs,
124  std::string tab = "");
125  static std::string toString(const std::vector<SQLTypeInfo>& arg_types);
126  static std::string toString(const std::vector<ExtArgumentType>& sig_types);
127  static std::string toStringSQL(const std::vector<ExtArgumentType>& sig_types);
128  static std::string toString(const ExtArgumentType& sig_type);
129  static std::string toStringSQL(const ExtArgumentType& sig_type);
130 
131  static std::vector<std::string> getLLVMDeclarations(
132  const std::unordered_set<std::string>& udf_decls);
133 
134  private:
135  static void addCommon(
136  std::unordered_map<std::string, std::vector<ExtensionFunction>>& sigs,
137  const std::string& json_func_sigs);
138 
139  private:
140  // Function overloading not supported, they're uniquely identified by name.
141  static std::unordered_map<std::string, std::vector<ExtensionFunction>> functions_;
142  static std::unordered_map<std::string, std::vector<ExtensionFunction>> udf_functions_;
143  static std::unordered_map<std::string, std::vector<ExtensionFunction>>
145 };
146 
147 std::string toString(const ExtArgumentType& sig_type);
148 
149 #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
std::string toString(const ExtArgumentType &sig_type)
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)
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="")
static std::vector< std::string > getLLVMDeclarations(const std::unordered_set< std::string > &udf_decls)
string name
Definition: setup.py:35
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)