Search Shortcut cmd + k | ctrl + k
chsql_native

ClickHouse Native Client & File Reader for chsql

Installing and Loading

INSTALL chsql_native FROM community;
LOAD chsql_native;

Example

--- This experimental rust extension implements Native Clickhouse formats for DuckDB.
--- ClickHouse Native Binary Client for chsql
--- export CLICKHOUSE_URL="tcp://localhost:9000"
--- export CLICKHOUSE_URL="tcp://user:pass@remote:9440/?secure=true&skip_verify=true"
--- Simple Query Example
D SELECT * FROM clickhouse_scan("SELECT version(), 'hello', 123");
┌────────────┬─────────┬────────┐
 version()   'hello'   123   
  varchar    varchar  uint32 
├────────────┼─────────┼────────┤
 24.10.2.80  hello       123 
└────────────┴─────────┴────────┘

--- Wide Query Example
D SELECT * FROM clickhouse_scan("SELECT * FROM system.functions WHERE alias_to != '' LIMIT 10");
┌────────────────────┬──────────────┬──────────────────┬──────────────────────┬───┬───────────┬────────────────┬──────────┬────────────┐
        name         is_aggregate  case_insensitive        alias_to          arguments  returned_value  examples  categories 
      varchar           uint32          uint32             varchar             varchar      varchar      varchar    varchar   
├────────────────────┼──────────────┼──────────────────┼──────────────────────┼───┼───────────┼────────────────┼──────────┼────────────┤
 connection_id                  0                 1  connectionID                                                            
 rand32                         0                 0  rand                                                                    
 INET6_ATON                     0                 1  IPv6StringToNum                                                         
 INET_ATON                      0                 1  IPv4StringToNum                                                         
 truncate                       0                 1  trunc                                                                   
 ceiling                        0                 1  ceil                                                                    
 replace                        0                 1  replaceAll                                                              
 from_utc_timestamp             0                 1  fromUTCTimestamp                                                        
 mapFromString                  0                 0  extractKeyValuePairs                                                    
 str_to_map                     0                 1  extractKeyValuePairs                                                    
├────────────────────┴──────────────┴──────────────────┴──────────────────────┴───┴───────────┴────────────────┴──────────┴────────────┤
 10 rows                                                                                                         12 columns (8 shown) 
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘


--- Native File Reader for chsql
--- Test files can be generated with clickhouse-local. File reads are full-scans.

--- Simple Example
D SELECT * FROM clickhouse_native('/tmp/numbers.clickhouse');
┌──────────────┬─────────┐
  version()    number  
   varchar      int32  
├──────────────┼─────────┤
 24.12.1.1273  0       
└──────────────┴─────────┘

--- Long Example
D SELECT count(*), max(number) FROM clickhouse_native('/tmp/100000.clickhouse');
┌──────────────┬─────────────┐
 count_star()  max(number) 
    int64         int32    
├──────────────┼─────────────┤
       100000        99999 
└──────────────┴─────────────┘

--- Wide Example
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) 
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

About chsql_native

This extension is highly experimental and potentially unstable. Do not use in production. See README for full examples.

Added Functions

function_name function_type description comment example
clickhouse_native table