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
QueryResult Class Referenceabstract

#include <duckdb.hpp>

Inheritance diagram for QueryResult:
Collaboration diagram for QueryResult:

Classes

class  QueryResultRow
class  QueryResultIterator
 The row-based query result iterator. Invoking the. More...

Public Types

using iterator = QueryResultIterator

Public Member Functions

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 ToString ()=0
 Converts the QueryResult to a string.
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 void DeduplicateColumns (vector< string > &names)
 Deduplicate column names for interop with external libraries.

Public Attributes

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 Member Functions

virtual DUCKDB_API unique_ptr< DataChunk > FetchInternal ()=0
DUCKDB_API string HeaderToString ()

Private Member Functions

 QueryResult (const QueryResult &)=delete

Additional Inherited Members

Protected Attributes inherited from duckdb::BaseQueryResult
bool success
 Whether or not execution was successful.
ErrorData error
 The error (in case execution was not successful).

Detailed Description

The QueryResult object holds the result of a query. It can either be a MaterializedQueryResult, in which case the result contains the entire result set, or a StreamQueryResult in which case the Fetch method can be called to incrementally fetch data from the database.

Constructor & Destructor Documentation

◆ QueryResult() [1/2]

duckdb::QueryResult::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.

296050 : BaseQueryResult(type, statement_type, std::move(properties), std::move(types_p), std::move(names_p)),
296051 client_properties(std::move(client_properties_p)) {
296052}
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.
Definition duckdb.cpp:296000
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
QueryResultType type
The type of the result (MATERIALIZED or STREAMING).
Definition duckdb.hpp:19516
ClientProperties client_properties
Properties from the client context.
Definition duckdb.hpp:19555

◆ QueryResult() [2/2]

duckdb::QueryResult::QueryResult ( QueryResultType type,
ErrorData error )

Creates an unsuccessful query result with error condition.

296055 : BaseQueryResult(type, std::move(error)),
296056 client_properties("UTC", ArrowOffsetSize::REGULAR, false, false, false, ArrowFormatVersion::V1_0, nullptr) {
296057}
ErrorData error
The error (in case execution was not successful).
Definition duckdb.hpp:19539
@ V1_0
Base Version.
Definition duckdb.hpp:19459

◆ ~QueryResult()

duckdb::QueryResult::~QueryResult ( )
override
296059 {
296060}

Member Function Documentation

◆ Cast() [1/2]

template<class TARGET>
TARGET & duckdb::QueryResult::Cast ( )
inline
19561 {
19562 if (type != TARGET::TYPE) {
19563 throw InternalException("Failed to cast query result to type - query result type mismatch");
19564 }
19565 return reinterpret_cast<TARGET &>(*this);
19566 }

◆ Cast() [2/2]

template<class TARGET>
const TARGET & duckdb::QueryResult::Cast ( ) const
inline
19569 {
19570 if (type != TARGET::TYPE) {
19571 throw InternalException("Failed to cast query result to type - query result type mismatch");
19572 }
19573 return reinterpret_cast<const TARGET &>(*this);
19574 }

◆ DeduplicateColumns()

void duckdb::QueryResult::DeduplicateColumns ( vector< string > & names)
static

Deduplicate column names for interop with external libraries.

296062 {
296063 unordered_map<string, idx_t> name_map;
296064 for (auto &column_name : names) {
296065 // put it all lower_case
296066 auto low_column_name = StringUtil::Lower(column_name);
296067 if (name_map.find(low_column_name) == name_map.end()) {
296068 // Name does not exist yet
296069 name_map[low_column_name]++;
296070 } else {
296071 // Name already exists, we add _x where x is the repetition number
296072 string new_column_name = column_name + "_" + std::to_string(name_map[low_column_name]);
296073 auto new_column_name_low = StringUtil::Lower(new_column_name);
296074 while (name_map.find(new_column_name_low) != name_map.end()) {
296075 // This name is already here due to a previous definition
296076 name_map[low_column_name]++;
296077 new_column_name = column_name + "_" + std::to_string(name_map[low_column_name]);
296078 new_column_name_low = StringUtil::Lower(new_column_name);
296079 }
296080 column_name = new_column_name;
296081 name_map[new_column_name_low]++;
296082 }
296083 }
296084}
vector< string > names
The names of the result.
Definition duckdb.hpp:19524
static DUCKDB_API string Lower(const string &str)
Convert a string to lowercase.
Definition duckdb.cpp:109630

◆ ColumnName()

const string & duckdb::QueryResult::ColumnName ( idx_t index) const

Returns the name of the column for the given index.

296086 {
296087 D_ASSERT(index < names.size());
296088 return names[index];
296089}
index

◆ Fetch()

Fetches a DataChunk of normalized (flat) vectors from the query result. Returns nullptr if there are no more results to fetch.

