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

Public Member Functions

DUCKDB_API StreamQueryResult (StatementType statement_type, StatementProperties properties, vector< LogicalType > types, vector< string > names, ClientProperties client_properties, shared_ptr< BufferedData > buffered_data)
 Create a successful StreamQueryResult. StreamQueryResults should always be successful initially (it makes no sense to stream an error).
DUCKDB_API StreamQueryResult (ErrorData error)
DUCKDB_API void WaitForTask ()
 Reschedules the tasks that work on producing a result chunk, returning when at least one task can be executed.
DUCKDB_API StreamExecutionResult ExecuteTask ()
 Executes a single task within the final pipeline, returning whether or not a chunk is ready to be fetched.
DUCKDB_API string ToString () override
 Converts the QueryResult to a string.
DUCKDB_API unique_ptr< MaterializedQueryResult > Materialize ()
 Materializes the query result and turns it into a materialized query result.
DUCKDB_API bool IsOpen ()
DUCKDB_API void Close ()
 Closes the StreamQueryResult.
Public Member Functions inherited from duckdb::QueryResult
DUCKDB_API QueryResult (QueryResultType type, StatementType statement_type, StatementProperties properties, vector< LogicalType > types, vector< string > names, ClientProperties client_properties)
 Creates a successful query result with the specified names and types.
DUCKDB_API QueryResult (QueryResultType type, ErrorData error)
 Creates an unsuccessful query result with error condition.
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const
DUCKDB_API const string & ColumnName (idx_t index) const
 Returns the name of the column for the given index.
DUCKDB_API unique_ptr< DataChunk > Fetch ()
DUCKDB_API unique_ptr< DataChunk > FetchRaw ()
virtual DUCKDB_API string ToBox (ClientContext &context, const BoxRendererConfig &config)
 Converts the QueryResult to a box-rendered string.
DUCKDB_API void Print ()
 Prints the QueryResult to the console.
DUCKDB_API bool Equals (QueryResult &other)
bool TryFetch (unique_ptr< DataChunk > &result, ErrorData &error)
iterator begin ()
iterator end ()
Public Member Functions inherited from duckdb::BaseQueryResult
DUCKDB_API BaseQueryResult (QueryResultType type, StatementType statement_type, StatementProperties properties, vector< LogicalType > types, vector< string > names)
 Creates a successful query result with the specified names and types.
DUCKDB_API BaseQueryResult (QueryResultType type, ErrorData error)
 Creates an unsuccessful query result with error condition.
DUCKDB_API void ThrowError (const string &prepended_message="") const
DUCKDB_API void SetError (ErrorData error)
DUCKDB_API bool HasError () const
DUCKDB_API const ExceptionType & GetErrorType () const
DUCKDB_API const std::string & GetError () const
DUCKDB_API ErrorData & GetErrorObject ()
DUCKDB_API idx_t ColumnCount ()

Static Public Member Functions

static bool IsChunkReady (StreamExecutionResult result)
Static Public Member Functions inherited from duckdb::QueryResult
static void DeduplicateColumns (vector< string > &names)
 Deduplicate column names for interop with external libraries.

Public Attributes

shared_ptr< ClientContext > context
 The client context this StreamQueryResult belongs to.
Public Attributes inherited from duckdb::QueryResult
ClientProperties client_properties
 Properties from the client context.
unique_ptr< QueryResult > next
 The next result (if any).
Public Attributes inherited from duckdb::BaseQueryResult
QueryResultType type
 The type of the result (MATERIALIZED or STREAMING).
StatementType statement_type
 The type of the statement that created this result.
StatementProperties properties
 Properties of the statement.
vector< LogicalType > types
 The SQL types of the result.
vector< string > names
 The names of the result.

Static Public Attributes

static constexpr const QueryResultType TYPE = QueryResultType::STREAM_RESULT

Protected Member Functions

DUCKDB_API unique_ptr< DataChunk > FetchInternal () override
Protected Member Functions inherited from duckdb::QueryResult
DUCKDB_API string HeaderToString ()

Private Member Functions

StreamExecutionResult ExecuteTaskInternal (ClientContextLock &lock)
unique_ptr< DataChunk > FetchNextInternal (ClientContextLock &lock)
unique_ptr< ClientContextLock > LockContext ()
void CheckExecutableInternal (ClientContextLock &lock)
bool IsOpenInternal (ClientContextLock &lock)

Private Attributes

shared_ptr< BufferedData > buffered_data

Friends

class ClientContext

Additional Inherited Members

Public Types inherited from duckdb::QueryResult
using iterator = QueryResultIterator
Protected Attributes inherited from duckdb::BaseQueryResult
bool success
 Whether or not execution was successful.
ErrorData error
 The error (in case execution was not successful).

Constructor & Destructor Documentation

◆ StreamQueryResult() [1/2]

