Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::ExpressionExecutor Class Reference

ExpressionExecutor is responsible for executing a set of expressions and storing the result in a data chunk. More...

#include <duckdb.hpp>

Collaboration diagram for duckdb::ExpressionExecutor:

Public Member Functions

DUCKDB_API ExpressionExecutor (ClientContext &context)
DUCKDB_API ExpressionExecutor (ClientContext &context, const Expression *expression)
DUCKDB_API ExpressionExecutor (ClientContext &context, const Expression &expression)
DUCKDB_API ExpressionExecutor (ClientContext &context, const vector< unique_ptr< Expression > > &expressions)
 ExpressionExecutor (ExpressionExecutor &&)=delete
bool HasContext ()
ClientContext & GetContext ()
Allocator & GetAllocator ()
DUCKDB_API void AddExpression (const Expression &expr)
 Add an expression to the set of to-be-executed expressions of the executor.
void ClearExpressions ()
DUCKDB_API void Execute (DataChunk *input, DataChunk &result)
 Execute the set of expressions with the given input chunk and store the result in the output chunk.
void Execute (DataChunk &input, DataChunk &result)
void Execute (DataChunk &result)
DUCKDB_API void ExecuteExpression (DataChunk &input, Vector &result)
 Execute the ExpressionExecutor and put the result in the result vector; this should only be used for expression executors with a single expression.
DUCKDB_API void ExecuteExpression (Vector &result)
 Execute the ExpressionExecutor and put the result in the result vector; this should only be used for expression executors with a single expression.
DUCKDB_API idx_t SelectExpression (DataChunk &input, SelectionVector &sel)
 Execute the ExpressionExecutor and generate a selection vector from all true values in the result; this should only be used with a single boolean expression.
DUCKDB_API idx_t SelectExpression (DataChunk &input, SelectionVector &result_sel, optional_ptr< SelectionVector > current_sel, idx_t current_count)
DUCKDB_API idx_t SelectExpression (DataChunk &input, optional_ptr< SelectionVector > true_sel, optional_ptr< SelectionVector > false_sel, optional_ptr< SelectionVector > current_sel, idx_t current_count)
DUCKDB_API void ExecuteExpression (idx_t expr_idx, Vector &result)
 Execute the expression with index expr_idx and store the result in the result vector.
void SetChunk (DataChunk *chunk)
void SetChunk (DataChunk &chunk)
DUCKDB_API vector< unique_ptr< ExpressionExecutorState > > & GetStates ()

Static Public Member Functions

static DUCKDB_API Value EvaluateScalar (ClientContext &context, const Expression &expr, bool allow_unfoldable=false)
 Evaluate a scalar expression and fold it into a single value.
static DUCKDB_API bool TryEvaluateScalar (ClientContext &context, const Expression &expr, Value &result)
 Try to evaluate a scalar expression and fold it into a single value, returns false if an exception is thrown.
static unique_ptr< ExpressionState > InitializeState (const Expression &expr, ExpressionExecutorState &state)
 Initialize the state of a given expression.

Public Attributes

vector< const Expression * > expressions
 The expressions of the executor.
DataChunk * chunk = nullptr
 The data chunk of the current physical operator, used to resolve column references and determines the output cardinality.

Protected Member Functions

