OmniSciDB  72180abbfe
 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 
35 enum class ExtArgumentType {
36  Int8,
37  Int16,
38  Int32,
39  Int64,
40  Float,
41  Double,
42  Void,
43  PInt8,
44  PInt16,
45  PInt32,
46  PInt64,
47  PFloat,
48  PDouble,
49  PBool,
50  Bool,
51  ArrayInt8,
52  ArrayInt16,
53  ArrayInt32,
54  ArrayInt64,
55  ArrayFloat,
57  ArrayBool,
58  GeoPoint,
60  Cursor,
61  GeoPolygon,
63 };
64 
66 
68  public:
69  ExtensionFunction(const std::string& name,
70  const std::vector<ExtArgumentType>& args,
71  const ExtArgumentType ret)
72  : name_(name), args_(args), ret_(ret) {}
73 
74  const std::string& getName() const { return name_; }
75 
76  const std::vector<ExtArgumentType>& getArgs() const { return args_; }
77 
78  const ExtArgumentType getRet() const { return ret_; }
79  std::string toString() const;
80 
81  private:
82  const std::string name_;
83  const std::vector<ExtArgumentType> args_;
85 };
86 
88  public:
89  static void add(const std::string& json_func_sigs);
90 
91  static void addUdfs(const std::string& json_func_sigs);
92 
93  static void clearRTUdfs();
94  static void addRTUdfs(const std::string& json_func_sigs);
95 
96  static std::vector<ExtensionFunction>* get(const std::string& name);
97 
98  static std::vector<ExtensionFunction>* get_udf(const std::string& name);
99 
100  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name);
101 
102  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
103  size_t arity);
104 
105  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
106  size_t arity,
107  const SQLTypeInfo& rtype);
108 
109  static std::string toString(const std::vector<ExtensionFunction>& ext_funcs,
110  std::string tab = "");
111  static std::string toString(const std::vector<SQLTypeInfo>& arg_types);
112  static std::string toString(const std::vector<ExtArgumentType>& sig_types);
113  static std::string toString(const ExtArgumentType& sig_type);
114 
115  static std::vector<std::string> getLLVMDeclarations(
116  const std::unordered_set<std::string>& udf_decls);
117 
118  private:
119  static void addCommon(
120  std::unordered_map<std::string, std::vector<ExtensionFunction>>& sigs,
121  const std::string& json_func_sigs);
122 
123  private:
124  // Function overloading not supported, they're uniquely identified by name.
125  static std::unordered_map<std::string, std::vector<ExtensionFunction>> functions_;
126  static std::unordered_map<std::string, std::vector<ExtensionFunction>> udf_functions_;
127  static std::unordered_map<std::string, std::vector<ExtensionFunction>>
129 };
130 
131 #endif // QUERYENGINE_EXTENSIONFUNCTIONSWHITELIST_H
static void addUdfs(const std::string &json_func_sigs)
const std::vector< ExtArgumentType > & getArgs() const
const std::string & getName() const
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
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)
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 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)
SQLTypeInfo ext_arg_type_to_type_info(const ExtArgumentType ext_arg_type)
static void addRTUdfs(const std::string &json_func_sigs)