Usage

Connecting

Connect to the server's native TCP port, normally 9000. This client uses unencrypted native TCP. It cannot connect to an HTTPS endpoint or an encrypted native TCP endpoint, such as the ClickHouse playground.

julia> using ClickHouse
julia> sock = ClickHouse.connect("localhost", 9000; compression = ClickHouse.COMPRESSION_LZ4);

Executing DDL

Creating a table

This temporary table lasts until the connection closes. Reuse the same socket for the following queries.

julia> ClickHouse.execute(sock, """
           CREATE TEMPORARY TABLE MyTable
               (u UInt64, f Float32, s String)
           ENGINE = Memory
       """)

Inserting data

julia> data = Dict(
           :u => UInt64[42, 1337, 123],
           :f => Float32[0., ℯ, π],
           :s => String["aa", "bb", "cc"],
       );
julia> ClickHouse.insert(sock, "MyTable", [data])

Selecting data

... into a dict of (column, data) pairs

julia> ClickHouse.select(sock, "SELECT * FROM MyTable LIMIT 3")Dict{Symbol, Any} with 3 entries:
  :f => Float32[0.0, 2.71828, 3.14159]
  :s => ["aa", "bb", "cc"]
  :u => UInt64[0x000000000000002a, 0x0000000000000539, 0x000000000000007b]

... into a DataFrame

julia> ClickHouse.select_df(sock, "SELECT * FROM MyTable LIMIT 3")3×3 DataFrame
 Row │ f        s       u      
     │ Float32  String  UInt64 
─────┼─────────────────────────
   1 │ 0.0      aa          42
   2 │ 2.71828  bb        1337
   3 │ 3.14159  cc         123

... streaming through a channel

julia> for block in ClickHouse.select_channel(sock, "SELECT * FROM MyTable LIMIT 1")
           @show block
       endblock = Dict{Symbol, Any}(:f => Float32[0.0], :s => ["aa"], :u => UInt64[0x000000000000002a])

... streaming each block into a callback

This is the fastest way to stream blocks and is used under the hood to implement all other select_xyz implementations.

julia> ClickHouse.select_callback(sock, "SELECT * FROM MyTable LIMIT 1") do block
           @show block
       endblock = Dict{Symbol, Any}(:f => Float32[0.0], :s => ["aa"], :u => UInt64[0x000000000000002a])