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

Public Member Functions

DUCKDB_API MaterializedQueryResult (StatementType statement_type, StatementProperties properties, vector< string > names, unique_ptr< ColumnDataCollection > collection, ClientProperties client_properties)
 Creates a successful query result with the specified names and types.
DUCKDB_API MaterializedQueryResult (ErrorData error)
 Creates an unsuccessful query result with error condition.
DUCKDB_API string ToString () override
 Converts the QueryResult to a string.
DUCKDB_API string ToBox (ClientContext &context, const BoxRendererConfig &config) override
 Converts the QueryResult to a box-rendered string.
DUCKDB_API Value GetValue (idx_t column, idx_t index)
template<class T>
T GetValue (idx_t column, idx_t index)
DUCKDB_API idx_t RowCount () const
ColumnDataCollection & Collection ()
 Returns a reference to the underlying column data collection.
unique_ptr< ColumnDataCollection > TakeCollection ()
 Takes ownership of the collection, 'collection' is null after this operation.
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 ()
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 Attributes

static constexpr const QueryResultType TYPE = QueryResultType::MATERIALIZED_RESULT

Protected Member Functions

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

Private Attributes

unique_ptr< ColumnDataCollection > collection
unique_ptr< ColumnDataRowCollection > row_collection
 Row collection, only created if GetValue is called.
ColumnDataScanState scan_state
 Scan state for Fetch calls.
bool scan_initialized

Friends

class ClientContext

Additional Inherited Members

Public Types inherited from duckdb::QueryResult
using iterator = QueryResultIterator
Static Public Member Functions inherited from duckdb::QueryResult
static void DeduplicateColumns (vector< string > &names)
 Deduplicate column names for interop with external libraries.
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.
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

◆ MaterializedQueryResult() [1/2]

duckdb::MaterializedQueryResult::MaterializedQueryResult ( StatementType statement_type,
StatementProperties properties,
vector< string > names,
unique_ptr< ColumnDataCollection > collection,
ClientProperties client_properties )

Creates a successful query result with the specified names and types.

294148 : QueryResult(QueryResultType::MATERIALIZED_RESULT, statement_type, std::move(properties), collection_p->Types(),
294149 std::move(names_p), std::move(client_properties)),
294150 collection(std::move(collection_p)), scan_initialized(false) {
294151}
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
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
Here is the call graph for this function:

◆ MaterializedQueryResult() [2/2]

duckdb::MaterializedQueryResult::MaterializedQueryResult ( ErrorData error)
explicit

Creates an unsuccessful query result with error condition.

294154 : QueryResult(QueryResultType::MATERIALIZED_RESULT, std::move(error)), scan_initialized(false) {
294155}
ErrorData error
The error (in case execution was not successful).
Definition duckdb.hpp:19539
Here is the call graph for this function:

Member Function Documentation

◆ ToString()

string duckdb::MaterializedQueryResult::ToString ( )
overridevirtual

Converts the QueryResult to a string.

Implements duckdb::QueryResult.

294157 {
294158 string result;
294159 if (success) {
294160 result = HeaderToString();
294161 result += "[ Rows: " + to_string(collection->Count()) + "]\n";
294162 auto &coll = Collection();
294163 for (auto &row : coll.Rows()) {
294164 for (idx_t col_idx = 0; col_idx < coll.ColumnCount(); col_idx++) {
294165 if (col_idx > 0) {
294166 result += "\t";
294167 }
294168 auto val = row.GetValue(col_idx);
294169 result += val.IsNull() ? "NULL" : StringUtil::Replace(val.ToString(), string("\0", 1), "\\0");
294170 }
294171 result += "\n";
294172 }
294173 result += "\n";
294174 } else {
294175 result = GetError() + "\n";
294176 }
294177 return result;
294178}
bool success
Whether or not execution was successful.
Definition duckdb.hpp:19537
ColumnDataCollection & Collection()
Returns a reference to the underlying column data collection.
Definition duckdb.cpp:294202
std::string to_string(const T &value)
Definition duckdb.cpp:19425
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ ToBox()

string duckdb::MaterializedQueryResult::ToBox ( ClientContext & context,
const BoxRendererConfig & config )
overridevirtual

Converts the QueryResult to a box-rendered string.

Reimplemented from duckdb::QueryResult.

294180 {
294181 if (!success) {
294182 return GetError() + "\n";
294183 }
294184 if (!collection) {
294185 return "Internal error - result was successful but there was no collection";
294186 }
294187 BoxRenderer renderer(config);
294188 return renderer.ToString(context, names, Collection());
294189}
vector< string > names
The names of the result.
Definition duckdb.hpp:19524
Here is the call graph for this function:

◆ GetValue() [1/2]

Value duckdb::MaterializedQueryResult::GetValue ( idx_t column,
idx_t index )

Gets the (index) value of the (column index) column. Note: this is very slow. Scanning over the underlying collection is much faster.

294191 {
294192 if (!row_collection) {
294193 row_collection = make_uniq<ColumnDataRowCollection>(collection->GetRows());
294194 }
294195 return row_collection->GetValue(column, index);
294196}
unique_ptr< ColumnDataRowCollection > row_collection
Row collection, only created if GetValue is called.
Definition duckdb.hpp:19761
Here is the caller graph for this function:

◆ GetValue() [2/2]

template<class T>
T duckdb::MaterializedQueryResult::GetValue ( idx_t column,
idx_t index )
inline
19742 {
19743 auto value = GetValue(column, index);
19744 return (T)value.GetValue<int64_t>();
19745 }
DUCKDB_API Value GetValue(idx_t column, idx_t index)
Definition duckdb.cpp:294191
::int64_t int64_t

◆ RowCount()

idx_t duckdb::MaterializedQueryResult::RowCount ( ) const
294198 {
294199 return collection ? collection->Count() : 0;
294200}

◆ Collection()

ColumnDataCollection & duckdb::MaterializedQueryResult::Collection ( )

Returns a reference to the underlying column data collection.

294202 {
294203 if (HasError()) {
294204 throw InvalidInputException("Attempting to get collection from an unsuccessful query result\n: Error %s",
294205 GetError());
294206 }
294207 if (!collection) {
294208 throw InternalException("Missing collection from materialized query result");
294209 }
294210 return *collection;
294211}
Here is the caller graph for this function:

◆ TakeCollection()

unique_ptr< ColumnDataCollection > duckdb::MaterializedQueryResult::TakeCollection ( )

Takes ownership of the collection, 'collection' is null after this operation.

294213 {
294214 if (HasError()) {
294215 throw InvalidInputException("Attempting to get collection from an unsuccessful query result\n: Error %s",
294216 GetError());
294217 }
294218 if (!collection) {
294219 throw InternalException("Missing collection from materialized query result");
294220 }
294221 return std::move(collection);
294222}

◆ FetchInternal()

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

Implements duckdb::QueryResult.

294224 {
294225 if (HasError()) {
294226 throw InvalidInputException("Attempting to fetch from an unsuccessful query result\nError: %s", GetError());
294227 }
294228 auto result = make_uniq<DataChunk>();
294229 collection->InitializeScanChunk(*result);
294230 if (!scan_initialized) {
294231 // we disallow zero copy so the chunk is independently usable even after the result is destroyed
294232 collection->InitializeScan(scan_state, ColumnDataScanProperties::DISALLOW_ZERO_COPY);
294233 scan_initialized = true;
294234 }
294235 collection->Scan(scan_state, *result);
294236 if (result->size() == 0) {
294237 return nullptr;
294238 }
294239 return result;
294240}
ColumnDataScanState scan_state
Scan state for Fetch calls.
Definition duckdb.hpp:19763
@ DISALLOW_ZERO_COPY
Definition duckdb.hpp:18814

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