296095 {
296096 auto chunk = FetchRaw();
296097 if (!chunk) {
296098 return nullptr;
296099 }
296100 chunk->Flatten();
296101 return chunk;
296102}
DUCKDB_API unique_ptr< DataChunk > FetchRaw()
Definition duckdb.cpp:296104

◆ FetchRaw()

Fetches a DataChunk from the query result. The vectors are not normalized and hence any vector types can be returned.

296104 {
296105 return FetchInternal();
296106}

◆ ToBox()

string duckdb::QueryResult::ToBox ( ClientContext & context,
const BoxRendererConfig & config )
virtual

Converts the QueryResult to a box-rendered string.

296091 {
296092 return ToString();
296093}
virtual DUCKDB_API string ToString()=0
Converts the QueryResult to a string.

◆ Print()

Prints the QueryResult to the console.

296165 {
296167}
static DUCKDB_API void Print(OutputStream stream, const string &str)
Print the object to the stream.
Definition duckdb.cpp:92556

◆ Equals()

Returns true if the two results are identical; false otherwise. Note that this method is destructive; it calls Fetch() until both results are exhausted. The data in the results will be lost.

296108 { // LCOV_EXCL_START
296109 // first compare the success state of the results
296110 if (success != other.success) {
296111 return false;
296112 }
296113 if (!success) {
296114 return error == other.error;
296115 }
296116 // compare names
296117 if (names != other.names) {
296118 return false;
296119 }
296120 // compare types
296121 if (types != other.types) {
296122 return false;
296123 }
296124 // now compare the actual values
296125 // fetch chunks
296126 unique_ptr<DataChunk> lchunk, rchunk;
296127 idx_t lindex = 0, rindex = 0;
296128 while (true) {
296129 if (!lchunk || lindex == lchunk->size()) {
296130 lchunk = Fetch();
296131 lindex = 0;
296132 }
296133 if (!rchunk || rindex == rchunk->size()) {
296134 rchunk = other.Fetch();
296135 rindex = 0;
296136 }
296137 if (!lchunk && !rchunk) {
296138 return true;
296139 }
296140 if (!lchunk || !rchunk) {
296141 return false;
296142 }
296143 if (lchunk->size() == 0 && rchunk->size() == 0) {
296144 return true;
296145 }
296146 D_ASSERT(lchunk->ColumnCount() == rchunk->ColumnCount());
296147 for (; lindex < lchunk->size() && rindex < rchunk->size(); lindex++, rindex++) {
296148 for (idx_t col = 0; col < rchunk->ColumnCount(); col++) {
296149 auto lvalue = lchunk->GetValue(col, lindex);
296150 auto rvalue = rchunk->GetValue(col, rindex);
296151 if (lvalue.IsNull() && rvalue.IsNull()) {
296152 continue;
296153 }
296154 if (lvalue.IsNull() != rvalue.IsNull()) {
296155 return false;
296156 }
296157 if (lvalue != rvalue) {
296158 return false;
296159 }
296160 }
296161 }
296162 }
296163} // LCOV_EXCL_STOP
bool success
Whether or not execution was successful.
Definition duckdb.hpp:19537
vector< LogicalType > types
The SQL types of the result.
Definition duckdb.hpp:19522
DUCKDB_API unique_ptr< DataChunk > Fetch()
Definition duckdb.cpp:296095
GOpaque< Size > size(const GMat &src)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ TryFetch()

bool duckdb::QueryResult::TryFetch ( unique_ptr< DataChunk > & result,
ErrorData & error )
inline
19599 {
19600 try {
19601 result = Fetch();
19602 return success;
19603 } catch (std::exception &ex) {
19604 error = ErrorData(ex);
19605 return false;
19606 } catch (...) {
19607 error = ErrorData("Unknown error in Fetch");
19608 return false;
19609 }
19610 }
DUCKDB_API unique_ptr< DataChunk > Fetch()
Definition duckdb.cpp:296095

◆ begin()

iterator duckdb::QueryResult::begin ( )
inline
19698 { // NOLINT: match stl API
19699 return QueryResultIterator(this);
19700 }
The row-based query result iterator. Invoking the.
Definition duckdb.hpp:19646

◆ end()

iterator duckdb::QueryResult::end ( )
inline
19701 { // NOLINT: match stl API
19702 return QueryResultIterator(nullptr);
19703 }

◆ HeaderToString()

string duckdb::QueryResult::HeaderToString ( )
protected
296169 {
296170 string result;
296171 for (auto &name : names) {
296172 result += name + "\t";
296173 }
296174 result += "\n";
296175 for (auto &type : types) {
296176 result += type.ToString() + "\t";
296177 }
296178 result += "\n";
296179 return result;
296180}

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