• Stars
    star
    287
  • Rank 138,917 (Top 3 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 26 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C++ client library for ClickHouse

ClickHouse C++ client Linux macOS Windows MSVC Windows mingw

C++ client for ClickHouse.

Supported data types

  • Array(T)
  • Date
  • DateTime, DateTime64
  • DateTime([timezone]), DateTime64(N, [timezone])
  • Decimal32, Decimal64, Decimal128
  • Enum8, Enum16
  • FixedString(N)
  • Float32, Float64
  • IPv4, IPv6
  • Nullable(T)
  • String
  • LowCardinality(String) or LowCardinality(FixedString(N))
  • Tuple
  • UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64
  • Int128
  • UUID
  • Map
  • Point, Ring, Polygon, MultiPolygon

Dependencies

In the most basic case one needs only:

  • a C++-17-complaint compiler,
  • cmake (3.12 or newer), and
  • ninja

Optional dependencies:

  • openssl
  • liblz4
  • libabsl

Building

$ mkdir build .
$ cd build
$ cmake .. [-DBUILD_TESTS=ON]
$ make

Plese refer to the workflows for the reference on dependencies/build options

Example application build with clickhouse-cpp

There are various ways to integrate clickhouse-cpp with the build system of an application. Below example uses the simple approach based on submodules presented in https://www.youtube.com/watch?v=ED-WUk440qc .

  • mkdir clickhouse-app && cd clickhouse-app && git init
  • git submodule add https://github.com/ClickHouse/clickhouse-cpp.git contribs/clickhouse-cpp
  • touch app.cpp, then copy the following C++ code into that file
#include <iostream>
#include <clickhouse/client.h>

using namespace clickhouse;

int main()
{
    /// Initialize client connection.
    Client client(ClientOptions().SetHost("localhost"));

    /// Create a table.
    client.Execute("CREATE TABLE IF NOT EXISTS default.numbers (id UInt64, name String) ENGINE = Memory");

    /// Insert some values.
    {
        Block block;

        auto id = std::make_shared<ColumnUInt64>();
        id->Append(1);
        id->Append(7);

        auto name = std::make_shared<ColumnString>();
        name->Append("one");
        name->Append("seven");

        block.AppendColumn("id"  , id);
        block.AppendColumn("name", name);

        client.Insert("default.numbers", block);
    }

    /// Select values inserted in the previous step.
    client.Select("SELECT id, name FROM default.numbers", [] (const Block& block)
        {
            for (size_t i = 0; i < block.GetRowCount(); ++i) {
                std::cout << block[0]->As<ColumnUInt64>()->At(i) << " "
                          << block[1]->As<ColumnString>()->At(i) << "\n";
            }
        }
    );

    /// Delete table.
    client.Execute("DROP TABLE default.numbers");

    return 0;
}
  • touch CMakeLists.txt, then copy the following CMake code into that file
cmake_minimum_required(VERSION 3.12)
project(application-example)

set(CMAKE_CXX_STANDARD 17)

add_subdirectory(contribs/clickhouse-cpp)

add_executable(${PROJECT_NAME} "app.cpp")

target_include_directories(${PROJECT_NAME} PRIVATE contribs/clickhouse-cpp/ contribs/clickhouse-cpp/contrib/absl)

target_link_libraries(${PROJECT_NAME} PRIVATE clickhouse-cpp-lib)
  • run rm -rf build && cmake -B build -S . && cmake --build build -j32 to remove remainders of the previous builds, run CMake and build the application. The generated binary is located in location build/application-example.

Thread-safety

⚠ Please note that Client instance is NOT thread-safe. I.e. you must create a separate Client for each thread or utilize some synchronization techniques. ⚠

Retries

If you wish to implement some retry logic atop of clickhouse::Client there are few simple rules to make you life easier:

  • If previous attempt threw an exception, then make sure to call clickhouse::Client::ResetConnection() before the next try.
  • For clickhouse::Client::Insert() you can reuse a block from previous try, no need to rebuild it from scratch.

See #184 for details.

More Repositories

1

ClickHouse

ClickHouse® is a free analytics DBMS for big data
C++
33,966
star
2

clickhouse-go

Golang driver for ClickHouse
Go
2,709
star
3

clickhouse-java

Java client and JDBC driver for ClickHouse
Java
1,324
star
4

clickhouse-presentations

Presentations, meetups and talks about ClickHouse
HTML
931
star
5

ClickBench

ClickBench: a Benchmark For Analytical Databases
HTML
542
star
6

metabase-clickhouse-driver

ClickHouse database driver for the Metabase business intelligence front-end
Clojure
439
star
7

clickhouse_exporter

This is a simple server that periodically scrapes ClickHouse stats and exports them via HTTP for Prometheus(https://prometheus.io/) consumption.
Go
354
star
8

ch-go

Low-level Go Client for ClickHouse
Go
295
star
9

NoiSQL

NoiSQL — Generating Music With SQL Queries
SQL
272
star
10

graphouse

Graphouse allows you to use ClickHouse as a Graphite storage.
Java
257
star
11

clickhouse-connect

Python driver/sqlalchemy/superset connectors
Python
241
star
12

clickhouse-odbc

ODBC driver for ClickHouse
C++
235
star
13

dbt-clickhouse

The Clickhouse plugin for dbt (data build tool)
Python
201
star
14

clickhouse-jdbc-bridge

A JDBC proxy from ClickHouse to external databases
Java
156
star
15

clickhouse-js

Official JS client for ClickHouse DB
TypeScript
152
star
16

github-explorer

Everything You Always Wanted To Know About GitHub (But Were Afraid To Ask)
HTML
129
star
17

clickhouse-kafka-connect

ClickHouse Kafka Connector
Java
126
star
18

clickhouse-docs

Official documentation for ClickHouse
JavaScript
86
star
19

examples

ClickHouse Examples
Jupyter Notebook
67
star
20

click-ui

The home of the ClickHouse design system and component library.
TypeScript
59
star
21

homebrew-clickhouse

ClickHouse Homebrew tap (old repository, unused)
58
star
22

clickhouse-tableau-connector-jdbc

Tableau connector to ClickHouse using JDBC driver
JavaScript
55
star
23

pastila

Paste toy-service on top of ClickHouse
HTML
43
star
24

power-bi-clickhouse

This connector allows you to retrieve data from ClickHouse directly into Power BI for analysis and visualization
41
star
25

libhdfs3

HDFS file read access for ClickHouse
C++
27
star
26

ch-bench

Benchmarks for ch
Go
27
star
27

HouseClick

House prices app
JavaScript
22
star
28

sysroot

Files for cross-compilation
C
18
star
29

clickpy

PyPI analytics powered by ClickHouse
JavaScript
18
star
30

terraform-provider-clickhouse

Terraform Provider for ClickHouse Cloud
Go
17
star
31

web-tables-demo

15
star
32

clickhub

Github analytics powered by the world's fastest real-time analytics database
Python
14
star
33

icudata

Pregenerated data for ICU library
Assembly
10
star
34

reversedns.space

https://reversedns.space/
HTML
9
star
35

clickhouse-website-worker

TypeScript
8
star
36

laion

Supporting code for inserting and searching laion in ClickHouse
Python
6
star
37

checkout

Wrapper around actions/checkout for flexible tuning
5
star
38

aretestsgreenyet

A single-page website to display the status of the open-source ClickHouse CI system.
HTML
4
star
39

fuzz-corpus

Corpuses for libFuzzer-type fuzzers
4
star
40

ch-async-inserts-demo

Demo on how to create a Node API that sends data to CH via Async inserts
TypeScript
4
star
41

clickhouse-playground-old

4
star
42

1trc

1 trillion rows
Python
4
star
43

clickhouse_vs_snowflake

HTML
3
star
44

clickhouse-website-content

JavaScript
3
star
45

clickhouse-academy

ClickHouse Academy training and certification
3
star
46

kafka-samples

Sample datasets for Kafka
Python
3
star
47

clickhouse-recipes

Sample code for solving common problems with ClickHouse
Python
3
star
48

bedrock_rag

A simple RAG pipeline for Google Analytics with ClickHouse and Bedrock
Python
3
star
49

protobuf

add protobuf for libhdfs3
C++
2
star
50

clickhouse-com-content

HTML
2
star
51

antlr4-runtime

Subtree of antlr4 original repo
C++
2
star
52

grpc

Stripped version of grpc
C++
2
star
53

clickhouse.github.io

HTML
2
star
54

ssl

Minimized libressl
C
2
star
55

libpq

Copy of https://github.com/postgres/postgres/tree/master/src/interfaces/libpq with some files from root
C
2
star
56

llvm

Stripped version of LLVM for use in ClickHouse for runtime code generation.
C++
2
star
57

copier

clickhouse-copier (obsolete)
C++
2
star
58

hive-metastore

For files generated with https://github.com/apache/thrift
Thrift
1
star
59

doc-pr-preview-test

Testing workflow to build Docusaurus previews for pull requests.
JavaScript
1
star
60

UnixODBC

Mirror of http://www.unixodbc.org/
C
1
star
61

clickhouse-docs-content

1
star
62

clickhouse-blog-images

HTML
1
star
63

bzip2

Forked from https://gitlab.com/federicomenaquintero/bzip2
C
1
star
64

libgsasl

https://www.gnu.org/software/gsasl/
C
1
star
65

readthedocs-stub

HTML
1
star
66

boost

Minimized boost lib
C++
1
star
67

clickhouse-repos-manager

a config and artifacts for packages.clickhouse.com
Python
1
star
68

clickhouse-kafka-transforms

This is meant to hold Clickhouse created kafka transforms.
Java
1
star
69

clickhouse-fivetran-destination

ClickHouse Cloud Fivetran Destination
Go
1
star
70

clickhouse-test.github.io

HTML
1
star
71

rust_vendor

Vendor files from rust dependencies
Rust
1
star
72

simple-logging-benchmark

A simple ClickHouse benchmark for the logging usecase
Python
1
star
73

clickhouse-typescript-schema

TypeScript
1
star