DuckDB Clickhouse Native Extension for chsql
Experimental ClickHouse Native Client and Native file reader for DuckDB chsql
INSTALL chsql_native FROM community;
LOAD chsql_native;
The extension provides an experimental clickhouse native client: clickhouse_scan
# Local Setup, Insecure
export CLICKHOUSE_URL="tcp://localhost:9000"
# Remote Setup, Secure
export CLICKHOUSE_URL="tcp://user:pass@remote:9440/?secure=true&skip_verify=true"
D SELECT * FROM clickhouse_scan("SELECT version(), 'hello', 123");
โโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโ
โ version() โ 'hello' โ 123 โ
โ varchar โ varchar โ uint32 โ
โโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ 24.10.2.80 โ hello โ 123 โ
โโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโ
The extension provides an experimental clickhouse native file reader: clickhouse_native
Generate some native files with clickhouse-local
or clickhouse-server
--- simple w/ one row, two columns
SELECT version(), number FROM numbers(1) INTO OUTFILE '/tmp/numbers.clickhouse' FORMAT Native;
--- simple w/ one column, 100000 rows
SELECT number FROM numbers(100000) INTO OUTFILE '/tmp/100000.clickhouse' FORMAT Native;
--- complex w/ multiple types
SELECT * FROM system.functions LIMIT 10 INTO OUTFILE '/tmp/functions.clickhouse' FORMAT Native;
Read ClickHouse Native files with DuckDB. Reads are full-scans at this time.
D SELECT * FROM clickhouse_native('/tmp/numbers.clickhouse');
โโโโโโโโโโโโโโโโฌโโโโโโโโโโ
โ version() โ number โ
โ varchar โ int32 โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโค
โ 24.12.1.1273 โ 0 โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโ
D SELECT count(*), max(number) FROM clickhouse_native('/tmp/100000.clickhouse');
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ count_star() โ max(number) โ
โ int64 โ int32 โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโค
โ 100000 โ 99999 โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
D SELECT * FROM clickhouse_native('/tmp/functions.clickhouse') WHERE alias_to != '' LIMIT 10;
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ name โ is_aggregate โ case_insensitive โ alias_to โ create_query โ origin โ โฆ โ syntax โ arguments โ returned_value โ examples โ categories โ
โ varchar โ int32 โ int32 โ varchar โ varchar โ varchar โ โ varchar โ varchar โ varchar โ varchar โ varchar โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโผโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโค
โ connection_id โ 0 โ 1 โ connectionID โ โ System โ โฆ โ โ โ โ โ โ
โ rand32 โ 0 โ 0 โ rand โ โ System โ โฆ โ โ โ โ โ โ
โ INET6_ATON โ 0 โ 1 โ IPv6StringToNum โ โ System โ โฆ โ โ โ โ โ โ
โ INET_ATON โ 0 โ 1 โ IPv4StringToNum โ โ System โ โฆ โ โ โ โ โ โ
โ truncate โ 0 โ 1 โ trunc โ โ System โ โฆ โ โ โ โ โ โ
โ ceiling โ 0 โ 1 โ ceil โ โ System โ โฆ โ โ โ โ โ โ
โ replace โ 0 โ 1 โ replaceAll โ โ System โ โฆ โ โ โ โ โ โ
โ from_utc_timestamp โ 0 โ 1 โ fromUTCTimestamp โ โ System โ โฆ โ โ โ โ โ โ
โ mapFromString โ 0 โ 0 โ extractKeyValuePairs โ โ System โ โฆ โ โ โ โ โ โ
โ str_to_map โ 0 โ 1 โ extractKeyValuePairs โ โ System โ โฆ โ โ โ โ โ โ
โโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโดโโโโดโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโค
โ 10 rows 12 columns (11 shown) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The reader is a clear room implementation of the ClickHouse Native file format using no code or libraries from ClickHouse Inc. As such it is potentially incomplete, imperfect and might not be compatible with all files. USE AT YOUR OWN RISK!
Simple CLI cold start count() test using duckdb
vs. clickhouse-local
and 1M rows
# time duckdb -c "LOAD chsql_native; SELECT count(*) FROM clickhouse_native('/tmp/1M.clickhouse');"
โโโโโโโโโโโโโโโโ
โ count_star() โ
โ int64 โ
โโโโโโโโโโโโโโโโค
โ 1000000 โ
โโโโโโโโโโโโโโโโ
real 0m0.095s
user 0m0.077s
sys 0m0.029s
# time clickhouse local "SELECT count(*) FROM '/tmp/1M.clickhouse'";
1000000
real 0m0.141s
user 0m0.086s
sys 0m0.043s
- Basic Fomat Reading
- Column Extraction
- Blocks Parser & Iterator
- Type Mapping WIP
- Strings
- Integers
- Enums
- ??? as String
- Compression support
- Basic Native Client
- clickhouse-rs binding
- TLS Support
- Type Mapping WIP
- Strings
- Integers
- Everything Else
You can easily modify the code and build a local extension for testing and development.
- Rust
- Clone and Compile the extension on your system
cd /usr/src
git clone --recurse-submodules https://github.com/quackscience/duckdb-extension-clickhouse-native
cd duckdb-extension-clickhouse-native
make configure && make
- Download and Run DuckDB with -unsigned
wget https://github.com/duckdb/duckdb/releases/download/v1.1.3/duckdb_cli-linux-amd64.zip && unzip duckdb_cli-linux-amd64.zip
./duckdb -unsigned
- Load your local extension build
D LOAD '/usr/src/duckdb-extension-clickhouse-native/build/debug/clickhouse_native.duckdb_extension';
DuckDB ยฎ is a trademark of DuckDB Foundation. ClickHouseยฎ is a trademark of ClickHouse Inc. All trademarks, service marks, and logos mentioned or depicted are the property of their respective owners. The use of any third-party trademarks, brand names, product names, and company names is purely informative or intended as parody and does not imply endorsement, affiliation, or association with the respective owners.