duckdb::StreamQueryResult::StreamQueryResult ( StatementType statement_type,
StatementProperties properties,
vector< LogicalType > types,
vector< string > names,
ClientProperties client_properties,
shared_ptr< BufferedData > buffered_data )

Create a successful StreamQueryResult. StreamQueryResults should always be successful initially (it makes no sense to stream an error).

303048 : QueryResult(QueryResultType::STREAM_RESULT, statement_type, std::move(properties), std::move(types),
303049 std::move(names), std::move(client_properties)),
303050 buffered_data(std::move(data)) {
303051 context = buffered_data->GetContext();
303052}
StatementProperties properties
Properties of the statement.
Definition duckdb.hpp:19520
StatementType statement_type
The type of the statement that created this result.
Definition duckdb.hpp:19518
vector< LogicalType > types
The SQL types of the result.
Definition duckdb.hpp:19522
vector< string > names
The names of the result.
Definition duckdb.hpp:19524
DUCKDB_API QueryResult(QueryResultType type, StatementType statement_type, StatementProperties properties, vector< LogicalType > types, vector< string > names, ClientProperties client_properties)
Creates a successful query result with the specified names and types.
Definition duckdb.cpp:296048
ClientProperties client_properties
Properties from the client context.
Definition duckdb.hpp:19555
shared_ptr< ClientContext > context
The client context this StreamQueryResult belongs to.
Definition duckdb.hpp:41313
Here is the call graph for this function:

◆ StreamQueryResult() [2/2]

duckdb::StreamQueryResult::StreamQueryResult ( ErrorData error)
explicit
303054 : QueryResult(QueryResultType::STREAM_RESULT, std::move(error)) {
303055}
ErrorData error
The error (in case execution was not successful).
Definition duckdb.hpp:19539

◆ ~StreamQueryResult()

duckdb::StreamQueryResult::~StreamQueryResult ( )
override
303057 {
303058}

Member Function Documentation

◆ IsChunkReady()

bool duckdb::StreamQueryResult::IsChunkReady ( StreamExecutionResult result)
static
303237 {
303238 if (result == StreamExecutionResult::CHUNK_READY) {
303239 // A chunk is ready to be fetched with Fetch()
303240 return true;
303241 }
303242 if (result == StreamExecutionResult::EXECUTION_CANCELLED) {
303243 // Another query execution was started that cancelled this one
303244 return true;
303245 }
303246 if (result == StreamExecutionResult::EXECUTION_ERROR) {
303247 // An error was encountered while executing the final pipeline
303248 return true;
303249 }
303250 if (result == StreamExecutionResult::EXECUTION_FINISHED) {
303251 // The final pipeline completed successfully
303252 return true;
303253 }
303254 return false;
303255}

◆ WaitForTask()

void duckdb::StreamQueryResult::WaitForTask ( )

Reschedules the tasks that work on producing a result chunk, returning when at least one task can be executed.

303091 {
303092 auto lock = LockContext();
303093 buffered_data->UnblockSinks();
303094 context->WaitForTask(*lock, *this);
303095}

◆ ExecuteTask()

StreamExecutionResult duckdb::StreamQueryResult::ExecuteTask ( )

Executes a single task within the final pipeline, returning whether or not a chunk is ready to be fetched.

303086 {
303087 auto lock = LockContext();
303088 return ExecuteTaskInternal(*lock);
303089}

◆ ToString()

string duckdb::StreamQueryResult::ToString ( )
overridevirtual

Converts the QueryResult to a string.

Implements duckdb::QueryResult.

303060 {
303061 string result;
303062 if (success) {
303063 result = HeaderToString();
303064 result += "[[STREAM RESULT]]";
303065 } else {
303066 result = GetError() + "\n";
303067 }
303068 return result;
303069}
bool success
Whether or not execution was successful.
Definition duckdb.hpp:19537

◆ Materialize()

unique_ptr< MaterializedQueryResult > duckdb::StreamQueryResult::Materialize ( )

Materializes the query result and turns it into a materialized query result.

303179 {
303180 if (HasError() || !context) {
303181 return make_uniq<MaterializedQueryResult>(GetErrorObject());
303182 }
303183 auto collection = make_uniq<ColumnDataCollection>(Allocator::DefaultAllocator(), types);
303184
303185 ColumnDataAppendState append_state;
303186 collection->InitializeAppend(append_state);
303187 while (true) {
303188#ifdef DUCKDB_ALTERNATIVE_VERIFY
303189 auto chunk = AlternativeFetch(*this);
303190#else
303191 auto chunk = Fetch();
303192#endif
303193 if (!chunk || chunk->size() == 0) {
303194 break;
303195 }
303196 collection->Append(append_state, *chunk);
303197 }
303198 auto result =
303199 make_uniq<MaterializedQueryResult>(statement_type, properties, names, std::move(collection), client_properties);
303200 if (HasError()) {
303201 return make_uniq<MaterializedQueryResult>(GetErrorObject());
303202 }
303203 return result;
303204}
DUCKDB_API unique_ptr< DataChunk > Fetch()
Definition duckdb.cpp:296095
Here is the call graph for this function:

