1#include "duckdb/common/vector_operations/vector_operations.hpp"
2#include "duckdb/execution/expression_executor.hpp"
3#include "duckdb/planner/expression/bound_cast_expression.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8unique_ptr<ExpressionState> ExpressionExecutor::InitializeState(BoundCastExpression &expr,
9 ExpressionExecutorState &root) {
10 auto result = make_unique<ExpressionState>(expr, root);
11 result->AddChild(expr.child.get());
12 return result;
13}
14
15void ExpressionExecutor::Execute(BoundCastExpression &expr, ExpressionState *state, const SelectionVector *sel,
16 idx_t count, Vector &result) {
17 // resolve the child
18 Vector child(expr.child->return_type);
19 auto child_state = state->child_states[0].get();
20
21 Execute(*expr.child, child_state, sel, count, child);
22 if (expr.source_type == expr.target_type) {
23 // NOP cast
24 result.Reference(child);
25 } else {
26 // cast it to the type specified by the cast expression
27 VectorOperations::Cast(child, result, expr.source_type, expr.target_type, count);
28 }
29}
30