🛰️ ClickHouse Native Protocol Rust Client w/ Arrow Compatibility
ClickHouse access in rust over ClickHouse's native protocol.
Currently supports revision 54477, DBMS_MIN_REVISION_WITH_QUERY_PLAN_SERIALIZATION, the latest revision as of June 2025.
A high-performance, async Rust client for ClickHouse with native Arrow integration. Designed to be faster and more memory-efficient than existing alternatives.
Why clickhouse-arrow?
- 🚀 Performance: Optimized for speed with zero-copy deserialization where possible
- 🎯 Arrow Native: First-class Apache Arrow support for efficient data interchange
- 📊 90%+ Test Coverage: Comprehensive test suite ensuring reliability
- 🔄 Async/Await: Modern async API built on Tokio
- 🗜️ Compression: LZ4 and ZSTD support for efficient data transfer
- ☁️ Cloud Ready: Full
ClickHouseCloud compatibility - 🛡️ Type Safe: Compile-time type checking with the
#[derive(Row)]macro
Details
The crate supports two "modes" of operation:
ArrowFormat
Support allowing interoperability with arrow.
NativeFormat
Uses internal types and custom traits if a dependency on arrow is not required.
[!NOTE] I am considering putting arrow behind a feature flag to provide a subset of features without arrow dependencies. If that sounds interesting to you, let me know.
CreateOptions, SchemaConversions, and Schemas
Creating Tables from Arrow Schemas
clickhouse-arrow provides powerful DDL capabilities through CreateOptions, allowing you to create ClickHouse tables directly from Arrow schemas:
use ;
use ;
// Define your Arrow schema
let schema = new;
// Configure table creation
let options = new
.with_order_by
.with_partition_by
.with_setting;
// Create the table
client.create_table.await?;
Schema Conversions for Type Control
SchemaConversions (type alias for HashMap<String, Type>) provides fine-grained control over Arrow-to-ClickHouse type mappings. This is especially important for:
- Converting Dictionary → Enum: By default, Arrow Dictionary types map to
LowCardinality(String). UseSchemaConversionsto map them toEnum8orEnum16instead:
use ;
use HashMap;
let schema_conversions = from;
let options = new
.with_order_by
.with_schema_conversions;
- Geo Types: Preserve geographic types during conversion
- Date Types: Choose between
DateandDate32 - Custom Type Mappings: Override any default type conversion
Field Naming Constants
When working with complex Arrow types, use these constants to ensure compatibility:
use *;
// For List types - inner field is named "item"
let list_field = new;
// For Struct/Tuple types - fields are named "field_0", "field_1", etc.
let tuple_fields = vec!;
// For Map types - uses specific field names
let map_type = Map;
These constants ensure your Arrow schemas align with ClickHouse's expectations and maintain compatibility with arrow-rs conventions.
Performance & Benchmarks
Benchmark Results
The following benchmarks were run on [TODO: Remove - Add your machine specs, e.g., M2 MacBook Pro, 16GB RAM]:
Insert Performance
[TODO: Remove - Add insert benchmark results]
Query Performance
[TODO: Remove - Add query benchmark results]
Memory Usage
[TODO: Remove - Add memory usage comparisons]
Key Performance Features
- Compression Benefits: LZ4/ZSTD compression often improves performance over remote networks due to reduced network I/O and can sometimes speed up even on localhost due to deterministic deserialization patterns
- Zero-Copy: Arrow integration enables zero-copy data transfer where possible
- Streaming: Large datasets are processed in chunks to maintain low memory footprint
- Connection Pooling: The
poolfeature enables connection reuse for better throughput
Running Benchmarks
# Run all benchmarks
&&
# Run specific benchmark
&&
# Run with release-lto profile for best performance
&&
Queries
Query Settings
The clickhouse_arrow::Settings type allows configuring ClickHouse query settings. You can import it directly:
use Settings;
// or via prelude
use *;
Refer to the settings module documentation for details and examples.
Arrow Round-Trip
There are cases where a round trip may deserialize a different type by schema or array than the schema and array you used to create the table.
will try to maintain an accurate and updated list as they occur. In addition, when possible, I will provide options or other functionality to alter this behavior.
(String|Binary)View/Large(List|String|Binary) variations are normalized.
- Behavior:
ClickHousedoes not make the same distinction betweenUtf8,Utf8View, orLargeUtf8. All of these are mapped to eitherType::Binary(the default, see above) orType::String - Option: None
- Default: Unsupported
- Impact: When deserializing from
ClickHouse, manual modification will be necessary to use these data types.
Utf8 -> Binary
- Behavior: By default,
Type::String/DataType::Utf8will be represented as Binary. - Option:
strings_as_strings(default:false). - Default: Disabled (
false). - Impact: Set to
trueto strip mapType::String->DataType::Utf8. Binary tends to be more efficient to work with in high throughput scenarios
Nullable Arrays
- Behavior:
ClickHousedoes not allowNullable(Array(...)), but insertion with non-null data is allowed by default. To modify this behavior, setarray_nullable_errortotrue. - Option:
array_nullable_error(default:false). - Default: Disabled (
false). - Impact: Enables flexible insertion but may cause schema mismatches if nulls are present.
LowCardinality(Nullable(...)) vs Nullable(LowCardinality(...))
- Behavior: Like arrays mentioned above,
ClickHousedoes not allow nullable low cardinality. The default behavior is to push down the nullability. - Option:
low_cardinality_nullable_error(default:false). - Default: Disabled (
false). - Impact: Enables flexible insertion but may cause schema mismatches if nulls are present.
Enum8/Enum16 vs. LowCardinality
- Behavior: Arrow
Dictionarytypes map toLowCardinality, butClickHouseEnumtypes may also map toDictionary, altering the type on round-trip. - Option: No options available rather provide hash maps for either
enum_i8and/orenum_i16forCreateOptionsduring schema creation. - Impact: The default behavior will ignore enums when starting from arrow.
[!NOTE] For examples of these cases, refer to the tests in the module arrow::types
[!NOTE] The configuration for the options above can be found in options
[!NOTE] For a builder of create options use during schema creation (eg
Engine,Order By,Enum8andEnum16lookups), refer to CreateOptions