OmniSciDB  8a228a1076
TableFunctionsFactory.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, 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 #pragma once
18 
19 #include <string>
20 #include <vector>
21 
23 
24 namespace table_functions {
25 
29  kConstant
30 };
31 
34  const size_t val{0};
35 };
36 
38  public:
39  TableFunction(const std::string& name,
40  const TableFunctionOutputRowSizer output_sizer,
41  const std::vector<ExtArgumentType>& input_args,
42  const std::vector<ExtArgumentType>& output_args,
43  bool is_runtime)
44  : name_(name)
45  , output_sizer_(output_sizer)
46  , input_args_(input_args)
47  , output_args_(output_args)
48  , is_runtime_(is_runtime) {}
49 
50  std::vector<ExtArgumentType> getArgs() const {
51  std::vector<ExtArgumentType> args;
52  args.insert(args.end(), input_args_.begin(), input_args_.end());
53  args.insert(args.end(), output_args_.begin(), output_args_.end());
54  return args;
55  }
56 
57  SQLTypeInfo getInputSQLType(const size_t idx) const;
58  SQLTypeInfo getOutputSQLType(const size_t idx) const;
59 
60  auto getOutputsSize() const { return output_args_.size(); }
61 
62  auto getName() const { return name_; }
63 
65  return output_sizer_.type == OutputBufferSizeType::kUserSpecifiedRowMultiplier;
66  }
67 
68  size_t getOutputRowParameter() const { return output_sizer_.val; }
69 
70  bool isRuntime() const { return is_runtime_; }
71 
72  std::string toString() const {
73  auto result = "TableFunction(" + name_ + ", [";
75  result += "], [";
77  result += "], is_runtime=" + std::string((is_runtime_ ? "true" : "false"));
78  result += ")";
79  return result;
80  }
81 
82  private:
83  const std::string name_;
85  const std::vector<ExtArgumentType> input_args_;
86  const std::vector<ExtArgumentType> output_args_;
87  const bool is_runtime_;
88 };
89 
91  public:
92  static void add(const std::string& name,
93  const TableFunctionOutputRowSizer sizer,
94  const std::vector<ExtArgumentType>& input_args,
95  const std::vector<ExtArgumentType>& output_args,
96  bool is_runtime = false);
97 
98  static const TableFunction& get(const std::string& name);
99 
100  static void init();
101 
102  private:
103  static std::unordered_map<std::string, TableFunction> functions_;
104 
105  friend class ::ExtensionFunctionsWhitelist;
106 };
107 
108 } // namespace table_functions
TableFunction(const std::string &name, const TableFunctionOutputRowSizer output_sizer, const std::vector< ExtArgumentType > &input_args, const std::vector< ExtArgumentType > &output_args, bool is_runtime)
const TableFunctionOutputRowSizer output_sizer_
const std::vector< ExtArgumentType > output_args_
void init(LogOptions const &log_opts)
Definition: Logger.cpp:280
std::vector< ExtArgumentType > getArgs() const
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
static std::unordered_map< std::string, TableFunction > functions_
const std::vector< ExtArgumentType > input_args_