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::ArrowAppender Class Reference

The ArrowAppender class can be used to incrementally construct an arrow array by appending data chunks into it. More...

Collaboration diagram for duckdb::ArrowAppender:

Public Member Functions

DUCKDB_API ArrowAppender (vector< LogicalType > types_p, const idx_t initial_capacity, ClientProperties options, unordered_map< idx_t, const shared_ptr< ArrowTypeExtensionData > > extension_type_cast)
 
DUCKDB_API void Append (DataChunk &input, idx_t from, idx_t to, idx_t input_size)
 Append a data chunk to the underlying arrow array.
 
DUCKDB_API ArrowArray Finalize ()
 Returns the underlying arrow array.
 
idx_t RowCount () const
 

Static Public Member Functions

static void ReleaseArray (ArrowArray *array)
 
static ArrowArrayFinalizeChild (const LogicalType &type, unique_ptr< ArrowAppendData > append_data_p)
 
static unique_ptr< ArrowAppendDataInitializeChild (const LogicalType &type, const idx_t capacity, ClientProperties &options, const shared_ptr< ArrowTypeExtensionData > &extension_type=nullptr)
 
static void AddChildren (ArrowAppendData &data, const idx_t count)
 

Private Attributes

vector< LogicalTypetypes
 The types of the chunks that will be appended in.
 
vector< unique_ptr< ArrowAppendData > > root_data
 The root arrow append data.
 
idx_t row_count = 0
 The total row count that has been appended.
 
ClientProperties options
 

Detailed Description

The ArrowAppender class can be used to incrementally construct an arrow array by appending data chunks into it.

Constructor & Destructor Documentation

◆ ArrowAppender()

duckdb::ArrowAppender::ArrowAppender ( vector< LogicalType types_p,
const idx_t  initial_capacity,
ClientProperties  options,
unordered_map< idx_t, const shared_ptr< ArrowTypeExtensionData > >  extension_type_cast 
)
34129 : types(std::move(types_p)), options(options) {
34130 for (idx_t i = 0; i < types.size(); i++) {
34131 unique_ptr<ArrowAppendData> entry;
34132 bool bitshift_boolean = types[i].id() == LogicalTypeId::BOOLEAN && !options.arrow_lossless_conversion;
34133 if (extension_type_cast.find(i) != extension_type_cast.end() && !bitshift_boolean) {
34134 entry = InitializeChild(types[i], initial_capacity, options, extension_type_cast[i]);
34135 } else {
34136 entry = InitializeChild(types[i], initial_capacity, options);
34137 }
34138 root_data.push_back(std::move(entry));
34139 }
34140}
vector< LogicalType > types
The types of the chunks that will be appended in.
Definition duckdb.cpp:32923
vector< unique_ptr< ArrowAppendData > > root_data
The root arrow append data.
Definition duckdb.cpp:32925

◆ ~ArrowAppender()

duckdb::ArrowAppender::~ArrowAppender ( )
34142 {
34143}

Member Function Documentation

◆ Append()

void duckdb::ArrowAppender::Append ( DataChunk input,
idx_t  from,
idx_t  to,
idx_t  input_size 
)

Append a data chunk to the underlying arrow array.

34146 {
34147 D_ASSERT(types == input.GetTypes());
34148 D_ASSERT(to >= from);
34149 for (idx_t i = 0; i < input.ColumnCount(); i++) {
34150 if (root_data[i]->extension_data && root_data[i]->extension_data->duckdb_to_arrow) {
34151 Vector input_data(root_data[i]->extension_data->GetInternalType());
34152 root_data[i]->extension_data->duckdb_to_arrow(*options.client_context, input.data[i], input_data,
34153 input_size);
34154 root_data[i]->append_vector(*root_data[i], input_data, from, to, input_size);
34155 } else {
34156 root_data[i]->append_vector(*root_data[i], input.data[i], from, to, input_size);
34157 }
34158 }
34159 row_count += to - from;
34160}
idx_t row_count
The total row count that has been appended.
Definition duckdb.cpp:32927
Here is the call graph for this function:

◆ Finalize()

ArrowArray duckdb::ArrowAppender::Finalize ( )

Returns the underlying arrow array.

