OmniSciDB  8a228a1076
TableFunctionsFactory.cpp
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 
18 
19 #include <boost/algorithm/string.hpp>
20 #include <mutex>
21 
22 extern bool g_enable_table_functions;
23 
24 namespace table_functions {
25 
26 namespace {
27 
29  auto generate_column_type = [](const auto subtype) {
30  auto ti = SQLTypeInfo(kCOLUMN, false);
31  ti.set_subtype(subtype);
32  return ti;
33  };
34  switch (ext_arg_type) {
36  return SQLTypeInfo(kTINYINT, false);
38  return SQLTypeInfo(kSMALLINT, false);
40  return SQLTypeInfo(kINT, false);
42  return SQLTypeInfo(kBIGINT, false);
44  return SQLTypeInfo(kFLOAT, false);
46  return SQLTypeInfo(kDOUBLE, false);
48  return SQLTypeInfo(kBOOLEAN, false);
50  return generate_column_type(kTINYINT);
52  return generate_column_type(kSMALLINT);
54  return generate_column_type(kINT);
56  return generate_column_type(kBIGINT);
58  return generate_column_type(kFLOAT);
60  return generate_column_type(kDOUBLE);
62  return generate_column_type(kBOOLEAN);
63  default:
64  LOG(WARNING) << "ext_arg_pointer_type_to_type_info: ExtArgumentType `"
66  << "` conversion to SQLTypeInfo not implemented.";
67  UNREACHABLE();
68  }
69  UNREACHABLE();
70  return SQLTypeInfo(kNULLT, false);
71 }
72 
73 } // namespace
74 
76  CHECK_LT(idx, input_args_.size());
78 }
79 
81  CHECK_LT(idx, output_args_.size());
82  // TODO(adb): conditionally handle nulls
84 }
85 
86 void TableFunctionsFactory::add(const std::string& name,
87  const TableFunctionOutputRowSizer sizer,
88  const std::vector<ExtArgumentType>& input_args,
89  const std::vector<ExtArgumentType>& output_args,
90  bool is_runtime) {
91  functions_.insert(std::make_pair(
92  name, TableFunction(name, sizer, input_args, output_args, is_runtime)));
93 }
94 
95 std::once_flag init_flag;
96 
99  return;
100  }
101  std::call_once(init_flag, []() {
103  "row_copier",
105  std::vector<ExtArgumentType>{ExtArgumentType::ColumnDouble,
107  std::vector<ExtArgumentType>{ExtArgumentType::ColumnDouble});
108  });
109 }
110 
111 const TableFunction& TableFunctionsFactory::get(const std::string& name) {
112  auto func_name = name;
113  boost::algorithm::to_lower(func_name);
114  auto itr = functions_.find(func_name);
115  if (itr == functions_.end()) {
116  throw std::runtime_error("Failed to find registered table function with name " +
117  name);
118  }
119  return itr->second;
120 }
121 
122 std::unordered_map<std::string, TableFunction> TableFunctionsFactory::functions_;
123 
124 } // namespace table_functions
std::string to_lower(const std::string &str)
TableFunction(const std::string &name, const TableFunctionOutputRowSizer output_sizer, const std::vector< ExtArgumentType > &input_args, const std::vector< ExtArgumentType > &output_args, bool is_runtime)
#define LOG(tag)
Definition: Logger.h:188
SQLTypeInfo ext_arg_pointer_type_to_type_info(const ExtArgumentType ext_arg_type)
#define UNREACHABLE()
Definition: Logger.h:241
static const TableFunction & get(const std::string &name)
std::once_flag init_flag
const std::vector< ExtArgumentType > output_args_
SQLTypeInfo getInputSQLType(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:207
SQLTypeInfo getOutputSQLType(const size_t idx) const
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
static std::unordered_map< std::string, TableFunction > functions_
Definition: sqltypes.h:47
static void add(const std::string &name, const TableFunctionOutputRowSizer sizer, const std::vector< ExtArgumentType > &input_args, const std::vector< ExtArgumentType > &output_args, bool is_runtime=false)
const std::vector< ExtArgumentType > input_args_
bool g_enable_table_functions
Definition: Execute.cpp:99