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 main {
10class ClientContext;
11}
12
13namespace processor {
14struct ExecutionContext;
15}
16
17namespace function {
18
19struct TableFuncBindData;
20struct ScanTableFuncBindInput;
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*)>;
88
94 table_func_can_parallel_t canParallelFunc = [] { return true; };
95 table_func_progress_t progressFunc = [](TableFuncSharedState*) { return 0.0; };
96 table_func_finalize_t finalizeFunc = [](auto, auto, auto) {};
97
99 : Function{}, tableFunc{nullptr}, bindFunc{nullptr}, initSharedStateFunc{nullptr},
100 initLocalStateFunc{nullptr} {};
101 TableFunction(std::string name, table_func_t tableFunc, table_func_bind_t bindFunc,
102 table_func_init_shared_t initSharedFunc, table_func_init_local_t initLocalFunc,
103 std::vector<common::LogicalTypeID> inputTypes,
104 std::optional<table_func_finalize_t> finalizeFunc = {})
105 : Function{std::move(name), std::move(inputTypes)}, tableFunc{tableFunc},
106 bindFunc{bindFunc}, initSharedStateFunc{initSharedFunc},
107 initLocalStateFunc{initLocalFunc} {
108 if (finalizeFunc.has_value()) {
109 this->finalizeFunc = finalizeFunc.value();
110 }
111 }
112 TableFunction(std::string name, table_func_t tableFunc, table_func_bind_t bindFunc,
113 table_func_init_shared_t initSharedFunc, table_func_init_local_t initLocalFunc,
114 table_func_progress_t progressFunc, std::vector<common::LogicalTypeID> inputTypes,
115 std::optional<table_func_finalize_t> finalizeFunc = {})
116 : Function{std::move(name), std::move(inputTypes)}, tableFunc{tableFunc},
117 bindFunc{bindFunc}, initSharedStateFunc{initSharedFunc},
118 initLocalStateFunc{initLocalFunc}, progressFunc(progressFunc) {
119 if (finalizeFunc.has_value()) {
120 this->finalizeFunc = finalizeFunc.value();
121 }
122 }
123
124 std::string signatureToString() const override {
125 return common::LogicalTypeUtils::toString(parameterTypeIDs);
126 }
127};
128
129} // namespace function
130} // 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:57
uint64_t offset_t
Definition types.h:74
TO ku_dynamic_cast(FROM *old)
Definition cast.h:11
std::function< std::unique_ptr< TableFuncBindData >(main::ClientContext *, function::ScanTableFuncBindInput *)> 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
Definition array_utils.h:7
Definition function.h:58
Definition bind_input.h:16
Definition table_functions.h:40
TableFuncSharedState * sharedState
Definition table_functions.h:43
TableFuncBindData * bindData
Definition table_functions.h:41
DELETE_COPY_DEFAULT_MOVE(TableFuncInput)
TableFuncInput(TableFuncBindData *bindData, TableFuncLocalState *localState, TableFuncSharedState *sharedState, main::ClientContext *context)
Definition table_functions.h:47
TableFuncLocalState * localState
Definition table_functions.h:42
main::ClientContext * 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:89
table_func_bind_t bindFunc
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:101
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:112
TableFunction()
Definition table_functions.h:98
table_func_init_local_t initLocalStateFunc
Definition table_functions.h:93
table_func_t tableFunc
Definition table_functions.h:90
std::string signatureToString() const override
Definition table_functions.h:124
table_func_init_shared_t initSharedStateFunc
Definition table_functions.h:92
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