OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TableFunctionOps.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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 #ifdef EXECUTE_INCLUDE
18 
20 
21 /*
22  set_output_row_size sets the row size of output Columns and
23  allocates the corresponding column buffers.
24 
25  `set_output_row_size` can be called exactly one time when entering a
26  table function (when not using TableFunctionSpecifiedParameter
27  sizer) or within a table function (when using
28  TableFunctionSpecifiedParameter sizer).
29 
30  For thread-safety, it is recommended to have `TableFunctionManager
31  mgr` as a first argument in a UDTF definition and then use
32  `mgr.set_output_row_size(..)` to set the row size of output columns,
33 */
34 
36  int8_t* mgr_ptr,
37  int64_t num_rows) {
38  auto mgr = reinterpret_cast<TableFunctionManager*>(mgr_ptr);
39  if (num_rows < 0) {
40  throw TableFunctionError(
41  "set_output_row_size: expected non-negative row size but got " +
42  std::to_string(num_rows));
43  }
44  mgr->allocate_output_buffers(num_rows);
45 }
46 
47 extern "C" DEVICE RUNTIME_EXPORT void set_output_row_size(int64_t num_rows) {
49  TableFunctionManager_set_output_row_size(reinterpret_cast<int8_t*>(mgr), num_rows);
50 }
51 
52 /*
53  TableFunctionManager_register_output_column stores the pointer of
54  output Column instance so that when the buffers of output columns
55  are allocated, the Column instance members ptr_ and size_ can be
56  updated.
57 
58  TableFunctionManager_register_output_column is used internally when
59  creating output Column instances prior entering the table function.
60  */
61 
62 extern "C" DEVICE RUNTIME_EXPORT void
63 TableFunctionManager_register_output_column(int8_t* mgr_ptr, int32_t index, int8_t* ptr) {
64  auto mgr = reinterpret_cast<TableFunctionManager*>(mgr_ptr);
65  CHECK(mgr);
66  mgr->set_output_column(index, ptr);
67 }
68 
69 /*
70  table_function_error allows code from within a table function to
71  set an error message that can be accessed from the execution context.
72  This allows the error message to be propagated as an exception message.
73  */
74 extern "C" DEVICE RUNTIME_EXPORT int32_t
75 TableFunctionManager_error_message(int8_t* mgr_ptr, const char* message) {
76  auto mgr = reinterpret_cast<TableFunctionManager*>(mgr_ptr);
77  CHECK(mgr);
78  if (message != nullptr) {
79  mgr->set_error_message(message);
80  } else {
81  mgr->set_error_message("no error message set");
82  }
84 }
85 
86 extern "C" DEVICE RUNTIME_EXPORT int32_t table_function_error(const char* message) {
88  return TableFunctionManager_error_message(reinterpret_cast<int8_t*>(mgr), message);
89 }
90 /*
91  TableFunctionManager_get_singleton is used internally to get the
92  pointer to global singleton of TableFunctionManager, if initialized,
93  otherwise throws runtime error.
94 */
97  if (!mgr) {
98  throw TableFunctionError("uninitialized TableFunctionManager singleton");
99  }
100  return reinterpret_cast<int8_t*>(mgr);
101 }
102 
103 #endif // EXECUTE_INCLUDE
EXTENSION_NOINLINE int32_t table_function_error(const char *message)
std::string to_string(char const *&&v)
#define DEVICE
EXTENSION_NOINLINE void TableFunctionManager_set_output_row_size(int8_t *mgr_ptr, int64_t num_rows)
EXTENSION_NOINLINE int8_t * TableFunctionManager_get_singleton()
EXTENSION_NOINLINE void set_output_row_size(int64_t num_rows)
#define RUNTIME_EXPORT
#define CHECK(condition)
Definition: Logger.h:209
static TableFunctionManager * get_singleton()
Definition: OmniSciTypes.h:300
EXTENSION_NOINLINE int32_t TableFunctionManager_error_message(int8_t *mgr_ptr, const char *message)