Java Code Examples for ru.yandex.clickhouse.ClickHouseDataSource#getConnection()

The following examples show how to use ru.yandex.clickhouse.ClickHouseDataSource#getConnection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClickHouseStatementImplTest.java    From clickhouse-jdbc with Apache License 2.0 6 votes vote down vote up
@Test
public void testResultSetWithExtremes() throws SQLException {
    ClickHouseProperties properties = new ClickHouseProperties();
    properties.setExtremes(true);
    ClickHouseDataSource dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    Connection connection = dataSource.getConnection();

    try {
        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery("select 1");
        StringBuilder sb = new StringBuilder();
        while (rs.next()) {
            sb.append(rs.getString(1)).append("\n");
        }

        Assert.assertEquals(sb.toString(), "1\n");
    } finally {
        connection.close();
    }
}
 
Example 2
Source File: RowBinaryStreamTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
}
 
Example 3
Source File: NativeStreamTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
}
 
Example 4
Source File: StreamSQLTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
}
 
Example 5
Source File: TimeZoneTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseDataSource datasourceServerTz = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", new ClickHouseProperties());
    connectionServerTz = datasourceServerTz.getConnection();
    TimeZone serverTimeZone = connectionServerTz.getTimeZone();
    ClickHouseProperties properties = new ClickHouseProperties();
    properties.setUseServerTimeZone(false);
    int serverTimeZoneOffsetHours = (int) TimeUnit.MILLISECONDS.toHours(serverTimeZone.getOffset(currentTime));
    int manualTimeZoneOffsetHours = serverTimeZoneOffsetHours - 1;
    properties.setUseTimeZone("GMT" + (manualTimeZoneOffsetHours > 0 ? "+" : "")  + manualTimeZoneOffsetHours + ":00");
    ClickHouseDataSource dataSourceManualTz = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connectionManualTz = dataSourceManualTz.getConnection();

    connectionServerTz.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
}
 
Example 6
Source File: ClickHouseDatabaseMetadataTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
}
 
Example 7
Source File: TSVStreamTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
}
 
Example 8
Source File: ClickhouseLZ4StreamTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    properties.setDecompress(true);
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
}
 
Example 9
Source File: CSVStreamTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
}
 
Example 10
Source File: ClickHousePreparedStatementTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
}
 
Example 11
Source File: BatchInsertsTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    ClickHouseDataSource dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
    dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setTimeZone(TimeZone.getDefault());
}
 
Example 12
Source File: OnTime.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
}
 
Example 13
Source File: ArrayTest.java    From clickhouse-jdbc with Apache License 2.0 4 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
}
 
Example 14
Source File: ClickHousePreparedStatementTest.java    From clickhouse-jdbc with Apache License 2.0 4 votes vote down vote up
@Test
public void testArrayOfNullable() throws Exception {
    connection.createStatement().execute("DROP TABLE IF EXISTS test.array_of_nullable");
    connection.createStatement().execute(
            "CREATE TABLE IF NOT EXISTS test.array_of_nullable (" +
                    "str Nullable(String), " +
                    "int Nullable(Int32), " +
                    "strs Array(Nullable(String)), " +
                    "ints Array(Nullable(Int32))) ENGINE = TinyLog"
    );

    PreparedStatement statement = connection.prepareStatement(
            "INSERT INTO test.array_of_nullable (str, int, strs, ints) VALUES (?, ?, ?, ?)"
    );

    statement.setObject(1, null);
    statement.setObject(2, null);
    statement.setObject(3, new String[]{"a", null, "c"});
    statement.setArray(4, new ClickHouseArray(ClickHouseDataType.Int32, new Integer[]{1, null, 3}));
    statement.addBatch();
    statement.executeBatch();

    ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM test.array_of_nullable");

    Assert.assertTrue(rs.next());
    Assert.assertNull(rs.getObject("str"));
    Assert.assertNull(rs.getObject("int"));
    Assert.assertEquals(rs.getArray("strs").getArray(), new String[]{"a", null, "c"});
    Assert.assertEquals(rs.getArray("ints").getArray(), new int[]{1, 0, 3});
    Assert.assertFalse(rs.next());

    ClickHouseProperties properties = new ClickHouseProperties();
    properties.setUseObjectsInArrays(true);
    ClickHouseDataSource configuredDataSource = new ClickHouseDataSource(dataSource.getUrl(), properties);
    ClickHouseConnection configuredConnection = configuredDataSource.getConnection();

    try {
        rs = configuredConnection.createStatement().executeQuery("SELECT * FROM test.array_of_nullable");
        rs.next();

        Assert.assertEquals(rs.getArray("ints").getArray(), new Integer[]{1, null, 3});
    } finally {
        configuredConnection.close();
    }
}
 
Example 15
Source File: ClickHouseStatementImplTest.java    From clickhouse-jdbc with Apache License 2.0 4 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {
    ClickHouseProperties properties = new ClickHouseProperties();
    dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123", properties);
    connection = dataSource.getConnection();
}