clickhouse-jdbc

JDBC driver for ClickHouse

Github stars Tracking Chart

clickhouse-jdbc Build Status
ClickHouse JDBC driver

This is a basic and restricted implementation of jdbc driver for ClickHouse.
It has support of a minimal subset of features to be usable.

Usage

<dependency>
    <groupId>ru.yandex.clickhouse</groupId>
    <artifactId>clickhouse-jdbc</artifactId>
    <version>0.2</version>
</dependency>

URL syntax:
jdbc:clickhouse://<host>:<port>[/<database>], e.g. jdbc:clickhouse://localhost:8123/test

JDBC Driver Class:
ru.yandex.clickhouse.ClickHouseDriver

additionally, if you have a few instances, you can use BalancedClickhouseDataSource.

Extended API

In order to provide non-JDBC complaint data manipulation functionality, proprietary API exists.
Entry point for API is ClickHouseStatement#write() method.

Importing file into table

import ru.yandex.clickhouse.ClickHouseStatement;
ClickHouseStatement sth = connection.createStatement();
sth
    .write() // Write API entrypoint
    .table("default.my_table") // where to write data
    .option("format_csv_delimiter", ";") // specific param
    .data(new File("/path/to/file.csv"), ClickHouseFormat.CSV) // specify input
    .send();

Configurable send

import ru.yandex.clickhouse.ClickHouseStatement;
ClickHouseStatement sth = connection.createStatement();
sth
    .write()
    .sql("INSERT INTO default.my_table (a,b,c)")
    .data(new MyCustomInputStream(), ClickHouseFormat.JSONEachRow)
    .addDbParam(ClickHouseQueryParam.MAX_PARALLEL_REPLICAS, 2)
    .send();

Send data in binary formatd with custom user callback

import ru.yandex.clickhouse.ClickHouseStatement;
ClickHouseStatement sth = connection.createStatement();
sth.write().send("INSERT INTO test.writer", new ClickHouseStreamCallback() {
    @Override
    public void writeTo(ClickHouseRowBinaryStream stream) throws IOException {
        for (int i = 0; i < 10; i++) {
            stream.writeInt32(i);
            stream.writeString("Name " + i);
        }
    }
},
ClickHouseFormat.RowBinary); // RowBinary or Native are supported

Compiling with maven

The driver is built with maven.
mvn package -DskipTests=true

To build a jar with dependencies use

mvn package assembly:single -DskipTests=true

Build requirements

In order to build the jdbc client one need to have jdk 1.6 or higher.

Main metrics

Overview
Name With OwnerClickHouse/clickhouse-java
Primary LanguageJava
Program languageJava (Language Count: 2)
Platform
License:Apache License 2.0
所有者活动
Created At2016-07-15 12:48:27
Pushed At2025-05-05 17:12:37
Last Commit At
Release Count97
Last Release Namev0.8.5 (Posted on )
First Release Namerelease_0.1.13 (Posted on )
用户参与
Stargazers Count1.5k
Watchers Count54
Fork Count579
Commits Count3.5k
Has Issues Enabled
Issues Count1177
Issue Open Count208
Pull Requests Count956
Pull Requests Open Count1
Pull Requests Close Count191
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private