OmniSciDB  5ade3759e0
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 <vector>
31 
32 #include "../Shared/sqltypes.h"
33 
34 enum class ExtArgumentType {
35  Int8,
36  Int16,
37  Int32,
38  Int64,
39  Float,
40  Double,
41  PInt8,
42  PInt16,
43  PInt32,
44  PInt64,
45  PFloat,
46  PDouble,
47  Bool
48 };
49 
51 
53  public:
54  ExtensionFunction(const std::string& name,
55  const std::vector<ExtArgumentType>& args,
56  const ExtArgumentType ret)
57  : name_(name), args_(args), ret_(ret) {}
58 
59  const std::string& getName() const { return name_; }
60 
61  const std::vector<ExtArgumentType>& getArgs() const { return args_; }
62 
63  const ExtArgumentType getRet() const { return ret_; }
64  std::string toString() const;
65 
66  private:
67  const std::string name_;
68  const std::vector<ExtArgumentType> args_;
70 };
71 
73  public:
74  static void add(const std::string& json_func_sigs);
75 
76  static void addUdfs(const std::string& json_func_sigs);
77 
78  static void clearRTUdfs();
79  static void addRTUdfs(const std::string& json_func_sigs);
80 
81  static std::vector<ExtensionFunction>* get(const std::string& name);
82 
83  static std::vector<ExtensionFunction>* get_udf(const std::string& name);
84 
85  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name);
86 
87  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
88  size_t arity);
89 
90  static std::vector<ExtensionFunction> get_ext_funcs(const std::string& name,
91  size_t arity,
92  const SQLTypeInfo& rtype);
93 
94  static std::string toString(const std::vector<ExtensionFunction>& ext_funcs,
95  std::string tab = "");
96  static std::string toString(const std::vector<SQLTypeInfo>& arg_types);
97  static std::string toString(const std::vector<ExtArgumentType>& sig_types);
98 
99  static std::vector<std::string> getLLVMDeclarations();
100 
101  private:
102  static void addCommon(
103  std::unordered_map<std::string, std::vector<ExtensionFunction>>& sigs,
104  const std::string& json_func_sigs);
105 
106  private:
107  // Function overloading not supported, they're uniquely identified by name.
108  static std::unordered_map<std::string, std::vector<ExtensionFunction>> functions_;
109  static std::unordered_map<std::string, std::vector<ExtensionFunction>> udf_functions_;
110  static std::unordered_map<std::string, std::vector<ExtensionFunction>>
112 };
113 
114 #endif // QUERYENGINE_EXTENSIONFUNCTIONSWHITELIST_H
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
static std::unordered_map< std::string, std::vector< ExtensionFunction > > rt_udf_functions_
const std::vector< ExtArgumentType > args_
const ExtArgumentType getRet() const
const std::string & getName() const
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
const std::vector< ExtArgumentType > & getArgs() const
ExtensionFunction(const std::string &name, const std::vector< ExtArgumentType > &args, const ExtArgumentType ret)
const ExtArgumentType ret_
SQLTypeInfo ext_arg_type_to_type_info(const ExtArgumentType ext_arg_type)