◆ IsOpen()

bool duckdb::StreamQueryResult::IsOpen ( )
303224 {
303225 if (!success || !context) {
303226 return false;
303227 }
303228 auto lock = LockContext();
303229 return IsOpenInternal(*lock);
303230}

◆ Close()

void duckdb::StreamQueryResult::Close ( )

Closes the StreamQueryResult.

303232 {
303233 buffered_data->Close();
303234 context.reset();
303235}

◆ FetchInternal()

unique_ptr< DataChunk > duckdb::StreamQueryResult::FetchInternal ( )
overrideprotectedvirtual

Implements duckdb::QueryResult.

303144 {
303145 unique_ptr<DataChunk> chunk;
303146 {
303147 auto lock = LockContext();
303148 CheckExecutableInternal(*lock);
303149 chunk = FetchNextInternal(*lock);
303150 }
303151 if (!chunk || chunk->ColumnCount() == 0 || chunk->size() == 0) {
303152 Close();
303153 return nullptr;
303154 }
303155 return chunk;
303156}
DUCKDB_API void Close()
Closes the StreamQueryResult.
Definition duckdb.cpp:303232

◆ ExecuteTaskInternal()

StreamExecutionResult duckdb::StreamQueryResult::ExecuteTaskInternal ( ClientContextLock & lock)
private
303082 {
303083 return buffered_data->ExecuteTaskInternal(*this, lock);
303084}

◆ FetchNextInternal()

unique_ptr< DataChunk > duckdb::StreamQueryResult::FetchNextInternal ( ClientContextLock & lock)
private
303107 {
303108 bool invalidate_query = true;
303109 unique_ptr<DataChunk> chunk;
303110 try {
303111 // fetch the chunk and return it
303112 auto stream_execution_result = buffered_data->ReplenishBuffer(*this, lock);
303113 if (ExecutionErrorOccurred(stream_execution_result)) {
303114 return chunk;
303115 }
303116 chunk = buffered_data->Scan();
303117 if (!chunk || chunk->ColumnCount() == 0 || chunk->size() == 0) {
303118 context->CleanupInternal(lock, this);
303119 chunk = nullptr;
303120 }
303121 return chunk;
303122 } catch (std::exception &ex) {
303123 ErrorData error(ex);
303124 if (!Exception::InvalidatesTransaction(error.Type())) {
303125 // standard exceptions do not invalidate the current transaction
303126 invalidate_query = false;
303127 } else if (Exception::InvalidatesDatabase(error.Type())) {
303128 // fatal exceptions invalidate the entire database
303129 auto &config = context->config;
303130 if (!config.query_verification_enabled) {
303131 auto &db_instance = DatabaseInstance::GetDatabase(*context);
303132 ValidChecker::Invalidate(db_instance, error.RawMessage());
303133 }
303134 }
303135 context->ProcessError(error, context->GetCurrentQuery());
303136 SetError(std::move(error));
303137 } catch (...) { // LCOV_EXCL_START
303138 SetError(ErrorData("Unhandled exception in FetchInternal"));
303139 } // LCOV_EXCL_STOP
303140 context->CleanupInternal(lock, this, invalidate_query);
303141 return nullptr;
303142}

◆ LockContext()

unique_ptr< ClientContextLock > duckdb::StreamQueryResult::LockContext ( )
private
303071 {
303072 if (!context) {
303073 string error_str = "Attempting to execute an unsuccessful or closed pending query result";
303074 if (HasError()) {
303075 error_str += StringUtil::Format("\nError: %s", GetError());
303076 }
303077 throw InvalidInputException(error_str);
303078 }
303079 return context->LockContext();
303080}
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002

◆ CheckExecutableInternal()

void duckdb::StreamQueryResult::CheckExecutableInternal ( ClientContextLock & lock)
private
303214 {
303215 if (!IsOpenInternal(lock)) {
303216 string error_str = "Attempting to execute an unsuccessful or closed pending query result";
303217 if (HasError()) {
303218 error_str += StringUtil::Format("\nError: %s", GetError());
303219 }
303220 throw InvalidInputException(error_str);
303221 }
303222}

◆ IsOpenInternal()

bool duckdb::StreamQueryResult::IsOpenInternal ( ClientContextLock & lock)
private
303206 {
303207 bool invalidated = !success || !context;
303208 if (!invalidated) {
303209 invalidated = !context->IsActiveResult(lock, *this);
303210 }
303211 return !invalidated;
303212}

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