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

Public Member Functions

 ResultArrowArrayStreamWrapper (unique_ptr< QueryResult > result, idx_t batch_size)
 

Public Attributes

ArrowArrayStream stream
 
unique_ptr< QueryResultresult
 
ErrorData last_error
 
idx_t batch_size
 
vector< LogicalTypecolumn_types
 
vector< string > column_names
 
unique_ptr< ChunkScanStatescan_state
 
unordered_map< idx_t, const shared_ptr< ArrowTypeExtensionData > > extension_types
 

Static Private Member Functions

static int MyStreamGetSchema (struct ArrowArrayStream *stream, struct ArrowSchema *out)
 
static int MyStreamGetNext (struct ArrowArrayStream *stream, struct ArrowArray *out)
 
static void MyStreamRelease (struct ArrowArrayStream *stream)
 
static const charMyStreamGetLastError (struct ArrowArrayStream *stream)
 

Constructor & Destructor Documentation

◆ ResultArrowArrayStreamWrapper()

duckdb::ResultArrowArrayStreamWrapper::ResultArrowArrayStreamWrapper ( unique_ptr< QueryResult result,
idx_t  batch_size 
)
explicit

We first initialize the private data of the stream

Ceil Approx_Batch_Size/STANDARD_VECTOR_SIZE

We initialize the stream functions

45848 : result(std::move(result_p)), scan_state(make_uniq<QueryResultChunkScanState>(*result)) {
45850 stream.private_data = this;
45852 if (batch_size_p == 0) {
45853 throw std::runtime_error("Approximate Batch Size of Record Batch MUST be higher than 0");
45854 }
45855 batch_size = batch_size_p;
45857 stream.get_schema = ResultArrowArrayStreamWrapper::MyStreamGetSchema;
45858 stream.get_next = ResultArrowArrayStreamWrapper::MyStreamGetNext;
45859 stream.release = ResultArrowArrayStreamWrapper::MyStreamRelease;
45860 stream.get_last_error = ResultArrowArrayStreamWrapper::MyStreamGetLastError;
45861
45862 extension_types =
45863 ArrowTypeExtensionData::GetExtensionTypes(*result->client_properties.client_context, result->types);
45864}
static unordered_map< idx_t, const shared_ptr< ArrowTypeExtensionData > > GetExtensionTypes(ClientContext &context, const vector< LogicalType > &duckdb_types)
This function returns possible extension types to given DuckDB types.
Here is the call graph for this function:

Member Function Documentation

◆ MyStreamGetSchema()

int duckdb::ResultArrowArrayStreamWrapper::MyStreamGetSchema ( struct ArrowArrayStream stream,
struct ArrowSchema out 
)
staticprivate
45742 {
45743 if (!stream->release) {
45744 return -1;
45745 }
45746 out->release = nullptr;
45747 auto my_stream = reinterpret_cast<ResultArrowArrayStreamWrapper *>(stream->private_data);
45748 if (!my_stream->column_types.empty()) {
45749 try {
45750 ArrowConverter::ToArrowSchema(out, my_stream->column_types, my_stream->column_names,
45751 my_stream->result->client_properties);
45752 } catch (std::runtime_error &e) {
45753 my_stream->last_error = ErrorData(e);
45754 return -1;
45755 }
45756 return 0;
45757 }
45758
45759 auto &result = *my_stream->result;
45760 if (result.HasError()) {
45761 my_stream->last_error = result.GetErrorObject();
45762 return -1;
45763 }
45764 if (result.type == QueryResultType::STREAM_RESULT) {
45765 auto &stream_result = result.Cast<StreamQueryResult>();
45766 if (!stream_result.IsOpen()) {
45767 my_stream->last_error = ErrorData("Query Stream is closed");
45768 return -1;
45769 }
45770 }
45771 if (my_stream->column_types.empty()) {
45772 my_stream->column_types = result.types;
45773 my_stream->column_names = result.names;
45774 }
45775 try {
45776 ArrowConverter::ToArrowSchema(out, my_stream->column_types, my_stream->column_names,
45777 my_stream->result->client_properties);
45778 } catch (std::runtime_error &e) {
45779 my_stream->last_error = ErrorData(e);
45780 return -1;
45781 }
45782 return 0;
45783}
ResultArrowArrayStreamWrapper(unique_ptr< QueryResult > result, idx_t batch_size)
Definition duckdb.cpp:45847
void(* release)(struct ArrowSchema *)
Release callback.
Definition duckdb.hpp:11274

◆ MyStreamGetNext()

int duckdb::ResultArrowArrayStreamWrapper::MyStreamGetNext ( struct ArrowArrayStream stream,
struct ArrowArray out 
)
staticprivate
45785 {
45786 if (!stream->release) {
45787 return -1;
45788 }
45789 auto my_stream = reinterpret_cast<ResultArrowArrayStreamWrapper *>(stream->private_data);
45790 auto &result = *my_stream->result;
45791 auto &scan_state = *my_stream->scan_state;
45792 if (result.HasError()) {
45793 my_stream->last_error = result.GetErrorObject();
45794 return -1;
45795 }
45796 if (result.type == QueryResultType::STREAM_RESULT) {
45797 auto &stream_result = result.Cast<StreamQueryResult>();
45798 if (!stream_result.IsOpen()) {
45799 // Nothing to output
45800 out->release = nullptr;
45801 return 0;
45802 }
45803 }
45804 if (my_stream->column_types.empty()) {
45805 my_stream->column_types = result.types;
45806 my_stream->column_names = result.names;
45807 }
45808
45809 try {
45810 idx_t result_count;
45811 ErrorData error;
45812 if (!ArrowUtil::TryFetchChunk(scan_state, result.client_properties, my_stream->batch_size, out, result_count,
45813 error, my_stream->extension_types)) {
45814 D_ASSERT(error.HasError());
45815 my_stream->last_error = error;
45816 return -1;
45817 }
45818 if (result_count == 0) {
45819 // Nothing to output
45820 out->release = nullptr;
45821 }
45822 } catch (std::exception &e) {
45823 my_stream->last_error = ErrorData(e);
45824 return -1;
45825 }
45826
45827 return 0;
45828}
void error(int _code, const String &_err, const char *_func, const char *_file, int _line)
void(* release)(struct ArrowArray *)
Release callback.
Definition duckdb.hpp:11299

◆ MyStreamRelease()

void duckdb::ResultArrowArrayStreamWrapper::MyStreamRelease ( struct ArrowArrayStream stream)
staticprivate
45830 {
45831 if (!stream || !stream->release) {
45832 return;
45833 }
45834 stream->release = nullptr;
45835 delete reinterpret_cast<ResultArrowArrayStreamWrapper *>(stream->private_data);
45836}

◆ MyStreamGetLastError()

const char * duckdb::ResultArrowArrayStreamWrapper::MyStreamGetLastError ( struct ArrowArrayStream stream)
staticprivate
45838 {
45839 if (!stream->release) {
45840 return "stream was released";
45841 }
45842 D_ASSERT(stream->private_data);
45843 auto my_stream = reinterpret_cast<ResultArrowArrayStreamWrapper *>(stream->private_data);
45844 return my_stream->last_error.Message().c_str();
45845}

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