1 | #include "duckdb/execution/operator/scan/physical_expression_scan.hpp" |
---|---|
2 | |
3 | #include "duckdb/execution/expression_executor.hpp" |
4 | |
5 | using namespace duckdb; |
6 | using namespace std; |
7 | |
8 | class PhysicalExpressionScanState : public PhysicalOperatorState { |
9 | public: |
10 | PhysicalExpressionScanState(PhysicalOperator *child) : PhysicalOperatorState(child), expression_index(0) { |
11 | } |
12 | |
13 | //! The current position in the scan |
14 | idx_t expression_index; |
15 | |
16 | unique_ptr<ExpressionExecutor> executor; |
17 | }; |
18 | |
19 | void PhysicalExpressionScan::GetChunkInternal(ClientContext &context, DataChunk &chunk, PhysicalOperatorState *state_) { |
20 | auto state = (PhysicalExpressionScanState *)state_; |
21 | if (state->expression_index >= expressions.size()) { |
22 | // finished executing all expression lists |
23 | return; |
24 | } |
25 | |
26 | if (state->expression_index == 0) { |
27 | // first run, fetch the chunk from the child |
28 | assert(children.size() == 1); |
29 | children[0]->GetChunk(context, state->child_chunk, state->child_state.get()); |
30 | if (state->child_chunk.size() == 0) { |
31 | return; |
32 | } |
33 | } |
34 | // now execute the expressions of the nth expression list for the child chunk list |
35 | state->executor = make_unique<ExpressionExecutor>(expressions[state->expression_index]); |
36 | state->executor->Execute(state->child_chunk, chunk); |
37 | |
38 | state->expression_index++; |
39 | } |
40 | |
41 | unique_ptr<PhysicalOperatorState> PhysicalExpressionScan::GetOperatorState() { |
42 | return make_unique<PhysicalExpressionScanState>(children[0].get()); |
43 | } |
44 |