r/cpp • • Apr 07 '26

Introducing Sparrow-IPC: A modern C++ implementation of Arrow IPC

https://medium.com/@QuantStack/introducing-sparrow-ipc-modern-c-20-arrow-ipc-e1690ae82b81

We’re excited to announce the release of Sparrow-IPC: a modern, open-source C++20 library that implements the Apache Arrow IPC protocol on top of Sparrow.

Sparrow-IPC passes 100% of the Apache Arrow IPC integration tests, ensuring full compatibility with existing Arrow tools and pipelines.

The library supports compression, the Arrow stream format, and the Arrow file format.

Some examples

Serialize record batches to a memory stream

std::vector<uint8_t> serialize_batches_to_stream(const std::vector<sp::record_batch>& batches)
{
    std::vector<uint8_t> stream_data;
    sp_ipc::memory_output_stream stream(stream_data);
    sp_ipc::serializer serializer(stream);

    // Serialize all batches using the streaming operator
    serializer << batches << sp_ipc::end_stream;

    return stream_data;
}

Pipe a source of record batches to a stream:

class record_batch_source
{
public:
    std::optional<sp::record_batch> next();
};

void stream_record_batches(std::ostream& os, record_batch_source& source)
{
    sp::serializer serial(os);
    std::optional<sp::record_batch> batch = std::nullopt;
    while (batch = source.next())
    {
        serial << batch;
    }
    serial << sp_ipc::end_stream;
}

Incremental deserialization:

void deserializer_incremental_example(const std::vector<std::vector<uint8_t>>& stream_chunks)
{
    // Container to accumulate all deserialized batches
    std::vector<sp::record_batch> batches;

    // Create a deserializer
    sp_ipc::deserializer deser(batches);

    // Deserialize chunks as they arrive using the streaming operator
    for (const auto& chunk : stream_chunks)
    {
        deser << std::span<const uint8_t>(chunk);
        std::cout << "After chunk: " << batches.size() << " batches accumulated\n";
    }

    // All batches are now available in the container
    std::cout << "Total batches deserialized: " << batches.size() << "\n";
}
18 Upvotes

2 comments sorted by

View all comments

Show parent comment

2

u/alexis_placet Apr 13 '26

Although Apache Arrow IPC includes "IPC" in its name, its purpose is not to share in-memory data between processes. Instead, it is designed to serialize, transfer, or stream Arrow data between processes that cannot share memory directly, for example, across remote servers.

When compression is used, decompression cost is unavoidable. However, if no compression is applied, Arrow IPC allows for zero-copy conversion between an IPC stream and Arrow’s in-memory representation.

In contrast, Apache Parquet is intended for on-disk storage of columnar data.

To summarize:

  • Use Arrow in-memory format for storing and sharing data among processes that can access shared memory on the same machine.
  • Use Arrow IPC format for transferring data between endpoints that cannot share memory (e.g., across network boundaries).

    • Apply compression if bandwidth is limited, acknowledging that decompression will be required at the receiving end.
    • Once received, the IPC stream can be reconstructed into Arrow’s in-memory format for processing or sharing among local processes.
  • Use Apache Parquet when you need to persist data on disk efficiently for later retrieval and analysis.