/
physical_operator.hpp
95 lines (83 loc) · 3.28 KB
/
physical_operator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//===----------------------------------------------------------------------===//
// DuckDB
//
// duckdb/execution/physical_operator.hpp
//
//
//===----------------------------------------------------------------------===//
#pragma once
#include "duckdb/catalog/catalog.hpp"
#include "duckdb/common/common.hpp"
#include "duckdb/common/enums/physical_operator_type.hpp"
#include "duckdb/common/types/data_chunk.hpp"
#include "duckdb/parser/statement/select_statement.hpp"
#include "duckdb/planner/expression.hpp"
#include "duckdb/planner/logical_operator.hpp"
namespace duckdb {
class ClientContext;
class ExpressionExecutor;
class PhysicalOperator;
//! The current state/context of the operator. The PhysicalOperatorState is
//! updated using the GetChunk function, and allows the caller to repeatedly
//! call the GetChunk function and get new batches of data everytime until the
//! data source is exhausted.
class PhysicalOperatorState {
public:
PhysicalOperatorState(PhysicalOperator *child);
virtual ~PhysicalOperatorState() = default;
//! Flag indicating whether or not the operator is finished [note: not all
//! operators use this flag]
bool finished;
//! DataChunk that stores data from the child of this operator
DataChunk child_chunk;
//! State of the child of this operator
unique_ptr<PhysicalOperatorState> child_state;
};
//! PhysicalOperator is the base class of the physical operators present in the
//! execution plan
/*!
The execution model is a pull-based execution model. GetChunk is called on
the root node, which causes the root node to be executed, and presumably call
GetChunk again on its child nodes. Every node in the operator chain has a
state that is updated as GetChunk is called: PhysicalOperatorState (different
operators subclass this state and add different properties).
*/
class PhysicalOperator {
public:
PhysicalOperator(PhysicalOperatorType type, vector<TypeId> types) : type(type), types(types) {
}
virtual ~PhysicalOperator() {
}
//! The physical operator type
PhysicalOperatorType type;
//! The set of children of the operator
vector<unique_ptr<PhysicalOperator>> children;
//! The types returned by this physical operator
vector<TypeId> types;
public:
string ToString(index_t depth = 0) const;
void Print();
//! Return a vector of the types that will be returned by this operator
vector<TypeId> &GetTypes() {
return types;
}
//! Initialize a given chunk to the types that will be returned by this
//! operator, this will prepare chunk for a call to GetChunk. This method
//! only has to be called once for any amount of calls to GetChunk.
virtual void InitializeChunk(DataChunk &chunk) {
auto &types = GetTypes();
chunk.Initialize(types);
}
//! Retrieves a chunk from this operator and stores it in the chunk
//! variable.
virtual void GetChunkInternal(ClientContext &context, DataChunk &chunk, PhysicalOperatorState *state) = 0;
void GetChunk(ClientContext &context, DataChunk &chunk, PhysicalOperatorState *state);
//! Create a new empty instance of the operator state
virtual unique_ptr<PhysicalOperatorState> GetOperatorState() {
return make_unique<PhysicalOperatorState>(children.size() == 0 ? nullptr : children[0].get());
}
virtual string ExtraRenderInformation() const {
return "";
}
};
} // namespace duckdb