Kuzu C++ API
Loading...
Searching...
No Matches
table_function.h
Go to the documentation of this file.
1#pragma once
2
3#include <mutex>
4
5#include "data_chunk.h"
6#include "mask.h"
7#include "function.h"
8#include "physical_operator.h"
9
10namespace kuzu {
11namespace binder {
12class BoundReadingClause;
13}
14namespace parser {
15struct YieldVariable;
16class ParsedExpression;
17} // namespace parser
18
19namespace planner {
20class LogicalOperator;
21class LogicalPlan;
22class Planner;
23} // namespace planner
24
25namespace processor {
26struct ExecutionContext;
27class PlanMapper;
28} // namespace processor
29
30namespace function {
31
33struct TableFuncBindData;
34
35// Shared state
38 // This for now is only used for QueryHNSWIndex.
39 // TODO(Guodong): This is not a good way to pass semiMasks to QueryHNSWIndex function.
40 // However, to avoid function specific logic when we handle semi mask in mapper, so we can move
41 // HNSW into an extension, we have to let semiMasks be owned by a base class.
43 std::mutex mtx;
44
45 explicit TableFuncSharedState() = default;
47 virtual ~TableFuncSharedState() = default;
48 virtual uint64_t getNumRows() const { return numRows; }
49
51
52 template<class TARGET>
53 TARGET* ptrCast() {
55 }
56};
57
58// Local state
60 virtual ~TableFuncLocalState() = default;
61
62 template<class TARGET>
63 TARGET* ptrCast() {
65 }
66};
67
68// Execution input
81
82// Execution output.
83// We might want to merge this with TableFuncLocalState. Also not all table function output vectors
84// in a single dataChunk, e.g. FTableScan. In future, if we have more cases, we should consider
85// make TableFuncOutput pure virtual.
95
97 TableFuncBindData* bindData;
98 processor::ExecutionContext* context;
99
100 TableFuncInitSharedStateInput(TableFuncBindData* bindData, processor::ExecutionContext* context)
102};
103
104// Init local state
114
115// Init output
124
125using table_func_bind_t = std::function<std::unique_ptr<TableFuncBindData>(main::ClientContext*,
126 const TableFuncBindInput*)>;
128 std::function<common::offset_t(const TableFuncInput&, TableFuncOutput& output)>;
130 std::function<std::shared_ptr<TableFuncSharedState>(const TableFuncInitSharedStateInput&)>;
132 std::function<std::unique_ptr<TableFuncLocalState>(const TableFuncInitLocalStateInput&)>;
134 std::function<std::unique_ptr<TableFuncOutput>(const TableFuncInitOutputInput&)>;
135using table_func_can_parallel_t = std::function<bool()>;
136using table_func_progress_t = std::function<double(TableFuncSharedState* sharedState)>;
138 std::function<void(const processor::ExecutionContext*, TableFuncSharedState*)>;
140 std::function<std::string(main::ClientContext&, const TableFuncBindData& bindData)>;
141using table_func_get_logical_plan_t = std::function<void(planner::Planner*,
142 const binder::BoundReadingClause&, std::vector<std::shared_ptr<binder::Expression>>,
143 std::vector<std::unique_ptr<planner::LogicalPlan>>&)>;
144using table_func_get_physical_plan_t = std::function<std::unique_ptr<processor::PhysicalOperator>(
145 processor::PlanMapper*, const planner::LogicalOperator*)>;
147 std::function<std::vector<common::LogicalType>(const binder::expression_vector&)>;
148
162
164 TableFunction(std::string name, std::vector<common::LogicalTypeID> inputTypes)
165 : Function{std::move(name), std::move(inputTypes)} {}
166 ~TableFunction() override;
167 TableFunction(const TableFunction&) = default;
168 TableFunction& operator=(const TableFunction& other) = default;
170
171 std::string signatureToString() const override {
173 }
174
175 std::unique_ptr<TableFunction> copy() const { return std::make_unique<TableFunction>(*this); }
176
177 // Init local state func
178 static std::unique_ptr<TableFuncLocalState> initEmptyLocalState(
179 const TableFuncInitLocalStateInput& input);
180 // Init shared state func
181 static std::unique_ptr<TableFuncSharedState> initEmptySharedState(
182 const TableFuncInitSharedStateInput& input);
183 // Init output func
184 static std::unique_ptr<TableFuncOutput> initSingleDataChunkScanOutput(
185 const TableFuncInitOutputInput& input);
186 // Utility functions
187 static std::vector<std::string> extractYieldVariables(const std::vector<std::string>& names,
188 const std::vector<parser::YieldVariable>& yieldVariables);
189 // Get logical plan func
190 static void getLogicalPlan(planner::Planner* planner,
191 const binder::BoundReadingClause& boundReadingClause, binder::expression_vector predicates,
192 std::vector<std::unique_ptr<planner::LogicalPlan>>& plans);
193 // Get physical plan func
194 static std::unique_ptr<processor::PhysicalOperator> getPhysicalPlan(
195 processor::PlanMapper* planMapper, const planner::LogicalOperator* logicalOp);
196 // Table func
198};
199
200} // namespace function
201} // 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:68
Definition result_set.h:12
Definition bind_input.h:12
std::vector< std::shared_ptr< Expression > > expression_vector
Definition expression.h:20
std::unordered_map< table_id_t, T > table_id_map_t
Definition types.h:76
uint64_t offset_t
Definition types.h:79
uint64_t row_idx_t
Definition types.h:52
TO ku_dynamic_cast(FROM *old)
Definition cast.h:11
Definition binary_function_executor.h:6
std::function< std::vector< common::LogicalType >(const binder::expression_vector &)> table_func_infer_input_types
Definition table_function.h:146
std::function< bool()> table_func_can_parallel_t
Definition table_function.h:135
std::function< void(const processor::ExecutionContext *, TableFuncSharedState *)> table_func_finalize_t
Definition table_function.h:137
std::function< std::unique_ptr< TableFuncOutput >(const TableFuncInitOutputInput &)> table_func_init_output_t
Definition table_function.h:133
std::function< void(planner::Planner *, const binder::BoundReadingClause &, std::vector< std::shared_ptr< binder::Expression > >, std::vector< std::unique_ptr< planner::LogicalPlan > > &)> table_func_get_logical_plan_t
Definition table_function.h:141
std::function< double(TableFuncSharedState *sharedState)> table_func_progress_t
Definition table_function.h:136
std::function< std::unique_ptr< TableFuncBindData >(main::ClientContext *, const TableFuncBindInput *)> table_func_bind_t
Definition table_function.h:125
std::function< common::offset_t(const TableFuncInput &, TableFuncOutput &output)> table_func_t
Definition table_function.h:127
std::function< std::unique_ptr< processor::PhysicalOperator >( processor::PlanMapper *, const planner::LogicalOperator *)> table_func_get_physical_plan_t
Definition table_function.h:144
std::function< std::string(main::ClientContext &, const TableFuncBindData &bindData)> table_func_rewrite_t
Definition table_function.h:139
std::function< std::shared_ptr< TableFuncSharedState >(const TableFuncInitSharedStateInput &)> table_func_init_shared_t
Definition table_function.h:129
std::function< std::unique_ptr< TableFuncLocalState >(const TableFuncInitLocalStateInput &)> table_func_init_local_t
Definition table_function.h:131
Definition client_context.h:19
Definition kuzu_fwd.h:45
Definition client_context.h:38
Definition array_utils.h:7
static std::string toString(LogicalTypeID dataTypeID)
Function()
Definition function.h:71
std::string name
Definition function.h:62
std::vector< common::LogicalTypeID > parameterTypeIDs
Definition function.h:63
Definition bind_input.h:39
Definition table_function.h:105
main::ClientContext * clientContext
Definition table_function.h:108
TableFuncInitLocalStateInput(TableFuncSharedState &sharedState, TableFuncBindData &bindData, main::ClientContext *clientContext)
Definition table_function.h:110
TableFuncBindData & bindData
Definition table_function.h:107
TableFuncSharedState & sharedState
Definition table_function.h:106
Definition table_function.h:116
processor::ResultSet & resultSet
Definition table_function.h:118
TableFuncInitOutputInput(std::vector< processor::DataPos > outColumnPositions, processor::ResultSet &resultSet)
Definition table_function.h:120
std::vector< processor::DataPos > outColumnPositions
Definition table_function.h:117
Definition table_function.h:96
TableFuncInitSharedStateInput(TableFuncBindData *bindData, processor::ExecutionContext *context)
Definition table_function.h:100
TableFuncBindData * bindData
Definition table_function.h:97
processor::ExecutionContext * context
Definition table_function.h:98
Definition table_function.h:69
TableFuncInput(TableFuncBindData *bindData, TableFuncLocalState *localState, TableFuncSharedState *sharedState, processor::ExecutionContext *context)
Definition table_function.h:76
TableFuncSharedState * sharedState
Definition table_function.h:72
TableFuncBindData * bindData
Definition table_function.h:70
DELETE_COPY_DEFAULT_MOVE(TableFuncInput)
TableFuncLocalState * localState
Definition table_function.h:71
processor::ExecutionContext * context
Definition table_function.h:73
Definition table_function.h:59
virtual ~TableFuncLocalState()=default
TARGET * ptrCast()
Definition table_function.h:63
Definition table_function.h:86
common::DataChunk dataChunk
Definition table_function.h:87
virtual ~TableFuncOutput()=default
TableFuncOutput(common::DataChunk dataChunk)
Definition table_function.h:89
void setOutputSize(common::offset_t size) const
Definition table_function.h:36
common::row_idx_t numRows
Definition table_function.h:37
TableFuncSharedState(common::row_idx_t numRows)
Definition table_function.h:46
TARGET * ptrCast()
Definition table_function.h:53
virtual uint64_t getNumRows() const
Definition table_function.h:48
common::NodeOffsetMaskMap semiMasks
Definition table_function.h:42
common::table_id_map_t< common::SemiMask * > getSemiMasks() const
Definition table_function.h:50
std::mutex mtx
Definition table_function.h:43
TableFunction(const TableFunction &)=default
table_func_bind_t bindFunc
Definition table_function.h:151
static std::unique_ptr< TableFuncSharedState > initEmptySharedState(const TableFuncInitSharedStateInput &input)
TableFunction()
Definition table_function.h:163
table_func_rewrite_t rewriteFunc
Definition table_function.h:158
table_func_get_logical_plan_t getLogicalPlanFunc
Definition table_function.h:159
TableFunction & operator=(const TableFunction &other)=default
static common::offset_t emptyTableFunc(const TableFuncInput &input, TableFuncOutput &output)
table_func_init_local_t initLocalStateFunc
Definition table_function.h:153
static void getLogicalPlan(planner::Planner *planner, const binder::BoundReadingClause &boundReadingClause, binder::expression_vector predicates, std::vector< std::unique_ptr< planner::LogicalPlan > > &plans)
table_func_t tableFunc
Definition table_function.h:150
static std::unique_ptr< TableFuncLocalState > initEmptyLocalState(const TableFuncInitLocalStateInput &input)
static std::unique_ptr< TableFuncOutput > initSingleDataChunkScanOutput(const TableFuncInitOutputInput &input)
table_func_progress_t progressFunc
Definition table_function.h:156
table_func_finalize_t finalizeFunc
Definition table_function.h:157
DEFAULT_BOTH_MOVE(TableFunction)
TableFunction(std::string name, std::vector< common::LogicalTypeID > inputTypes)
Definition table_function.h:164
table_func_infer_input_types inferInputTypes
Definition table_function.h:161
static std::vector< std::string > extractYieldVariables(const std::vector< std::string > &names, const std::vector< parser::YieldVariable > &yieldVariables)
table_func_can_parallel_t canParallelFunc
Definition table_function.h:155
static std::unique_ptr< processor::PhysicalOperator > getPhysicalPlan(processor::PlanMapper *planMapper, const planner::LogicalOperator *logicalOp)
std::string signatureToString() const override
Definition table_function.h:171
table_func_init_output_t initOutputFunc
Definition table_function.h:154
table_func_get_physical_plan_t getPhysicalPlanFunc
Definition table_function.h:160
table_func_init_shared_t initSharedStateFunc
Definition table_function.h:152
std::unique_ptr< TableFunction > copy() const
Definition table_function.h:175
Definition yield_variable.h:7