This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Rust workspace containing two crates:
clickhouse-arrow: High-performance ClickHouse client with native protocol and Arrow integrationclickhouse-arrow-derive: Procedural macros for theRowderive
The project focuses on efficient data operations with ClickHouse while maintaining compatibility with the Arrow ecosystem.
# Build all workspace members
cargo build
# Build with all features
cargo build --all-features
# Build release with optimizations
cargo build --release
# Build with LTO for maximum performance
cargo build --profile release-lto# Run all tests (requires test-utils feature for integration tests)
cargo test --features test-utils
# Run specific integration test suites
cargo test --test e2e_arrow --features test-utils
cargo test --test e2e_native --features "test-utils,derive"
# Run with output visible
cargo test --features test-utils -- --nocapture# Format code
cargo fmt
# Run clippy with all features
cargo clippy --all-features --all-targets
# Fix clippy warnings
cargo clippy --fixAll examples require the test-utils feature:
cargo run --example select --features test-utils
cargo run --example insert --features test-utils
cargo run --example pool --features test-utils
# Control number of runs
EXAMPLE_RUNS=50 cargo run --example insert --features test-utilscargo bench --features test-utils
cargo bench --bench insert --features test-utils
cargo bench --bench query --features test-utils-
Client Module (
src/client/)builder.rs: ClientBuilder for connection configurationmod.rs: Main client implementation with query/insert methods- Connection pooling via bb8 (optional feature)
-
Protocol Implementation (
src/native/)- Native ClickHouse wire protocol
- Packet encoding/decoding
- Compression support (LZ4, ZSTD)
-
Data Formats
- Arrow Format (
src/arrow/): Arrow RecordBatch integration - Native Format (
src/formats/): Internal type system
- Arrow Format (
-
Type System (
src/types/)- Comprehensive ClickHouse type support
- Arrow type mapping and conversion
- Special handling for LowCardinality, Nullable, Arrays
- Format Abstraction:
ArrowFormatandNativeFormattraits allow switching between Arrow and native representations - Streaming: All queries return async streams for memory-efficient data processing
- Zero-Copy: Optimized for minimal allocations during data transfer
- Builder Pattern: Consistent API for client configuration
-
Arrow Round-Trip Considerations:
Utf8types default toBinaryfor performance (configurable viastrings_as_strings)Nullable(Array)is converted toArray(Nullable)by defaultDictionarytypes map toLowCardinality
-
Compression: Automatically negotiated with server, supports LZ4 and ZSTD
-
Connection Pooling: Optional bb8-based pooling with the
poolfeature -
Feature Flags:
derive: Enable Row derive macroserde: JSON serialization supportpool: Connection poolinginner_pool: Spawns multiple "inner connections" for improved concurrencycloud: ClickHouse Cloud supporttest-utils: Required for tests/examples/benchmarks
- Unit tests are inline with modules
- Integration tests require a ClickHouse container (handled automatically by testcontainers)
- E2E tests cover Arrow format, native format, compatibility, and row binary
- Benchmarks measure insert/query performance and compression
- The project uses Rust 2024 edition
- Extensive clippy lints are configured in the workspace Cargo.toml
- Custom disallowed methods are defined in clippy.toml
- Test containers are automatically managed, set
DISABLE_CLEANUP=trueto keep containers running