timeplus-io / timeplus-native-jdbc

Timeplus JDBC driver which speaks native TCP protocol to Timeplus Core
Apache License 2.0
0 stars 0 forks source link

Timeplus Native JDBC

A Native JDBC library for accessing Timeplus in Java with streaming SQL support.

This is a fork of https://github.com/housepower/ClickHouse-Native-JDBC, but revised and enhanced for streaming query processing. If you don't need to run streaming SQL or has lower performance need, you may also use https://github.com/timeplus-io/proton-java-driver.

CONTRIBUTE

We welcome anyone that wants to help out in any way, whether that includes reporting problems, helping with documentations, or contributing code changes to fix bugs, add tests, or implement new features. Please follow Contributing Guide.

JDBC Driver

Requirements

Notes: We only do test with Java LTS versions.

Limitations

Import

<dependency>
    <groupId>com.timeplus</groupId>
    <artifactId>timeplus-native-jdbc</artifactId>
    <version>${timeplus-native-jdbc.version}</version>
</dependency>

Or use the shade version with dependencies packed in the same JAR.

<dependency>
    <groupId>com.timeplus</groupId>
    <artifactId>timeplus-native-jdbc-shaded</artifactId>
    <version>${timeplus-native-jdbc.version}</version>
</dependency>

Example Code

Unlike the Proton JDBC Driver which only supports batch query, this JDBC driver talks to the native port of Timeplus and support streaming SQL. The query will be long running and you can get latest results from the JDBC ResultSet.

Here is an example to run a DDL to create a random stream, then run a streaming SQL to list all events.

package test_jdbc_driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class App {

    public static void main(String[] args) throws Exception {
        String url = "jdbc:timeplus://localhost:8463";
        try (Connection connection = DriverManager.getConnection(url)) {
            try (Statement stmt = connection.createStatement()) {
                stmt.executeQuery(
                    "create random stream if not exists simple_random(i int, s string) settings eps=3"
                );
                try (
                    ResultSet rs = stmt.executeQuery(
                        "SELECT * FROM simple_random"
                    )
                ) {
                    while (rs.next()) {
                        System.out.println(
                            rs.getInt(1) + "\t" + rs.getString(2)
                        );
                    }
                }
            }
        }
    }
}

License

This project is distributed under the terms of the Apache License (Version 2.0). See LICENSE for details.