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::MergeIntoGlobalState Class Reference
Inheritance diagram for duckdb::MergeIntoGlobalState:
Collaboration diagram for duckdb::MergeIntoGlobalState:

Public Member Functions

 MergeIntoGlobalState (ClientContext &context, const PhysicalMergeInto &op)
optional_ptr< DataChunk > ComputeActionInput (ClientContext &context, MergeIntoOperator &action, DataChunk &chunk, MergeIntoLocalState &local_state, MergeLocalExecutionState &local_action_state)
SinkResultType Sink (ExecutionContext &context, DataChunk &chunk, MergeIntoLocalState &local_state, OperatorSinkInput &input, MergeActionRange range, idx_t &index_in_match)
SinkCombineResultType Combine (ExecutionContext &context, MergeIntoLocalState &local_state, OperatorSinkCombineInput &input)
SinkFinalizeType Finalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input)
Public Member Functions inherited from duckdb::GlobalSinkState
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const
virtual idx_t MaxThreads (idx_t source_max_threads)
Public Member Functions inherited from duckdb::StateWithBlockableTasks
unique_lock< mutex > Lock ()
void PreventBlocking (const unique_lock< mutex > &guard)
bool BlockTask (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
 Add a task to 'blocked_tasks' before returning SourceResultType::BLOCKED (must hold the lock).
bool CanBlock (const unique_lock< mutex > &guard) const
bool UnblockTasks (const unique_lock< mutex > &guard)
 Unblock all tasks (must hold the lock).
SinkResultType BlockSink (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
SourceResultType BlockSource (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
void VerifyLock (const unique_lock< mutex > &guard) const

Public Attributes

const PhysicalMergeInto & op
idx_t finalize_idx = 0
vector< unique_ptr< GlobalSinkState > > sink_states
atomic< idx_t > merged_count
Public Attributes inherited from duckdb::GlobalSinkState
SinkFinalizeType state

Constructor & Destructor Documentation

◆ MergeIntoGlobalState()

duckdb::MergeIntoGlobalState::MergeIntoGlobalState ( ClientContext & context,
const PhysicalMergeInto & op )
inline
196448 : op(op) {
196449 for (auto &action : op.actions) {
196450 sink_states.push_back(action->op ? action->op->GetGlobalSinkState(context) : nullptr);
196451 }
196452 merged_count = 0;
196453 }

Member Function Documentation

◆ ComputeActionInput()

optional_ptr< DataChunk > duckdb::MergeIntoGlobalState::ComputeActionInput ( ClientContext & context,
MergeIntoOperator & action,
DataChunk & chunk,
MergeIntoLocalState & local_state,
MergeLocalExecutionState & local_action_state )
inline
196461 {
196462 auto &current_count = local_state.sink_state.current_count;
196463 auto &current_sel = local_state.sink_state.current_sel;
196464 auto &sliced_chunk = local_state.sink_state.sliced_chunk;
196465 auto &selected_sel = local_state.sink_state.selected_sel;
196466 auto &remaining_sel = local_state.sink_state.remaining_sel;
196467 if (current_count == 0) {
196468 return nullptr;
196469 }
196470 if (!sliced_chunk) {
196471 sliced_chunk = make_uniq<DataChunk>();
196472 sliced_chunk->Initialize(context, chunk.GetTypes());
196473 } else {
196474 sliced_chunk->Reset();
196475 }
196476 optional_ptr<DataChunk> result;
196477 if (action.condition) {
196478 // if we have a condition we need to evaluate it
196479 auto &executor = *local_action_state.condition_executor;
196480 idx_t match_count =
196481 executor.SelectExpression(chunk, selected_sel, remaining_sel, current_sel, current_count);
196482 if (match_count == 0) {
196483 // no matches - move to next action
196484 return nullptr;
196485 }
196486 // slice the chunk for this action with the matching sel
196487 sliced_chunk->Slice(chunk, selected_sel, match_count);
196488 result = sliced_chunk;
196489
196490 // for the next chunk - update the matches
196491 current_count = current_count - match_count;
196492 current_sel.Initialize(remaining_sel);
196493 } else if (current_count != chunk.size()) {
196494 // if we have previously processed rows - remove them
196495 sliced_chunk->Slice(chunk, current_sel, current_count);
196496 result = sliced_chunk;
196497 } else {
196498 result = chunk;
196499 }
196500 // if we have any expressions - execute them to generate the new input chunk
196501 if (!action.expressions.empty()) {
196502 auto &insert_chunk = local_action_state.insert_chunk;
196503 insert_chunk->Reset();
196504 local_action_state.insert_executor->Execute(*result, *insert_chunk);
196505 result = insert_chunk.get();
196506 }
196507 if (action.op) {
196508 local_state.merged_count += result->size();
196509 }
196510 return result;
196511 }
DUCKDB_API vector< LogicalType > GetTypes() const
Returns a list of types of the vectors of this data chunk.
Definition duckdb.cpp:116995
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Sink()

SinkResultType duckdb::MergeIntoGlobalState::Sink ( ExecutionContext & context,
DataChunk & chunk,
MergeIntoLocalState & local_state,
OperatorSinkInput & input,
MergeActionRange range,
idx_t & index_in_match )
inline
196514 {
196515 auto &input_chunk = local_state.sink_state.input_chunk;
196516 for (; range.start + index_in_match < range.end; index_in_match++) {
196517 idx_t i = range.start + index_in_match;
196518 auto &action = op.actions[i];
196519 auto &local_action_state = local_state.states[i];
196520 if (!input_chunk) {
196521 // first time processing this action - compute the input chunk
196522 input_chunk = ComputeActionInput(context.client, *action, chunk, local_state, local_action_state);
196523 if (!input_chunk) {
196524 // no data for this action - move to next action
196525 continue;
196526 }
196527 }
196528 // process the action
196529 if (!action->op) {
196530 if (action->action_type == MergeActionType::MERGE_ERROR) {
196531 // abort - generate an error message
196532 string merge_condition;
196533 merge_condition += MergeIntoStatement::ActionConditionToString(range.condition);
196534 if (action->condition) {
196535 merge_condition += " AND " + action->condition->ToString();
196536 }
196537 if (!action->expressions.empty()) {
196538 // if there are any user-provided error messages: add the first error message encountered
196539 merge_condition += ": " + input_chunk->data[0].GetValue(0).ToString();
196540 }
196541 throw ConstraintException("Merge error condition %s", merge_condition);
196542 }
196543 D_ASSERT(action->action_type == MergeActionType::MERGE_DO_NOTHING);
196544 input_chunk = nullptr;
196545 continue;
196546 }
196547 auto &gstate = sink_states[i];
196548 auto &lstate = *local_action_state.local_state;
196549 OperatorSinkInput sink_input {*gstate, lstate, input.interrupt_state};
196550 auto result = action->op->Sink(context, *input_chunk, sink_input);
196551 if (result == SinkResultType::BLOCKED) {
196552 return SinkResultType::BLOCKED;
196553 }
196554 // move to next action
196555 input_chunk = nullptr;
196556 }
196557 return SinkResultType::NEED_MORE_INPUT;
196558 }

◆ Combine()

SinkCombineResultType duckdb::MergeIntoGlobalState::Combine ( ExecutionContext & context,
MergeIntoLocalState & local_state,
OperatorSinkCombineInput & input )
inline
196561 {
196562 for (; local_state.combine_idx < local_state.states.size(); ++local_state.combine_idx) {
196563 auto &lstate = local_state.states[local_state.combine_idx];
196564 auto &gstate = sink_states[local_state.combine_idx];
196565 auto &action = op.actions[local_state.combine_idx];
196566 if (!action->op) {
196567 continue;
196568 }
196569 OperatorSinkCombineInput combine_input {*gstate, *lstate.local_state, input.interrupt_state};
196570 auto result = action->op->Combine(context, combine_input);
196571 if (result == SinkCombineResultType::BLOCKED) {
196572 return SinkCombineResultType::BLOCKED;
196573 }
196574 }
196575 return SinkCombineResultType::FINISHED;
196576 }

◆ Finalize()

SinkFinalizeType duckdb::MergeIntoGlobalState::Finalize ( Pipeline & pipeline,
Event & event,
ClientContext & context,
OperatorSinkFinalizeInput & input )
inline
196579 {
196580 for (; finalize_idx < sink_states.size(); ++finalize_idx) {
196581 auto &gstate = sink_states[finalize_idx];
196582 auto &action = op.actions[finalize_idx];
196583 if (!action->op) {
196584 continue;
196585 }
196586
196587 OperatorSinkFinalizeInput finalize_input {*gstate, input.interrupt_state};
196588 auto result = action->op->Finalize(pipeline, event, context, finalize_input);
196589 if (result == SinkFinalizeType::BLOCKED) {
196590 return SinkFinalizeType::BLOCKED;
196591 }
196592 }
196593 return SinkFinalizeType::READY;
196594 }

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