void Initialize (const Expression &expr, ExpressionExecutorState &state)
void Execute (const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
void Execute (const BoundBetweenExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
void Execute (const BoundCaseExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
void Execute (const BoundCastExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
void Execute (const BoundComparisonExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
void Execute (const BoundConjunctionExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
void Execute (const BoundConstantExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
void Execute (const BoundFunctionExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
void Execute (const BoundOperatorExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
void Execute (const BoundParameterExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
void Execute (const BoundReferenceExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, Vector &result)
idx_t Select (const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, SelectionVector *true_sel, SelectionVector *false_sel)
 Execute the (boolean-returning) expression and generate a selection vector with all entries that are "true" in the result.
idx_t DefaultSelect (const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, SelectionVector *true_sel, SelectionVector *false_sel)
idx_t Select (const BoundBetweenExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, SelectionVector *true_sel, SelectionVector *false_sel)
idx_t Select (const BoundComparisonExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, SelectionVector *true_sel, SelectionVector *false_sel)
idx_t Select (const BoundConjunctionExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, SelectionVector *true_sel, SelectionVector *false_sel)
void Verify (const Expression &expr, Vector &result, idx_t count)
 Verify that the output of a step in the ExpressionExecutor is correct.
void FillSwitch (Vector &vector, Vector &result, const SelectionVector &sel, sel_t count)

Static Protected Member Functions

static unique_ptr< ExpressionState > InitializeState (const BoundReferenceExpression &expr, ExpressionExecutorState &state)
static unique_ptr< ExpressionState > InitializeState (const BoundBetweenExpression &expr, ExpressionExecutorState &state)
static unique_ptr< ExpressionState > InitializeState (const BoundCaseExpression &expr, ExpressionExecutorState &state)
static unique_ptr< ExpressionState > InitializeState (const BoundCastExpression &expr, ExpressionExecutorState &state)
static unique_ptr< ExpressionState > InitializeState (const BoundComparisonExpression &expr, ExpressionExecutorState &state)
static unique_ptr< ExpressionState > InitializeState (const BoundConjunctionExpression &expr, ExpressionExecutorState &state)
static unique_ptr< ExpressionState > InitializeState (const BoundConstantExpression &expr, ExpressionExecutorState &state)
static unique_ptr< ExpressionState > InitializeState (const BoundFunctionExpression &expr, ExpressionExecutorState &state)
static unique_ptr< ExpressionState > InitializeState (const BoundOperatorExpression &expr, ExpressionExecutorState &state)
static unique_ptr< ExpressionState > InitializeState (const BoundParameterExpression &expr, ExpressionExecutorState &state)

Private Member Functions

DUCKDB_API ExpressionExecutor (const vector< unique_ptr< Expression > > &exprs)

Private Attributes

optional_ptr< ClientContext > context
 Client context.
vector< unique_ptr< ExpressionExecutorState > > states
 The states of the expression executor; this holds any intermediates and temporary states of expressions.
DebugVectorVerification debug_vector_verification = DebugVectorVerification::NONE
 The vector verification (debug setting).

Friends

class BoundIndex

Detailed Description

ExpressionExecutor is responsible for executing a set of expressions and storing the result in a data chunk.

Constructor & Destructor Documentation

◆ ExpressionExecutor() [1/6]

duckdb::ExpressionExecutor::ExpressionExecutor ( ClientContext & context)
explicit
149879 : context(&context) {
149880 debug_vector_verification = Settings::Get<DebugVerifyVectorSetting>(context);
149881}
DebugVectorVerification debug_vector_verification
The vector verification (debug setting).
Definition duckdb.hpp:47311
optional_ptr< ClientContext > context
Client context.
Definition duckdb.hpp:47307

◆ ExpressionExecutor() [2/6]

duckdb::ExpressionExecutor::ExpressionExecutor ( ClientContext & context,
const Expression * expression )
149884 : ExpressionExecutor(context) {
149885 D_ASSERT(expression);
149886 AddExpression(*expression);
149887}
DUCKDB_API void AddExpression(const Expression &expr)
Add an expression to the set of to-be-executed expressions of the executor.
Definition duckdb.cpp:149927

◆ ExpressionExecutor() [3/6]

duckdb::ExpressionExecutor::ExpressionExecutor ( ClientContext & context,
const Expression & expression )
149890 : ExpressionExecutor(context) {
149891 AddExpression(expression);
149892}

◆ ExpressionExecutor() [4/6]

duckdb::ExpressionExecutor::ExpressionExecutor ( ClientContext & context,
const vector< unique_ptr< Expression > > & expressions )
149895 : ExpressionExecutor(context) {
149896 D_ASSERT(exprs.size() > 0);
149897 for (auto &expr : exprs) {
149898 AddExpression(*expr);
149899 }
149900}

◆ ExpressionExecutor() [5/6]

duckdb::ExpressionExecutor::ExpressionExecutor ( )
private
149909 : context(nullptr) {
149910}

◆ ExpressionExecutor() [6/6]

duckdb::ExpressionExecutor::ExpressionExecutor ( const vector< unique_ptr< Expression > > & exprs)
explicitprivate
149902 : context(nullptr) {
149903 D_ASSERT(exprs.size() > 0);
149904 for (auto &expr : exprs) {
149905 AddExpression(*expr);
149906 }
149907}

Member Function Documentation

◆ HasContext()

bool duckdb::ExpressionExecutor::HasContext ( )
149912 {
149913 return context;
149914}

◆ GetContext()

ClientContext & duckdb::ExpressionExecutor::GetContext ( )
149916 {
149917 if (!context) {
149918 throw InternalException("Calling ExpressionExecutor::GetContext on an expression executor without a context");
149919 }
149920 return *context;
149921}

◆ GetAllocator()

Allocator & duckdb::ExpressionExecutor::GetAllocator ( )
149923 {
149924 return context ? Allocator::Get(*context) : Allocator::DefaultAllocator();
149925}

◆ AddExpression()

void duckdb::ExpressionExecutor::AddExpression ( const Expression & expr)

Add an expression to the set of to-be-executed expressions of the executor.

149927 {
149928 expressions.push_back(&expr);
149929 auto state = make_uniq<ExpressionExecutorState>();
149930 Initialize(expr, *state);
149931 state->Verify();
149932 states.push_back(std::move(state));
149933}
vector< unique_ptr< ExpressionExecutorState > > states
The states of the expression executor; this holds any intermediates and temporary states of expressio...
Definition duckdb.hpp:47309
vector< const Expression * > expressions
The expressions of the executor.
Definition duckdb.hpp:47179
Here is the caller graph for this function:

◆ ClearExpressions()

void duckdb::ExpressionExecutor::ClearExpressions ( )
149935 {
149936 states.clear();
149937 expressions.clear();
149938}

◆ Execute() [1/14]

void duckdb::ExpressionExecutor::Execute ( DataChunk * input,
DataChunk & result )

Execute the set of expressions with the given input chunk and store the result in the output chunk.

149945 {
149946 SetChunk(input);
149947 D_ASSERT(expressions.size() == result.ColumnCount());
149948 D_ASSERT(!expressions.empty());
149949
149950 for (idx_t i = 0; i < expressions.size(); i++) {
149951 ExecuteExpression(i, result.data[i]);
149952 }
149953 result.SetCardinality(input ? input->size() : 1);
149954 result.Verify();
149955}
DUCKDB_API void ExecuteExpression(DataChunk &input, Vector &result)
Execute the ExpressionExecutor and put the result in the result vector; this should only be used for ...
Definition duckdb.cpp:149957
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Execute() [2/14]

void duckdb::ExpressionExecutor::Execute ( DataChunk & input,
DataChunk & result )
inline
47195 {
47196 Execute(&input, result);
47197 }
DUCKDB_API void Execute(DataChunk *input, DataChunk &result)
Execute the set of expressions with the given input chunk and store the result in the output chunk.
Definition duckdb.cpp:149945

◆ Execute() [3/14]

void duckdb::ExpressionExecutor::Execute ( DataChunk & result)
inline
47198 {
47199 Execute(nullptr, result);
47200 }

◆ ExecuteExpression() [1/3]

void duckdb::ExpressionExecutor::ExecuteExpression ( DataChunk & input,
Vector & result )

Execute the ExpressionExecutor and put the result in the result vector; this should only be used for expression executors with a single expression.

149957 {
149958 SetChunk(&input);
149959 ExecuteExpression(result);
149960}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExecuteExpression() [2/3]

void duckdb::ExpressionExecutor::ExecuteExpression ( Vector & result)

Execute the ExpressionExecutor and put the result in the result vector; this should only be used for expression executors with a single expression.

149982 {
149983 D_ASSERT(expressions.size() == 1);
149984 ExecuteExpression(0, result);
149985}
Here is the call graph for this function:

◆ SelectExpression() [1/3]

idx_t duckdb::ExpressionExecutor::SelectExpression ( DataChunk & input,
SelectionVector & sel )

Execute the ExpressionExecutor and generate a selection vector from all true values in the result; this should only be used with a single boolean expression.

149962 {
149963 return SelectExpression(input, sel, nullptr, input.size());
149964}
DUCKDB_API idx_t SelectExpression(DataChunk &input, SelectionVector &sel)
Execute the ExpressionExecutor and generate a selection vector from all true values in the result; th...
Definition duckdb.cpp:149962
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SelectExpression() [2/3]

idx_t duckdb::ExpressionExecutor::SelectExpression ( DataChunk & input,
SelectionVector & result_sel,
optional_ptr< SelectionVector > current_sel,
idx_t current_count )
149967 {
149968 return SelectExpression(input, result_sel, nullptr, current_sel, current_count);
149969}

◆ SelectExpression() [3/3]

idx_t duckdb::ExpressionExecutor::SelectExpression ( DataChunk & input,
optional_ptr< SelectionVector > true_sel,
optional_ptr< SelectionVector > false_sel,
optional_ptr< SelectionVector > current_sel,
idx_t current_count )
149973 {
149974 D_ASSERT(expressions.size() == 1);
149975 D_ASSERT(current_count <= input.size());
149976 SetChunk(&input);
149977 idx_t selected_tuples = Select(*expressions[0], states[0]->root_state.get(), current_sel.get(), current_count,
149978 true_sel.get(), false_sel.get());
149979 return selected_tuples;
149980}
idx_t Select(const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count, SelectionVector *true_sel, SelectionVector *false_sel)
Execute the (boolean-returning) expression and generate a selection vector with all entries that are ...
Definition duckdb.cpp:150153

◆ ExecuteExpression() [3/3]

void duckdb::ExpressionExecutor::ExecuteExpression ( idx_t expr_idx,
Vector & result )

Execute the expression with index expr_idx and store the result in the result vector.

149987 {
149988 D_ASSERT(expr_idx < expressions.size());
149989 D_ASSERT(result.GetType().id() == expressions[expr_idx]->return_type.id());
149990 Execute(*expressions[expr_idx], states[expr_idx]->root_state.get(), nullptr, chunk ? chunk->size() : 1, result);
149991}
DataChunk * chunk
The data chunk of the current physical operator, used to resolve column references and determines the...
Definition duckdb.hpp:47182
Here is the call graph for this function:

◆ EvaluateScalar()

Value duckdb::ExpressionExecutor::EvaluateScalar ( ClientContext & context,
const Expression & expr,
bool allow_unfoldable = false )
static

Evaluate a scalar expression and fold it into a single value.

149993 {
149994 D_ASSERT(allow_unfoldable || expr.IsFoldable());
149995 D_ASSERT(expr.IsScalar());
149996 // use an ExpressionExecutor to execute the expression
149997 ExpressionExecutor executor(context, expr);
149998
149999 Vector result(expr.return_type);
150000 executor.ExecuteExpression(result);
150001
150002 D_ASSERT(allow_unfoldable || result.GetVectorType() == VectorType::CONSTANT_VECTOR);
150003 auto result_value = result.GetValue(0);
150004 D_ASSERT(result_value.type().InternalType() == expr.return_type.InternalType());
150005 return result_value;
150006}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryEvaluateScalar()

bool duckdb::ExpressionExecutor::TryEvaluateScalar ( ClientContext & context,
const Expression & expr,
Value & result )
static

Try to evaluate a scalar expression and fold it into a single value, returns false if an exception is thrown.

150008 {
150009 try {
150010 result = EvaluateScalar(context, expr);
150011 return true;
150012 } catch (InternalException &ex) {
150013 throw;
150014 } catch (...) {
150015 return false;
150016 }
150017}
static DUCKDB_API Value EvaluateScalar(ClientContext &context, const Expression &expr, bool allow_unfoldable=false)
Evaluate a scalar expression and fold it into a single value.
Definition duckdb.cpp:149993
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeState() [1/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const Expression & expr,
ExpressionExecutorState & state )
static

Initialize the state of a given expression.

150066 {
150067 switch (expr.GetExpressionClass()) {
150068 case ExpressionClass::BOUND_REF:
150069 return InitializeState(expr.Cast<BoundReferenceExpression>(), state);
150070 case ExpressionClass::BOUND_BETWEEN:
150071 return InitializeState(expr.Cast<BoundBetweenExpression>(), state);
150072 case ExpressionClass::BOUND_CASE:
150073 return InitializeState(expr.Cast<BoundCaseExpression>(), state);
150074 case ExpressionClass::BOUND_CAST:
150075 return InitializeState(expr.Cast<BoundCastExpression>(), state);
150076 case ExpressionClass::BOUND_COMPARISON:
150077 return InitializeState(expr.Cast<BoundComparisonExpression>(), state);
150078 case ExpressionClass::BOUND_CONJUNCTION:
150079 return InitializeState(expr.Cast<BoundConjunctionExpression>(), state);
150080 case ExpressionClass::BOUND_CONSTANT:
150081 return InitializeState(expr.Cast<BoundConstantExpression>(), state);
150082 case ExpressionClass::BOUND_FUNCTION:
150083 return InitializeState(expr.Cast<BoundFunctionExpression>(), state);
150084 case ExpressionClass::BOUND_OPERATOR:
150085 return InitializeState(expr.Cast<BoundOperatorExpression>(), state);
150086 case ExpressionClass::BOUND_PARAMETER:
150087 return InitializeState(expr.Cast<BoundParameterExpression>(), state);
150088 default:
150089 throw InternalException("Attempting to initialize state of expression of unknown type!");
150090 }
150091}
static unique_ptr< ExpressionState > InitializeState(const Expression &expr, ExpressionExecutorState &state)
Initialize the state of a given expression.
Definition duckdb.cpp:150065
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetChunk() [1/2]

void duckdb::ExpressionExecutor::SetChunk ( DataChunk * chunk)
inline
47230 {
47231 this->chunk = chunk;
47232 }

◆ SetChunk() [2/2]

void duckdb::ExpressionExecutor::SetChunk ( DataChunk & chunk)
inline
47233 {
47234 SetChunk(&chunk);
47235 }

◆ GetStates()

vector< unique_ptr< ExpressionExecutorState > > & duckdb::ExpressionExecutor::GetStates ( )
150237 {
150238 return states;
150239}

◆ Initialize()

void duckdb::ExpressionExecutor::Initialize ( const Expression & expr,
ExpressionExecutorState & state )
protected
149940 {
149941 state.executor = this;
149942 state.root_state = InitializeState(expression, state);
149943}

◆ InitializeState() [2/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const BoundReferenceExpression & expr,
ExpressionExecutorState & state )
staticprotected
149511 {
149512 auto result = make_uniq<ExpressionState>(expr, root);
149513 result->Finalize();
149514 return result;
149515}

◆ InitializeState() [3/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const BoundBetweenExpression & expr,
ExpressionExecutorState & state )
staticprotected
148065 {
148066 auto result = make_uniq<ExpressionState>(expr, root);
148067 result->AddChild(*expr.input);
148068 result->AddChild(*expr.lower);
148069 result->AddChild(*expr.upper);
148070
148071 result->Finalize();
148072 return result;
148073}

◆ InitializeState() [4/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const BoundCaseExpression & expr,
ExpressionExecutorState & state )
staticprotected
148199 {
148200 auto result = make_uniq<CaseExpressionState>(expr, root);
148201 for (auto &case_check : expr.case_checks) {
148202 result->AddChild(*case_check.when_expr);
148203 result->AddChild(*case_check.then_expr);
148204 }
148205 result->AddChild(*expr.else_expr);
148206
148207 result->Finalize();
148208 return std::move(result);
148209}

◆ InitializeState() [5/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const BoundCastExpression & expr,
ExpressionExecutorState & state )
staticprotected
148416 {
148417 auto result = make_uniq<ExecuteFunctionState>(expr, root);
148418 result->AddChild(*expr.child);
148419 result->Finalize();
148420
148421 if (expr.bound_cast.init_local_state) {
148422 auto context_ptr = root.executor->HasContext() ? &root.executor->GetContext() : nullptr;
148423 CastLocalStateParameters parameters(context_ptr, expr.bound_cast.cast_data);
148424 result->local_state = expr.bound_cast.init_local_state(parameters);
148425 }
148426 return std::move(result);
148427}

◆ InitializeState() [6/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const BoundComparisonExpression & expr,
ExpressionExecutorState & state )
staticprotected
148463 {
148464 auto result = make_uniq<ExpressionState>(expr, root);
148465 result->AddChild(*expr.left);
148466 result->AddChild(*expr.right);
148467
148468 result->Finalize();
148469 return result;
148470}

◆ InitializeState() [7/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const BoundConjunctionExpression & expr,
ExpressionExecutorState & state )
staticprotected
148860 {
148861 auto result = make_uniq<ConjunctionState>(expr, root);
148862 for (auto &child : expr.children) {
148863 result->AddChild(*child);
148864 }
148865
148866 result->Finalize();
148867 return std::move(result);
148868}

◆ InitializeState() [8/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const BoundConstantExpression & expr,
ExpressionExecutorState & state )
staticprotected
148993 {
148994 auto result = make_uniq<ExpressionState>(expr, root);
148995 result->Finalize();
148996 return result;
148997}

◆ InitializeState() [9/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const BoundFunctionExpression & expr,
ExpressionExecutorState & state )
staticprotected
149135 {
149136 auto result = make_uniq<ExecuteFunctionState>(expr, root);
149137 for (auto &child : expr.children) {
149138 result->AddChild(*child);
149139 }
149140
149141 result->Finalize();
149142 if (expr.function.HasInitStateCallback()) {
149143 result->local_state = expr.function.GetInitStateCallback()(*result, expr, expr.bind_info.get());
149144 }
149145 return std::move(result);
149146}

◆ InitializeState() [10/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const BoundOperatorExpression & expr,
ExpressionExecutorState & state )
staticprotected
149251 {
149252 auto result = make_uniq<ExpressionState>(expr, root);
149253 for (auto &child : expr.children) {
149254 result->AddChild(*child);
149255 }
149256
149257 result->Finalize();
149258 return result;
149259}

◆ InitializeState() [11/11]

unique_ptr< ExpressionState > duckdb::ExpressionExecutor::InitializeState ( const BoundParameterExpression & expr,
ExpressionExecutorState & state )
staticprotected
149490 {
149491 auto result = make_uniq<ExpressionState>(expr, root);
149492 result->Finalize();
149493 return result;
149494}

◆ Execute() [4/14]

void duckdb::ExpressionExecutor::Execute ( const Expression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
150094 {
150095#ifdef DEBUG
150096 // The result vector must be used for the first time, or must be reset.
150097 // Otherwise, the validity mask can contain previous (now incorrect) data.
150098 if (result.GetVectorType() == VectorType::FLAT_VECTOR) {
150099 // We do not initialize vector caches for these expressions.
150100 if (expr.GetExpressionClass() != ExpressionClass::BOUND_REF &&
150101 expr.GetExpressionClass() != ExpressionClass::BOUND_CONSTANT &&
150102 expr.GetExpressionClass() != ExpressionClass::BOUND_PARAMETER) {
150103 D_ASSERT(FlatVector::Validity(result).CheckAllValid(count));
150104 }
150105 }
150106#endif
150107
150108 if (count == 0) {
150109 return;
150110 }
150111 if (result.GetType().id() != expr.return_type.id()) {
150112 throw InternalException(
150113 "ExpressionExecutor::Execute called with a result vector of type %s that does not match expression type %s",
150114 result.GetType(), expr.return_type);
150115 }
150116 switch (expr.GetExpressionClass()) {
150117 case ExpressionClass::BOUND_BETWEEN:
150118 Execute(expr.Cast<BoundBetweenExpression>(), state, sel, count, result);
150119 break;
150120 case ExpressionClass::BOUND_REF:
150121 Execute(expr.Cast<BoundReferenceExpression>(), state, sel, count, result);
150122 break;
150123 case ExpressionClass::BOUND_CASE:
150124 Execute(expr.Cast<BoundCaseExpression>(), state, sel, count, result);
150125 break;
150126 case ExpressionClass::BOUND_CAST:
150127 Execute(expr.Cast<BoundCastExpression>(), state, sel, count, result);
150128 break;
150129 case ExpressionClass::BOUND_COMPARISON:
150130 Execute(expr.Cast<BoundComparisonExpression>(), state, sel, count, result);
150131 break;
150132 case ExpressionClass::BOUND_CONJUNCTION:
150133 Execute(expr.Cast<BoundConjunctionExpression>(), state, sel, count, result);
150134 break;
150135 case ExpressionClass::BOUND_CONSTANT:
150136 Execute(expr.Cast<BoundConstantExpression>(), state, sel, count, result);
150137 break;
150138 case ExpressionClass::BOUND_FUNCTION:
150139 Execute(expr.Cast<BoundFunctionExpression>(), state, sel, count, result);
150140 break;
150141 case ExpressionClass::BOUND_OPERATOR:
150142 Execute(expr.Cast<BoundOperatorExpression>(), state, sel, count, result);
150143 break;
150144 case ExpressionClass::BOUND_PARAMETER:
150145 Execute(expr.Cast<BoundParameterExpression>(), state, sel, count, result);
150146 break;
150147 default:
150148 throw InternalException("Attempting to execute expression of unknown type!");
150149 }
150150 Verify(expr, result, count);
150151}
void Verify(const Expression &expr, Vector &result, idx_t count)
Verify that the output of a step in the ExpressionExecutor is correct.
Definition duckdb.cpp:150019

◆ Execute() [5/14]

void duckdb::ExpressionExecutor::Execute ( const BoundBetweenExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
148076 {
148077 // resolve the children
148078 state->intermediate_chunk.Reset();
148079
148080 auto &input = state->intermediate_chunk.data[0];
148081 auto &lower = state->intermediate_chunk.data[1];
148082 auto &upper = state->intermediate_chunk.data[2];
148083
148084 Execute(*expr.input, state->child_states[0].get(), sel, count, input);
148085 Execute(*expr.lower, state->child_states[1].get(), sel, count, lower);
148086 Execute(*expr.upper, state->child_states[2].get(), sel, count, upper);
148087
148088 Vector intermediate1(LogicalType::BOOLEAN);
148089 Vector intermediate2(LogicalType::BOOLEAN);
148090
148091 if (expr.upper_inclusive && expr.lower_inclusive) {
148092 VectorOperations::GreaterThanEquals(input, lower, intermediate1, count);
148093 VectorOperations::LessThanEquals(input, upper, intermediate2, count);
148094 } else if (expr.lower_inclusive) {
148095 VectorOperations::GreaterThanEquals(input, lower, intermediate1, count);
148096 VectorOperations::LessThan(input, upper, intermediate2, count);
148097 } else if (expr.upper_inclusive) {
148098 VectorOperations::GreaterThan(input, lower, intermediate1, count);
148099 VectorOperations::LessThanEquals(input, upper, intermediate2, count);
148100 } else {
148101 VectorOperations::GreaterThan(input, lower, intermediate1, count);
148102 VectorOperations::LessThan(input, upper, intermediate2, count);
148103 }
148104 VectorOperations::And(intermediate1, intermediate2, result, count);
148105}

◆ Execute() [6/14]

void duckdb::ExpressionExecutor::Execute ( const BoundCaseExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
148212 {
148213 auto &state = state_p->Cast<CaseExpressionState>();
148214
148215 state.intermediate_chunk.Reset();
148216
148217 // first execute the check expression
148218 auto current_true_sel = &state.true_sel;
148219 auto current_false_sel = &state.false_sel;
148220 auto current_sel = sel;
148221 idx_t current_count = count;
148222 for (idx_t i = 0; i < expr.case_checks.size(); i++) {
148223 auto &case_check = expr.case_checks[i];
148224 auto &intermediate_result = state.intermediate_chunk.data[i * 2 + 1];
148225 auto check_state = state.child_states[i * 2].get();
148226 auto then_state = state.child_states[i * 2 + 1].get();
148227
148228 idx_t tcount =
148229 Select(*case_check.when_expr, check_state, current_sel, current_count, current_true_sel, current_false_sel);
148230 if (tcount == 0) {
148231 // everything is false: do nothing
148232 continue;
148233 }
148234 idx_t fcount = current_count - tcount;
148235 if (fcount == 0 && current_count == count) {
148236 // everything is true in the first CHECK statement
148237 // we can skip the entire case and only execute the TRUE side
148238 Execute(*case_check.then_expr, then_state, sel, count, result);
148239 return;
148240 } else {
148241 // we need to execute and then fill in the desired tuples in the result
148242 Execute(*case_check.then_expr, then_state, current_true_sel, tcount, intermediate_result);
148243 FillSwitch(intermediate_result, result, *current_true_sel, NumericCast<sel_t>(tcount));
148244 }
148245 // continue with the false tuples
148246 current_sel = current_false_sel;
148247 current_count = fcount;
148248 if (fcount == 0) {
148249 // everything is true: we are done
148250 break;
148251 }
148252 }
148253 if (current_count > 0) {
148254 auto else_state = state.child_states.back().get();
148255 if (current_count == count) {
148256 // everything was false, we can just evaluate the else expression directly
148257 Execute(*expr.else_expr, else_state, sel, count, result);
148258 return;
148259 } else {
148260 auto &intermediate_result = state.intermediate_chunk.data[expr.case_checks.size() * 2];
148261
148262 D_ASSERT(current_sel);
148263 Execute(*expr.else_expr, else_state, current_sel, current_count, intermediate_result);
148264 FillSwitch(intermediate_result, result, *current_sel, NumericCast<sel_t>(current_count));
148265 }
148266 }
148267 if (sel) {
148268 result.Slice(*sel, count);
148269 }
148270}

◆ Execute() [7/14]

void duckdb::ExpressionExecutor::Execute ( const BoundCastExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
148430 {
148431 auto lstate = ExecuteFunctionState::GetFunctionState(*state);
148432
148433 // resolve the child
148434 state->intermediate_chunk.Reset();
148435
148436 auto &child = state->intermediate_chunk.data[0];
148437 auto child_state = state->child_states[0].get();
148438
148439 Execute(*expr.child, child_state, sel, count, child);
148440
148441 string error_message;
148442 auto error_ref = expr.try_cast ? &error_message : nullptr;
148443 CastParameters parameters(expr.bound_cast.cast_data.get(), false, error_ref, lstate);
148444 parameters.query_location = expr.GetQueryLocation();
148445 parameters.cast_source = expr.child.get();
148446 parameters.cast_target = expr;
148447 expr.bound_cast.function(child, result, count, parameters);
148448}

◆ Execute() [8/14]

void duckdb::ExpressionExecutor::Execute ( const BoundComparisonExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
148473 {
148474 // resolve the children
148475 state->intermediate_chunk.Reset();
148476 auto &left = state->intermediate_chunk.data[0];
148477 auto &right = state->intermediate_chunk.data[1];
148478
148479 Execute(*expr.left, state->child_states[0].get(), sel, count, left);
148480 Execute(*expr.right, state->child_states[1].get(), sel, count, right);
148481
148482 switch (expr.GetExpressionType()) {
148483 case ExpressionType::COMPARE_EQUAL:
148484 VectorOperations::Equals(left, right, result, count);
148485 break;
148486 case ExpressionType::COMPARE_NOTEQUAL:
148487 VectorOperations::NotEquals(left, right, result, count);
148488 break;
148489 case ExpressionType::COMPARE_LESSTHAN:
148490 VectorOperations::LessThan(left, right, result, count);
148491 break;
148492 case ExpressionType::COMPARE_GREATERTHAN:
148493 VectorOperations::GreaterThan(left, right, result, count);
148494 break;
148495 case ExpressionType::COMPARE_LESSTHANOREQUALTO:
148496 VectorOperations::LessThanEquals(left, right, result, count);
148497 break;
148498 case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
148499 VectorOperations::GreaterThanEquals(left, right, result, count);
148500 break;
148501 case ExpressionType::COMPARE_DISTINCT_FROM:
148502 VectorOperations::DistinctFrom(left, right, result, count);
148503 break;
148504 case ExpressionType::COMPARE_NOT_DISTINCT_FROM:
148505 VectorOperations::NotDistinctFrom(left, right, result, count);
148506 break;
148507 default:
148508 throw InternalException("Unknown comparison type!");
148509 }
148510}

◆ Execute() [9/14]

void duckdb::ExpressionExecutor::Execute ( const BoundConjunctionExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
148871 {
148872 // execute the children
148873 state->intermediate_chunk.Reset();
148874 for (idx_t i = 0; i < expr.children.size(); i++) {
148875 auto &current_result = state->intermediate_chunk.data[i];
148876 Execute(*expr.children[i], state->child_states[i].get(), sel, count, current_result);
148877 if (i == 0) {
148878 // move the result
148879 result.Reference(current_result);
148880 } else {
148881 Vector intermediate(LogicalType::BOOLEAN);
148882 // AND/OR together
148883 switch (expr.GetExpressionType()) {
148884 case ExpressionType::CONJUNCTION_AND:
148885 VectorOperations::And(current_result, result, intermediate, count);
148886 break;
148887 case ExpressionType::CONJUNCTION_OR:
148888 VectorOperations::Or(current_result, result, intermediate, count);
148889 break;
148890 default:
148891 throw InternalException("Unknown conjunction type!");
148892 }
148893 result.Reference(intermediate);
148894 }
148895 }
148896}

◆ Execute() [10/14]

void duckdb::ExpressionExecutor::Execute ( const BoundConstantExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
149000 {
149001 D_ASSERT(expr.value.type() == expr.return_type);
149002 result.Reference(expr.value);
149003}

◆ Execute() [11/14]

void duckdb::ExpressionExecutor::Execute ( const BoundFunctionExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
149182 {
149183 state->intermediate_chunk.Reset();
149184 auto &arguments = state->intermediate_chunk;
149185 if (!state->types.empty()) {
149186 for (idx_t i = 0; i < expr.children.size(); i++) {
149187 D_ASSERT(state->types[i] == expr.children[i]->return_type);
149188 Execute(*expr.children[i], state->child_states[i].get(), sel, count, arguments.data[i]);
149189#ifdef DEBUG
149190 if (expr.children[i]->return_type.id() == LogicalTypeId::VARCHAR) {
149191 arguments.data[i].UTFVerify(count);
149192 }
149193#endif
149194 }
149195 }
149196 arguments.SetCardinality(count);
149197 arguments.Verify();
149198
149199 D_ASSERT(expr.function.HasFunctionCallback());
149200 auto &execute_function_state = state->Cast<ExecuteFunctionState>();
149201 if (!execute_function_state.TryExecuteDictionaryExpression(expr, arguments, *state, result)) {
149202 expr.function.GetFunctionCallback()(arguments, *state, result);
149203 }
149204
149205 VerifyNullHandling(expr, arguments, result);
149206 D_ASSERT(result.GetType() == expr.return_type);
149207}

◆ Execute() [12/14]

void duckdb::ExpressionExecutor::Execute ( const BoundOperatorExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
149262 {
149263 // special handling for special snowflake 'IN'
149264 // IN has n children
149265 auto expression_type = expr.GetExpressionType();
149266 if (expression_type == ExpressionType::COMPARE_IN || expression_type == ExpressionType::COMPARE_NOT_IN) {
149267 if (expr.children.size() < 2) {
149268 throw InvalidInputException("IN needs at least two children");
149269 }
149270
149271 Vector left(expr.children[0]->return_type);
149272 // eval left side
149273 Execute(*expr.children[0], state->child_states[0].get(), sel, count, left);
149274
149275 // init result to false
149276 Vector intermediate(LogicalType::BOOLEAN);
149277 Value false_val = Value::BOOLEAN(false);
149278 intermediate.Reference(false_val);
149279
149280 // in rhs is a list of constants
149281 // for every child, OR the result of the comparison with the left
149282 // to get the overall result.
149283 for (idx_t child = 1; child < expr.children.size(); child++) {
149284 Vector vector_to_check(expr.children[child]->return_type);
149285 Vector comp_res(LogicalType::BOOLEAN);
149286
149287 Execute(*expr.children[child], state->child_states[child].get(), sel, count, vector_to_check);
149288 VectorOperations::Equals(left, vector_to_check, comp_res, count);
149289
149290 if (child == 1) {
149291 // first child: move to result
149292 intermediate.Reference(comp_res);
149293 } else {
149294 // otherwise OR together
149295 Vector new_result(LogicalType::BOOLEAN, true, false);
149296 VectorOperations::Or(intermediate, comp_res, new_result, count);
149297 intermediate.Reference(new_result);
149298 }
149299 }
149300 if (expression_type == ExpressionType::COMPARE_NOT_IN) {
149301 // NOT IN: invert result
149302 VectorOperations::Not(intermediate, result, count);
149303 } else {
149304 // directly use the result
149305 result.Reference(intermediate);
149306 }
149307 } else if (expression_type == ExpressionType::OPERATOR_COALESCE) {
149308 SelectionVector sel_a(count);
149309 SelectionVector sel_b(count);
149310 SelectionVector slice_sel(count);
149311 SelectionVector result_sel(count);
149312 SelectionVector *next_sel = &sel_a;
149313 const SelectionVector *current_sel = sel;
149314 idx_t remaining_count = count;
149315 idx_t next_count;
149316 for (idx_t child = 0; child < expr.children.size(); child++) {
149317 Vector vector_to_check(expr.children[child]->return_type);
149318 Execute(*expr.children[child], state->child_states[child].get(), current_sel, remaining_count,
149319 vector_to_check);
149320
149321 UnifiedVectorFormat vdata;
149322 vector_to_check.ToUnifiedFormat(remaining_count, vdata);
149323
149324 idx_t result_count = 0;
149325 next_count = 0;
149326 for (idx_t i = 0; i < remaining_count; i++) {
149327 auto base_idx = current_sel ? current_sel->get_index(i) : i;
149328 auto idx = vdata.sel->get_index(i);
149329 if (vdata.validity.RowIsValid(idx)) {
149330 slice_sel.set_index(result_count, i);
149331 result_sel.set_index(result_count++, base_idx);
149332 } else {
149333 next_sel->set_index(next_count++, base_idx);
149334 }
149335 }
149336 if (result_count > 0) {
149337 vector_to_check.Slice(slice_sel, result_count);
149338 FillSwitch(vector_to_check, result, result_sel, NumericCast<sel_t>(result_count));
149339 }
149340 current_sel = next_sel;
149341 next_sel = next_sel == &sel_a ? &sel_b : &sel_a;
149342 remaining_count = next_count;
149343 if (next_count == 0) {
149344 break;
149345 }
149346 }
149347 if (remaining_count > 0) {
149348 for (idx_t i = 0; i < remaining_count; i++) {
149349 FlatVector::SetNull(result, current_sel->get_index(i), true);
149350 }
149351 }
149352 if (sel) {
149353 result.Slice(*sel, count);
149354 } else if (count == 1) {
149355 result.SetVectorType(VectorType::CONSTANT_VECTOR);
149356 }
149357 } else if (expression_type == ExpressionType::OPERATOR_TRY) {
149358 auto &child_state = *state->child_states[0];
149359 Vector try_result(result.GetType());
149360 try {
149361 Execute(*expr.children[0], &child_state, sel, count, try_result);
149362 if (try_result.GetVectorType() == VectorType::CONSTANT_VECTOR) {
149363 result.Reference(try_result);
149364 return;
149365 }
149366 VectorOperations::Copy(try_result, result, count, 0, 0);
149367 return;
149368 } catch (std::exception &ex) {
149369 ErrorData error(ex);
149370 auto error_type = error.Type();
149371 if (!Exception::IsExecutionError(error_type)) {
149372 throw;
149373 }
149374 }
149375
149376 // On error, evaluate per row
149377 SelectionVector selvec(1);
149378 DataChunk intermediate;
149379 intermediate.Initialize(GetAllocator(), {result.GetType()}, 1);
149380 for (idx_t i = 0; i < count; i++) {
149381 intermediate.Reset();
149382 intermediate.SetCardinality(1);
149383
149384 // Make sure to clear any dictionary states in the child expression, so that it actually
149385 // gets executed anew for every row
149386 child_state.ResetDictionaryStates();
149387
149388 selvec.set_index(0, sel ? sel->get_index(i) : i);
149389 Value val(result.GetType());
149390 try {
149391 Execute(*expr.children[0], &child_state, &selvec, 1, intermediate.data[0]);
149392 val = intermediate.GetValue(0, 0);
149393 } catch (std::exception &ex) {
149394 ErrorData error(ex);
149395 auto error_type = error.Type();
149396 if (!Exception::IsExecutionError(error_type)) {
149397 throw;
149398 }
149399 }
149400 result.SetValue(i, val);
149401 }
149402 if (count == 1) {
149403 result.SetVectorType(VectorType::CONSTANT_VECTOR);
149404 }
149405 } else if (expr.children.size() == 1) {
149406 state->intermediate_chunk.Reset();
149407 auto &child = state->intermediate_chunk.data[0];
149408
149409 Execute(*expr.children[0], state->child_states[0].get(), sel, count, child);
149410 switch (expr.GetExpressionType()) {
149411 case ExpressionType::OPERATOR_NOT: {
149412 VectorOperations::Not(child, result, count);
149413 break;
149414 }
149415 case ExpressionType::OPERATOR_IS_NULL: {
149416 VectorOperations::IsNull(child, result, count);
149417 break;
149418 }
149419 case ExpressionType::OPERATOR_IS_NOT_NULL: {
149420 VectorOperations::IsNotNull(child, result, count);
149421 break;
149422 }
149423 default:
149424 throw NotImplementedException("Unsupported operator type with 1 child!");
149425 }
149426 } else {
149427 throw NotImplementedException("operator");
149428 }
149429}
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
static DUCKDB_API bool IsExecutionError(ExceptionType type)
Whether this exception type can occur during execution of a query.
Definition duckdb.cpp:70769
static DUCKDB_API Value BOOLEAN(bool value)
Create a boolean Value from a specified value.
Definition duckdb.cpp:132118
static void IsNull(Vector &input, Vector &result, idx_t count)
result = IS NULL (input)
Definition duckdb.cpp:143320
static void IsNotNull(Vector &arg, Vector &result, idx_t count)
result = IS NOT NULL(input)
Definition duckdb.cpp:143316

◆ Execute() [13/14]

void duckdb::ExpressionExecutor::Execute ( const BoundParameterExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
149497 {
149498 D_ASSERT(expr.parameter_data);
149499 D_ASSERT(expr.parameter_data->return_type == expr.return_type);
149500 D_ASSERT(expr.parameter_data->GetValue().type() == expr.return_type);
149501 result.Reference(expr.parameter_data->GetValue());
149502}

◆ Execute() [14/14]

void duckdb::ExpressionExecutor::Execute ( const BoundReferenceExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
Vector & result )
protected
149518 {
149519 D_ASSERT(expr.index != DConstants::INVALID_INDEX);
149520 D_ASSERT(expr.index < chunk->ColumnCount());
149521
149522 if (sel) {
149523 result.Slice(chunk->data[expr.index], *sel, count);
149524 } else {
149525 result.Reference(chunk->data[expr.index]);
149526 }
149527}
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

◆ Select() [1/4]

idx_t duckdb::ExpressionExecutor::Select ( const Expression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
SelectionVector * true_sel,
SelectionVector * false_sel )
protected

Execute the (boolean-returning) expression and generate a selection vector with all entries that are "true" in the result.

150154 {
150155 if (count == 0) {
150156 return 0;
150157 }
150158 D_ASSERT(true_sel || false_sel);
150159 D_ASSERT(expr.return_type.id() == LogicalTypeId::BOOLEAN);
150160 switch (expr.GetExpressionClass()) {
150161#ifndef DUCKDB_SMALLER_BINARY
150162 case ExpressionClass::BOUND_BETWEEN:
150163 return Select(expr.Cast<BoundBetweenExpression>(), state, sel, count, true_sel, false_sel);
150164#endif
150165 case ExpressionClass::BOUND_COMPARISON:
150166 return Select(expr.Cast<BoundComparisonExpression>(), state, sel, count, true_sel, false_sel);
150167 case ExpressionClass::BOUND_CONJUNCTION:
150168 return Select(expr.Cast<BoundConjunctionExpression>(), state, sel, count, true_sel, false_sel);
150169 default:
150170 return DefaultSelect(expr, state, sel, count, true_sel, false_sel);
150171 }
150172}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DefaultSelect()

idx_t duckdb::ExpressionExecutor::DefaultSelect ( const Expression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
SelectionVector * true_sel,
SelectionVector * false_sel )
protected
150216 {
150217 // generic selection of boolean expression:
150218 // resolve the true/false expression first
150219 // then use that to generate the selection vector
150220 bool intermediate_bools[STANDARD_VECTOR_SIZE];
150221 Vector intermediate(LogicalType::BOOLEAN, data_ptr_cast(intermediate_bools));
150222 Execute(expr, state, sel, count, intermediate);
150223
150224 UnifiedVectorFormat idata;
150225 intermediate.ToUnifiedFormat(count, idata);
150226
150227 if (!sel) {
150228 sel = FlatVector::IncrementalSelectionVector();
150229 }
150230 if (!idata.validity.AllValid()) {
150231 return DefaultSelectSwitch<false>(idata, sel, count, true_sel, false_sel);
150232 } else {
150233 return DefaultSelectSwitch<true>(idata, sel, count, true_sel, false_sel);
150234 }
150235}

◆ Select() [2/4]

idx_t duckdb::ExpressionExecutor::Select ( const BoundBetweenExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
SelectionVector * true_sel,
SelectionVector * false_sel )
protected
148108 {
148109#ifdef DUCKDB_SMALLER_BINARY
148110 throw InternalException("ExpressionExecutor::Select not available with DUCKDB_SMALLER_BINARY");
148111#else
148112 // resolve the children
148113 Vector input(state->intermediate_chunk.data[0]);
148114 Vector lower(state->intermediate_chunk.data[1]);
148115 Vector upper(state->intermediate_chunk.data[2]);
148116
148117 Execute(*expr.input, state->child_states[0].get(), sel, count, input);
148118 Execute(*expr.lower, state->child_states[1].get(), sel, count, lower);
148119 Execute(*expr.upper, state->child_states[2].get(), sel, count, upper);
148120
148121 if (expr.upper_inclusive && expr.lower_inclusive) {
148122 return BetweenLoopTypeSwitch<BothInclusiveBetweenOperator>(input, lower, upper, sel, count, true_sel,
148123 false_sel);
148124 } else if (expr.lower_inclusive) {
148125 return BetweenLoopTypeSwitch<LowerInclusiveBetweenOperator>(input, lower, upper, sel, count, true_sel,
148126 false_sel);
148127 } else if (expr.upper_inclusive) {
148128 return BetweenLoopTypeSwitch<UpperInclusiveBetweenOperator>(input, lower, upper, sel, count, true_sel,
148129 false_sel);
148130 } else {
148131 return BetweenLoopTypeSwitch<ExclusiveBetweenOperator>(input, lower, upper, sel, count, true_sel, false_sel);
148132 }
148133#endif
148134}

◆ Select() [3/4]

idx_t duckdb::ExpressionExecutor::Select ( const BoundComparisonExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
SelectionVector * true_sel,
SelectionVector * false_sel )
protected
148811 {
148812 // resolve the children
148813 state->intermediate_chunk.Reset();
148814 auto &left = state->intermediate_chunk.data[0];
148815 auto &right = state->intermediate_chunk.data[1];
148816
148817 Execute(*expr.left, state->child_states[0].get(), sel, count, left);
148818 Execute(*expr.right, state->child_states[1].get(), sel, count, right);
148819
148820 switch (expr.GetExpressionType()) {
148821 case ExpressionType::COMPARE_EQUAL:
148822 return VectorOperations::Equals(left, right, sel, count, true_sel, false_sel);
148823 case ExpressionType::COMPARE_NOTEQUAL:
148824 return VectorOperations::NotEquals(left, right, sel, count, true_sel, false_sel);
148825 case ExpressionType::COMPARE_LESSTHAN:
148826 return VectorOperations::LessThan(left, right, sel, count, true_sel, false_sel);
148827 case ExpressionType::COMPARE_GREATERTHAN:
148828 return VectorOperations::GreaterThan(left, right, sel, count, true_sel, false_sel);
148829 case ExpressionType::COMPARE_LESSTHANOREQUALTO:
148830 return VectorOperations::LessThanEquals(left, right, sel, count, true_sel, false_sel);
148831 case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
148832 return VectorOperations::GreaterThanEquals(left, right, sel, count, true_sel, false_sel);
148833 case ExpressionType::COMPARE_DISTINCT_FROM:
148834 return VectorOperations::DistinctFrom(left, right, sel, count, true_sel, false_sel);
148835 case ExpressionType::COMPARE_NOT_DISTINCT_FROM:
148836 return VectorOperations::NotDistinctFrom(left, right, sel, count, true_sel, false_sel);
148837 default:
148838 throw InternalException("Unknown comparison type!");
148839 }
148840}

◆ Select() [4/4]

idx_t duckdb::ExpressionExecutor::Select ( const BoundConjunctionExpression & expr,
ExpressionState * state,
const SelectionVector * sel,
idx_t count,
SelectionVector * true_sel,
SelectionVector * false_sel )
protected
148900 {
148901 auto &state = state_p->Cast<ConjunctionState>();
148902
148903 if (expr.GetExpressionType() == ExpressionType::CONJUNCTION_AND) {
148904 // get runtime statistics
148905 auto filter_state = state.adaptive_filter->BeginFilter();
148906 const SelectionVector *current_sel = sel;
148907 idx_t current_count = count;
148908 idx_t false_count = 0;
148909
148910 unique_ptr<SelectionVector> temp_true, temp_false;
148911 if (false_sel) {
148912 temp_false = make_uniq<SelectionVector>(STANDARD_VECTOR_SIZE);
148913 }
148914 if (!true_sel) {
148915 temp_true = make_uniq<SelectionVector>(STANDARD_VECTOR_SIZE);
148916 true_sel = temp_true.get();
148917 }
148918 for (idx_t i = 0; i < expr.children.size(); i++) {
148919 idx_t tcount = Select(*expr.children[state.adaptive_filter->permutation[i]],
148920 state.child_states[state.adaptive_filter->permutation[i]].get(), current_sel,
148921 current_count, true_sel, temp_false.get());
148922 idx_t fcount = current_count - tcount;
148923 if (fcount > 0 && false_sel) {
148924 // move failing tuples into the false_sel
148925 // tuples passed, move them into the actual result vector
148926 for (idx_t i = 0; i < fcount; i++) {
148927 false_sel->set_index(false_count++, temp_false->get_index(i));
148928 }
148929 }
148930 current_count = tcount;
148931 if (current_count == 0) {
148932 break;
148933 }
148934 if (current_count < count) {
148935 // tuples were filtered out: move on to using the true_sel to only evaluate passing tuples in subsequent
148936 // iterations
148937 current_sel = true_sel;
148938 }
148939 }
148940 // adapt runtime statistics
148941 state.adaptive_filter->EndFilter(filter_state);
148942 return current_count;
148943 } else {
148944 // get runtime statistics
148945 auto filter_state = state.adaptive_filter->BeginFilter();
148946
148947 const SelectionVector *current_sel = sel;
148948 idx_t current_count = count;
148949 idx_t result_count = 0;
148950
148951 unique_ptr<SelectionVector> temp_true, temp_false;
148952 if (true_sel) {
148953 temp_true = make_uniq<SelectionVector>(STANDARD_VECTOR_SIZE);
148954 }
148955 if (!false_sel) {
148956 temp_false = make_uniq<SelectionVector>(STANDARD_VECTOR_SIZE);
148957 false_sel = temp_false.get();
148958 }
148959 for (idx_t i = 0; i < expr.children.size(); i++) {
148960 idx_t tcount = Select(*expr.children[state.adaptive_filter->permutation[i]],
148961 state.child_states[state.adaptive_filter->permutation[i]].get(), current_sel,
148962 current_count, temp_true.get(), false_sel);
148963 if (tcount > 0) {
148964 if (true_sel) {
148965 // tuples passed, move them into the actual result vector
148966 for (idx_t i = 0; i < tcount; i++) {
148967 true_sel->set_index(result_count++, temp_true->get_index(i));
148968 }
148969 }
148970 // now move on to check only the non-passing tuples
148971 current_count -= tcount;
148972 current_sel = false_sel;
148973 }
148974 }
148975 if (true_sel) {
148976 true_sel->Sort(result_count);
148977 }
148978
148979 // adapt runtime statistics
148980 state.adaptive_filter->EndFilter(filter_state);
148981 return result_count;
148982 }
148983}

◆ Verify()

void duckdb::ExpressionExecutor::Verify ( const Expression & expr,
Vector & result,
idx_t count )
protected

Verify that the output of a step in the ExpressionExecutor is correct.

First cast to VARIANT

FIXME: this is probably also where we want to test 'variant_normalize'

Then cast back into the original type

150019 {
150020 D_ASSERT(expr.return_type.id() == vector.GetType().id());
150021 vector.Verify(count);
150022 if (expr.verification_stats) {
150023 expr.verification_stats->Verify(vector, count);
150024 }
150025 if (debug_vector_verification == DebugVectorVerification::DICTIONARY_EXPRESSION) {
150026 Vector::DebugTransformToDictionary(vector, count);
150027 }
150028 if (debug_vector_verification == DebugVectorVerification::VARIANT_VECTOR) {
150029 if (TypeVisitor::Contains(vector.GetType(), [](const LogicalType &type) {
150030 if (type.IsJSONType() || type.id() == LogicalTypeId::VARIANT || type.id() == LogicalTypeId::UNION ||
150031 type.id() == LogicalTypeId::ENUM || type.id() == LogicalTypeId::AGGREGATE_STATE) {
150032 return true;
150033 }
150034 if (type.id() == LogicalTypeId::STRUCT && StructType::IsUnnamed(type)) {
150035 return true;
150036 }
150037 return false;
150038 })) {
150039 return;
150040 }
150041
150042 Vector intermediate(LogicalType::VARIANT(), true, false, count);
150043
150045 if (HasContext()) {
150046 VectorOperations::Cast(GetContext(), vector, intermediate, count, true);
150047 } else {
150048 VectorOperations::DefaultCast(vector, intermediate, count, true);
150049 }
150050 intermediate.Verify(count);
150052
150053 Vector result(vector.GetType(), true, false, count);
150055 if (HasContext()) {
150056 VectorOperations::Cast(GetContext(), intermediate, result, count, true);
150057 } else {
150058 VectorOperations::DefaultCast(intermediate, result, count, true);
150059 }
150060 vector.Reference(result);
150061 vector.Verify(count);
150062 }
150063}
static DUCKDB_API LogicalType VARIANT()
Definition duckdb.cpp:140950
static DUCKDB_API void Cast(ClientContext &context, Vector &source, Vector &result, idx_t count, bool strict=false)
Cast the data from the source type to the target type. Throws an exception if the cast fails.
Definition duckdb.cpp:143475
Here is the call graph for this function:

◆ FillSwitch()

void duckdb::ExpressionExecutor::FillSwitch ( Vector & vector,
Vector & result,
const SelectionVector & sel,
sel_t count )
protected
148326 {
148327 switch (result.GetType().InternalType()) {
148328 case PhysicalType::BOOL:
148329 case PhysicalType::INT8:
148330 TemplatedFillLoop<int8_t>(vector, result, sel, count);
148331 break;
148332 case PhysicalType::INT16:
148333 TemplatedFillLoop<int16_t>(vector, result, sel, count);
148334 break;
148335 case PhysicalType::INT32:
148336 TemplatedFillLoop<int32_t>(vector, result, sel, count);
148337 break;
148338 case PhysicalType::INT64:
148339 TemplatedFillLoop<int64_t>(vector, result, sel, count);
148340 break;
148341 case PhysicalType::UINT8:
148342 TemplatedFillLoop<uint8_t>(vector, result, sel, count);
148343 break;
148345 TemplatedFillLoop<uint16_t>(vector, result, sel, count);
148346 break;
148348 TemplatedFillLoop<uint32_t>(vector, result, sel, count);
148349 break;
148351 TemplatedFillLoop<uint64_t>(vector, result, sel, count);
148352 break;
148353 case PhysicalType::INT128:
148354 TemplatedFillLoop<hugeint_t>(vector, result, sel, count);
148355 break;
148356 case PhysicalType::UINT128:
148357 TemplatedFillLoop<uhugeint_t>(vector, result, sel, count);
148358 break;
148359 case PhysicalType::FLOAT:
148360 TemplatedFillLoop<float>(vector, result, sel, count);
148361 break;
148363 TemplatedFillLoop<double>(vector, result, sel, count);
148364 break;
148366 TemplatedFillLoop<interval_t>(vector, result, sel, count);
148367 break;
148369 TemplatedFillLoop<string_t>(vector, result, sel, count);
148370 StringVector::AddHeapReference(result, vector);
148371 break;
148372 case PhysicalType::STRUCT: {
148373 auto &vector_entries = StructVector::GetEntries(vector);
148374 auto &result_entries = StructVector::GetEntries(result);
148375 ValidityFillLoop(vector, result, sel, count);
148376 D_ASSERT(vector_entries.size() == result_entries.size());
148377 for (idx_t i = 0; i < vector_entries.size(); i++) {
148378 FillSwitch(*vector_entries[i], *result_entries[i], sel, count);
148379 }
148380 break;
148381 }
148382 case PhysicalType::LIST: {
148383 idx_t offset = ListVector::GetListSize(result);
148384 auto &list_child = ListVector::GetEntry(vector);
148385 ListVector::Append(result, list_child, ListVector::GetListSize(vector));
148386
148387 // all the false offsets need to be incremented by true_child.count
148388 TemplatedFillLoop<list_entry_t>(vector, result, sel, count);
148389 if (offset == 0) {
148390 break;
148391 }
148392
148393 auto result_data = FlatVector::GetData<list_entry_t>(result);
148394 for (idx_t i = 0; i < count; i++) {
148395 auto result_idx = sel.get_index(i);
148396 result_data[result_idx].offset += offset;
148397 }
148398
148399 Vector::Verify(result, sel, count);
148400 break;
148401 }
148402 default:
148403 throw NotImplementedException("Unimplemented type for case expression: %s", result.GetType().ToString());
148404 }
148405}
DUCKDB_API void Verify(idx_t count)
Definition duckdb.cpp:137589
@ UINT32
Unsigned 32-bit little-endian integer.
Definition duckdb.hpp:2758
@ INTERVAL
YEAR_MONTH or DAY_TIME interval in SQL style.
Definition duckdb.hpp:2806
@ LIST
A list of some logical data type.
Definition duckdb.hpp:2813
@ UINT16
Unsigned 16-bit little-endian integer.
Definition duckdb.hpp:2752
@ INT64
Signed 64-bit little-endian integer.
Definition duckdb.hpp:2767
@ INT16
Signed 16-bit little-endian integer.
Definition duckdb.hpp:2755
@ INT32
Signed 32-bit little-endian integer.
Definition duckdb.hpp:2761
@ UINT64
Unsigned 64-bit little-endian integer.
Definition duckdb.hpp:2764
@ BOOL
Boolean as 8 bit "bool" value.
Definition duckdb.hpp:2743
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
@ VARCHAR
DuckDB Extensions.
Definition duckdb.hpp:2847
@ FLOAT
4-byte floating point value
Definition duckdb.hpp:2773
@ UINT8
Unsigned 8-bit little-endian integer.
Definition duckdb.hpp:2746
@ INT8
Signed 8-bit little-endian integer.
Definition duckdb.hpp:2749
@ DOUBLE
8-byte floating point value
Definition duckdb.hpp:2776
static DUCKDB_API void Append(Vector &target, const Vector &source, idx_t source_size, idx_t source_offset=0)
Definition duckdb.cpp:138257
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of a list.
Definition duckdb.cpp:138203
static DUCKDB_API idx_t GetListSize(const Vector &vector)
Gets the total size of the underlying child-vector of a list.
Definition duckdb.cpp:138221
static DUCKDB_API void AddHeapReference(Vector &vector, Vector &other)
Add a reference from this vector to the string heap of the provided vector.
Definition duckdb.cpp:137962

The documentation for this class was generated from the following files: