1#include "duckdb/execution/expression_executor_state.hpp"
2#include "duckdb/execution/expression_executor.hpp"
3#include "duckdb/planner/expression.hpp"
4#include "duckdb/planner/expression/bound_function_expression.hpp"
5
6namespace duckdb {
7
8void ExpressionState::AddChild(Expression *expr) {
9 types.push_back(x: expr->return_type);
10 child_states.push_back(x: ExpressionExecutor::InitializeState(expr: *expr, state&: root));
11}
12
13void ExpressionState::Finalize() {
14 if (!types.empty()) {
15 intermediate_chunk.Initialize(allocator&: GetAllocator(), types);
16 }
17}
18
19Allocator &ExpressionState::GetAllocator() {
20 return root.executor->GetAllocator();
21}
22
23bool ExpressionState::HasContext() {
24 return root.executor->HasContext();
25}
26
27ClientContext &ExpressionState::GetContext() {
28 if (!HasContext()) {
29 throw BinderException("Cannot use %s in this context", (expr.Cast<BoundFunctionExpression>()).function.name);
30 }
31 return root.executor->GetContext();
32}
33
34ExpressionState::ExpressionState(const Expression &expr, ExpressionExecutorState &root) : expr(expr), root(root) {
35}
36
37ExpressionExecutorState::ExpressionExecutorState() : profiler() {
38}
39
40void ExpressionState::Verify(ExpressionExecutorState &root_executor) {
41 D_ASSERT(&root_executor == &root);
42 for (auto &entry : child_states) {
43 entry->Verify(root_executor);
44 }
45}
46
47void ExpressionExecutorState::Verify() {
48 D_ASSERT(executor);
49 root_state->Verify(root_executor&: *this);
50}
51
52} // namespace duckdb
53