34214 {
34215 D_ASSERT(root_data.size() == types.size());
34216 auto root_holder = make_uniq<ArrowAppendData>(options);
34217
34218 ArrowArray result;
34219 AddChildren(*root_holder, types.size());
34220 result.children = root_holder->child_pointers.data();
34221 result.n_children = NumericCast<int64_t>(types.size());
34222
34223 // Configure root array
34224 result.length = NumericCast<int64_t>(row_count);
34225 result.n_buffers = 1;
34226 result.buffers = root_holder->buffers.data(); // there is no actual buffer there since we don't have NULLs
34227 result.offset = 0;
34228 result.null_count = 0; // needs to be 0
34229 result.dictionary = nullptr;
34230 root_holder->child_data = std::move(root_data);
34231
34232 for (idx_t i = 0; i < root_holder->child_data.size(); i++) {
34233 root_holder->child_arrays[i] = *ArrowAppender::FinalizeChild(types[i], std::move(root_holder->child_data[i]));
34234 }
34235
34236 // Release ownership to caller
34237 result.private_data = root_holder.release();
34238 result.release = ArrowAppender::ReleaseArray;
34239 return result;
34240}
Definition duckdb.hpp:11287
void(* release)(struct ArrowArray *)
Release callback.
Definition duckdb.hpp:11299
void * private_data
Opaque producer-specific data.
Definition duckdb.hpp:11301
int64_t length
Array data description.
Definition duckdb.hpp:11289

◆ RowCount()

idx_t duckdb::ArrowAppender::RowCount ( ) const
34162 {
34163 return row_count;
34164}

◆ ReleaseArray()

void duckdb::ArrowAppender::ReleaseArray ( ArrowArray array)
static
34166 {
34167 if (!array || !array->release) {
34168 return;
34169 }
34170 auto holder = static_cast<ArrowAppendData *>(array->private_data);
34171 for (int64_t i = 0; i < array->n_children; i++) {
34172 auto child = array->children[i];
34173 if (!child->release) {
34174 // Child was moved out of the array
34175 continue;
34176 }
34177 child->release(child);
34178 D_ASSERT(!child->release);
34179 }
34180 if (array->dictionary && array->dictionary->release) {
34181 array->dictionary->release(array->dictionary);
34182 }
34183 array->release = nullptr;
34184 delete holder;
34185}
::int64_t int64_t

◆ FinalizeChild()

ArrowArray * duckdb::ArrowAppender::FinalizeChild ( const LogicalType type,
unique_ptr< ArrowAppendData append_data_p 
)
static
34190 {
34191 auto result = make_uniq<ArrowArray>();
34192
34193 auto &append_data = *append_data_p;
34194 result->private_data = append_data_p.release();
34195 result->release = ReleaseArray;
34196 result->n_children = 0;
34197 result->null_count = 0;
34198 result->offset = 0;
34199 result->dictionary = nullptr;
34200 result->buffers = append_data.buffers.data();
34201 result->null_count = NumericCast<int64_t>(append_data.null_count);
34202 result->length = NumericCast<int64_t>(append_data.row_count);
34203 result->buffers[0] = append_data.GetValidityBuffer().data();
34204
34205 if (append_data.finalize) {
34206 append_data.finalize(append_data, type, result.get());
34207 }
34208
34209 append_data.array = std::move(result);
34210 return append_data.array.get();
34211}

◆ InitializeChild()

unique_ptr< ArrowAppendData > duckdb::ArrowAppender::InitializeChild ( const LogicalType type,
const idx_t  capacity,
ClientProperties options,
const shared_ptr< ArrowTypeExtensionData > &  extension_type = nullptr 
)
static
34425 {
34426 auto result = make_uniq<ArrowAppendData>(options);
34427 LogicalType array_type = type;
34428 if (extension_type) {
34429 array_type = extension_type->GetInternalType();
34430 }
34431 InitializeFunctionPointers(*result, array_type);
34432 result->extension_data = extension_type;
34433
34434 const auto byte_count = (capacity + 7) / 8;
34435 result->GetValidityBuffer().reserve(byte_count);
34436 result->initialize(*result, array_type, capacity);
34437 return result;
34438}

◆ AddChildren()

void duckdb::ArrowAppender::AddChildren ( ArrowAppendData data,
const idx_t  count 
)
static
34440 {
34441 data.child_pointers.resize(count);
34442 data.child_arrays.resize(count);
34443 for (idx_t i = 0; i < count; i++) {
34444 data.child_pointers[i] = &data.child_arrays[i];
34445 }
34446}

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