Description
ArrowStream is Apache Arrow’s “stream mode” format. It is designed for in-memory stream processing.
Example usage
In the example below we use theforex dataset which is available in the
ClickHouse SQL playground. You can connect to it
remotely with clickhouse-client using the host sql-clickhouse.clickhouse.com
and the user demo (which has no password). The forex table lives in the
forex database, so we select it as the default database:
forex table stores currency exchange rates. We can inspect its size and
how well it compresses on disk by querying system.columns:
Query
Response
Arrow “file mode” format, which
requires the whole result before it can be read, ArrowStream is delivered as a
sequence of record batches that a consumer can read incrementally as they
arrive. This makes it well suited to streaming a query result straight into a
visualization or analytics tool without first materializing the entire dataset.
To stream the result, send the query over ClickHouse’s HTTP interface with a
POST request and read the response as an Arrow stream. We disable compression
of the Arrow output via the
output_format_arrow_compression_method
setting so that consumers can decode batches directly as they are received.
The ArrowStream output is raw binary, so rather than printing it to the
terminal we pipe it into a consumer. The stream is self-describing (it carries
its own schema), so here we pipe it straight into
clickhouse-local, which reads the
incoming batches with --input-format ArrowStream and queries them as a table.
The forex table is large, so we bound the remote query with a WHERE
predicate and a LIMIT to keep this example small:
Response
RecordBatchReader yields each record batch as soon as it is streamed from the
server:
ArrowStream data from ClickHouse into a
real-time visualization with Perspective, see
the blog post
Streaming real-time visualizations with ClickHouse, Apache Arrow and Perspective.
Format settings
ArrowStream shares the same format settings as the Arrow format.