Kùzu C++ API
Loading...
Searching...
No Matches
table_functions.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
5#include "data_chunk.h"
6#include "function.h"
7
8namespace kuzu {
9namespace parser {
10class ParsedExpression;
11}
12
13namespace processor {
14struct ExecutionContext;
15}
16
17namespace function {
18
19struct TableFuncBindInput;
20struct TableFuncBindData;
21
23 virtual ~TableFuncSharedState() = default;
24
25 template<class TARGET>
26 TARGET* ptrCast() {
28 }
29};
30
32 virtual ~TableFuncLocalState() = default;
33
34 template<class TARGET>
35 TARGET* ptrCast() {
37 }
38};
39
52
53// We are in the middle of merging different scan operators into table function. But they organize
54// output vectors in different ways. E.g.
55// - Call functions and scan file functions put all vectors into single data chunk
56// - Factorized table scan instead
57// We introduce this as a temporary solution to unify the interface. In the long term, we should aim
58// to use ResultSet as TableFuncOutput.
66
68 TableFuncBindData* bindData;
69 uint64_t queryID;
70
71 explicit TableFunctionInitInput(TableFuncBindData* bindData, uint64_t queryID)
73
74 virtual ~TableFunctionInitInput() = default;
75};
76
77using table_func_bind_t = std::function<std::unique_ptr<TableFuncBindData>(main::ClientContext*,
81 std::function<std::unique_ptr<TableFuncSharedState>(TableFunctionInitInput&)>;
82using table_func_init_local_t = std::function<std::unique_ptr<TableFuncLocalState>(
83 TableFunctionInitInput&, TableFuncSharedState*, storage::MemoryManager*)>;
84using table_func_can_parallel_t = std::function<bool()>;
85using table_func_progress_t = std::function<double(TableFuncSharedState* sharedState)>;
87 std::function<void(processor::ExecutionContext*, TableFuncSharedState*, TableFuncLocalState*)>;
89 std::function<std::string(main::ClientContext&, const TableFuncBindData& bindData)>;
90
92 table_func_t tableFunc = nullptr;
93 table_func_bind_t bindFunc = nullptr;
94 table_func_init_shared_t initSharedStateFunc = nullptr;
95 table_func_init_local_t initLocalStateFunc = nullptr;
96 table_func_can_parallel_t canParallelFunc = [] { return true; };
97 table_func_progress_t progressFunc = [](TableFuncSharedState*) { return 0.0; };
98 table_func_finalize_t finalizeFunc = [](auto, auto, auto) {};
100
102 : Function{}, tableFunc{nullptr}, bindFunc{nullptr}, initSharedStateFunc{nullptr},
103 initLocalStateFunc{nullptr} {};
104 TableFunction(std::string name, std::vector<common::LogicalTypeID> inputTypes)
105 : Function{name, inputTypes} {}
106 TableFunction(std::string name, table_func_t tableFunc, table_func_bind_t bindFunc,
107 table_func_init_shared_t initSharedFunc, table_func_init_local_t initLocalFunc,
108 std::vector<common::LogicalTypeID> inputTypes,
109 std::optional<table_func_finalize_t> finalizeFunc = {})
110 : Function{std::move(name), std::move(inputTypes)}, tableFunc{tableFunc},
111 bindFunc{bindFunc}, initSharedStateFunc{initSharedFunc},
112 initLocalStateFunc{initLocalFunc} {
113 if (finalizeFunc.has_value()) {
114 this->finalizeFunc = finalizeFunc.value();
115 }
116 }
117 TableFunction(std::string name, table_func_t tableFunc, table_func_bind_t bindFunc,
118 table_func_init_shared_t initSharedFunc, table_func_init_local_t initLocalFunc,
119 table_func_progress_t progressFunc, std::vector<common::LogicalTypeID> inputTypes,
120 std::optional<table_func_finalize_t> finalizeFunc = {})
121 : Function{std::move(name), std::move(inputTypes)}, tableFunc{tableFunc},
122 bindFunc{bindFunc}, initSharedStateFunc{initSharedFunc},
123 initLocalStateFunc{initLocalFunc}, progressFunc(progressFunc) {
124 if (finalizeFunc.has_value()) {
125 this->finalizeFunc = finalizeFunc.value();
126 }
127 }
128
129 std::string signatureToString() const override {
130 return common::LogicalTypeUtils::toString(parameterTypeIDs);
131 }
132
133 virtual std::unique_ptr<TableFunction> copy() const {
134 return std::make_unique<TableFunction>(*this);
135 }
136};
137
138} // namespace function
139} // namespace kuzu
#define KUZU_API
Definition api.h:25
Definition data_chunk.h:20
Contain client side configuration. We make profiler associated per query, so profiler is not maintain...
Definition client_context.h:61
uint64_t offset_t
Definition types.h:77
TO ku_dynamic_cast(FROM *old)
Definition cast.h:11
std::function< std::unique_ptr< TableFuncBindData >(main::ClientContext *, function::TableFuncBindInput *)> table_func_bind_t
Definition table_functions.h:77
std::function< std::unique_ptr< TableFuncSharedState >(TableFunctionInitInput &)> table_func_init_shared_t
Definition table_functions.h:80
std::function< bool()> table_func_can_parallel_t
Definition table_functions.h:84
std::function< std::unique_ptr< TableFuncLocalState >( TableFunctionInitInput &, TableFuncSharedState *, storage::MemoryManager *)> table_func_init_local_t
Definition table_functions.h:82
std::function< common::offset_t(TableFuncInput &, TableFuncOutput &)> table_func_t
Definition table_functions.h:79
std::function< void(processor::ExecutionContext *, TableFuncSharedState *, TableFuncLocalState *)> table_func_finalize_t
Definition table_functions.h:86
std::function< double(TableFuncSharedState *sharedState)> table_func_progress_t
Definition table_functions.h:85
std::function< std::string(main::ClientContext &, const TableFuncBindData &bindData)> table_func_rewrite_t
Definition table_functions.h:88
Definition array_utils.h:7
Definition function.h:58
Definition bind_input.h:38
Definition table_functions.h:40
TableFuncInput(TableFuncBindData *bindData, TableFuncLocalState *localState, TableFuncSharedState *sharedState, processor::ExecutionContext *context)
Definition table_functions.h:47
TableFuncSharedState * sharedState
Definition table_functions.h:43
TableFuncBindData * bindData
Definition table_functions.h:41
DELETE_COPY_DEFAULT_MOVE(TableFuncInput)
TableFuncLocalState * localState
Definition table_functions.h:42
processor::ExecutionContext * context
Definition table_functions.h:44
Definition table_functions.h:31
virtual ~TableFuncLocalState()=default
TARGET * ptrCast()
Definition table_functions.h:35
Definition table_functions.h:59
common::DataChunk dataChunk
Definition table_functions.h:60
DELETE_COPY_DEFAULT_MOVE(TableFuncOutput)
std::vector< common::ValueVector * > vectors
Definition table_functions.h:61
Definition table_functions.h:22
TARGET * ptrCast()
Definition table_functions.h:26
Definition table_functions.h:91
TableFunction(std::string name, table_func_t tableFunc, table_func_bind_t bindFunc, table_func_init_shared_t initSharedFunc, table_func_init_local_t initLocalFunc, std::vector< common::LogicalTypeID > inputTypes, std::optional< table_func_finalize_t > finalizeFunc={})
Definition table_functions.h:106
TableFunction(std::string name, table_func_t tableFunc, table_func_bind_t bindFunc, table_func_init_shared_t initSharedFunc, table_func_init_local_t initLocalFunc, table_func_progress_t progressFunc, std::vector< common::LogicalTypeID > inputTypes, std::optional< table_func_finalize_t > finalizeFunc={})
Definition table_functions.h:117
TableFunction()
Definition table_functions.h:101
table_func_rewrite_t rewriteFunc
Definition table_functions.h:99
TableFunction(std::string name, std::vector< common::LogicalTypeID > inputTypes)
Definition table_functions.h:104
std::string signatureToString() const override
Definition table_functions.h:129
virtual std::unique_ptr< TableFunction > copy() const
Definition table_functions.h:133
Definition table_functions.h:67
uint64_t queryID
Definition table_functions.h:69
TableFuncBindData * bindData
Definition table_functions.h:68
TableFunctionInitInput(TableFuncBindData *bindData, uint64_t queryID)
Definition table_functions.h:71