OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  switch (ext_arg_type) {
31  return SQLTypeInfo(kTINYINT, false);
33  return SQLTypeInfo(kSMALLINT, false);
35  return SQLTypeInfo(kINT, false);
37  return SQLTypeInfo(kBIGINT, false);
39  return SQLTypeInfo(kFLOAT, false);
41  return SQLTypeInfo(kDOUBLE, false);
42  default:
43  UNREACHABLE();
44  }
45  UNREACHABLE();
46  return SQLTypeInfo(kNULLT, false);
47 }
48 
49 } // namespace
50 
52  CHECK_LT(idx, output_args_.size());
53  // TODO(adb): conditionally handle nulls
55 }
56 
57 void TableFunctionsFactory::add(const std::string& name,
58  const TableFunctionOutputRowSizer sizer,
59  const std::vector<ExtArgumentType>& input_args,
60  const std::vector<ExtArgumentType>& output_args,
61  bool is_runtime) {
62  functions_.insert(std::make_pair(
63  name, TableFunction(name, sizer, input_args, output_args, is_runtime)));
64 }
65 
66 std::once_flag init_flag;
67 
70  return;
71  }
72  std::call_once(init_flag, []() {
74  "row_copier",
76  std::vector<ExtArgumentType>{ExtArgumentType::PDouble,
79  ExtArgumentType::PInt64},
80  std::vector<ExtArgumentType>{ExtArgumentType::PDouble});
81  });
82 }
83 
84 const TableFunction& TableFunctionsFactory::get(const std::string& name) {
85  auto func_name = name;
86  boost::algorithm::to_lower(func_name);
87  auto itr = functions_.find(func_name);
88  if (itr == functions_.end()) {
89  throw std::runtime_error("Failed to find registered table function with name " +
90  name);
91  }
92  return itr->second;
93 }
94 
95 std::unordered_map<std::string, TableFunction> TableFunctionsFactory::functions_;
96 
97 } // namespace table_functions
SQLTypeInfo getOutputSQLType(const size_t idx) const
SQLTypeInfo ext_arg_pointer_type_to_type_info(const ExtArgumentType ext_arg_type)
#define UNREACHABLE()
Definition: Logger.h:234
static const TableFunction & get(const std::string &name)
std::once_flag init_flag
const std::vector< ExtArgumentType > output_args_
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:852
#define CHECK_LT(x, y)
Definition: Logger.h:200
bool g_enable_table_functions
Definition: Execute.cpp:94
static std::unordered_map< std::string, TableFunction > functions_
Definition: sqltypes.h:48
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)