14#include <sparrow/record_batch.hpp>
21namespace sp = sparrow;
29 std::vector<sp::record_batch> batches;
30 for (
size_t i = 0; i < count; ++i)
32 auto int_array = sp::primitive_array<int32_t>(
33 {
static_cast<int32_t
>(i * 10),
static_cast<int32_t
>(i * 10 + 1),
static_cast<int32_t
>(i * 10 + 2)}
35 auto string_array = sp::string_array(std::vector<std::string>{
36 "batch_" + std::to_string(i) +
"_a",
37 "batch_" + std::to_string(i) +
"_b",
38 "batch_" + std::to_string(i) +
"_c"
40 batches.push_back(sp::record_batch(
41 {{
"id", sp::array(std::move(int_array))}, {
"name", sp::array(std::move(string_array))}}
52 std::vector<uint8_t> buffer;
85 std::vector<sp::record_batch> batches;
91 deser.
deserialize(std::span<const uint8_t>(stream_data));
94 for (
const auto& batch : batches)
96 std::cout <<
"Batch with " << batch.nb_rows() <<
" rows and " << batch.nb_columns() <<
" columns\n";
112 std::vector<sp::record_batch> batches;
118 for (
const auto& chunk : stream_chunks)
120 deser << std::span<const uint8_t>(chunk);
121 std::cout <<
"After chunk: " << batches.size() <<
" batches accumulated\n";
125 std::cout <<
"Total batches deserialized: " << batches.size() <<
"\n";
137 const std::vector<uint8_t>& chunk1,
138 const std::vector<uint8_t>& chunk2,
139 const std::vector<uint8_t>& chunk3
142 std::vector<sp::record_batch> batches;
146 deser << std::span<const uint8_t>(chunk1) << std::span<const uint8_t>(chunk2)
147 << std::span<const uint8_t>(chunk3);
149 std::cout <<
"Deserialized " << batches.size() <<
" batches from 3 chunks\n";
156 std::cout <<
"=== Sparrow IPC Deserializer Examples ===\n\n";
164 std::cout <<
"1. Function API Example (deserialize_stream)\n";
165 std::cout <<
" ----------------------------------------\n";
167 std::cout <<
" Deserialized " << deserialized.size() <<
" batches\n\n";
169 std::cout <<
"2. Basic Deserializer Class Example\n";
170 std::cout <<
" ---------------------------------\n";
174 std::cout <<
"3. Incremental Deserialization Example\n";
175 std::cout <<
" ------------------------------------\n";
177 std::vector<std::vector<uint8_t>> chunks;
178 for (
size_t i = 0; i < 3; ++i)
186 std::cout <<
"4. Chaining Example\n";
187 std::cout <<
" -----------------\n";
190 std::cout <<
"\n=== All examples completed successfully! ===\n";
192 catch (
const std::exception& e)
194 std::cerr <<
"Error: " << e.what() <<
"\n";
void deserialize(std::span< const uint8_t > data)
An output stream that writes data to a contiguous memory buffer.
A class for serializing Apache Arrow record batches to an output stream.
void deserializer_chaining_example(const std::vector< uint8_t > &chunk1, const std::vector< uint8_t > &chunk2, const std::vector< uint8_t > &chunk3)
Example: Chaining multiple deserializations.
void deserializer_incremental_example(const std::vector< std::vector< uint8_t > > &stream_chunks)
Example: Incremental deserialization with the deserializer class.
void deserializer_basic_example(const std::vector< uint8_t > &stream_data)
Example: Basic usage of the deserializer class.
std::vector< sp::record_batch > create_sample_batches(size_t count)
Helper function to create sample record batches for demonstration.
std::vector< uint8_t > serialize_batches(const std::vector< sp::record_batch > &batches)
Helper function to serialize batches to a byte buffer.
std::vector< sp::record_batch > deserialize_stream_example(const std::vector< uint8_t > &stream_data)
Example: Deserialize a stream using the function API.
SPARROW_IPC_API std::vector< sparrow::record_batch > deserialize_stream(std::span< const uint8_t > data)
Deserializes an Arrow IPC stream from binary data into a vector of record batches.
serializer & end_stream(serializer &serializer)