Skip to content

Commit bbfca81

Browse files
committed
Merge branch 'roaringbitmap' of github.com:zhicwu/clickhouse-jdbc into roaringbitmap
2 parents 3fc7aa1 + 411874f commit bbfca81

File tree

6 files changed

+47
-18
lines changed

6 files changed

+47
-18
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ jobs:
108108
continue-on-error: true
109109
- name: Build project
110110
run: |
111+
mvn --batch-mode --update-snapshots -DskipTests -pl clickhouse-benchmark -am package
111112
cd clickhouse-benchmark
112113
java -jar target/benchmarks.jar -rf json ${{ github.event.inputs.options }} > output.txt
113114
echo "BENCHMARK_REPORT<<EOF" >> $GITHUB_ENV

clickhouse-benchmark/src/main/java/tech/clickhouse/benchmark/Basic.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import java.sql.ResultSet;
44
import java.sql.Statement;
55
import java.util.Collections;
6+
import java.util.Random;
67
import org.openjdk.jmh.annotations.Benchmark;
78

89
public class Basic extends JdbcBenchmark {
910
@Benchmark
1011
public int selectOneRandomNumber(ClientState state) throws Throwable {
11-
final int num = (int) (Math.random() * 1000);
12+
final int num = new Random().nextInt(1000);
1213

1314
try (Statement stmt = executeQuery(state, "select ? as n", num)) {
1415
ResultSet rs = stmt.getResultSet();
@@ -25,7 +26,7 @@ public int selectOneRandomNumber(ClientState state) throws Throwable {
2526

2627
@Benchmark
2728
public int insertOneRandomNumber(ClientState state) throws Throwable {
28-
final int num = (int) (Math.random() * 1000);
29+
final int num = new Random().nextInt(1000);
2930

3031
return executeInsert(state, "insert into test_insert(i) values(?)",
3132
Collections.enumeration(Collections.singletonList(new Object[] { num })));

clickhouse-benchmark/src/main/java/tech/clickhouse/benchmark/Insertion.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
import java.sql.Timestamp;
44
// import java.util.Collections;
55
import java.util.Enumeration;
6+
import java.util.Random;
67
import org.openjdk.jmh.annotations.Benchmark;
78

89
public class Insertion extends JdbcBenchmark {
910
// @Benchmark
1011
// public int insertOneNumber(ClientState state) throws Throwable {
1112
// return executeInsert(state, "insert into test_insert(i) values(?)",
12-
// Collections.enumeration(Collections.singletonList(new Object[] { (int)
13-
// (Math.random() * 1000) })));
13+
// Collections.enumeration(Collections.singletonList(new Object[] { new
14+
// Random().nextInt(1000) })));
1415
// }
1516

1617
@Benchmark
1718
public int insert10kUInt64Rows(ClientState state) throws Throwable {
1819
final int rows = 10000;
19-
final int num = (int) (Math.random() * rows);
20+
final int num = new Random().nextInt(rows);
2021

2122
return executeInsert(state, "insert into test_insert(i) values(?)", new Enumeration<Object[]>() {
2223
int counter = 0;
@@ -36,7 +37,7 @@ public Object[] nextElement() {
3637
@Benchmark
3738
public int insert10kStringRows(ClientState state) throws Throwable {
3839
final int rows = 10000;
39-
final int num = (int) (Math.random() * rows);
40+
final int num = new Random().nextInt(rows);
4041

4142
return executeInsert(state, "insert into test_insert(s) values(?)", new Enumeration<Object[]>() {
4243
int counter = 0;
@@ -56,7 +57,7 @@ public Object[] nextElement() {
5657
@Benchmark
5758
public int insert10kTimestampRows(ClientState state) throws Throwable {
5859
final int rows = 10000;
59-
final int num = (int) (Math.random() * rows);
60+
final int num = new Random().nextInt(rows);
6061

6162
return executeInsert(state, "insert into test_insert(t) values(?)", new Enumeration<Object[]>() {
6263
int counter = 0;
@@ -68,7 +69,7 @@ public boolean hasMoreElements() {
6869

6970
@Override
7071
public Object[] nextElement() {
71-
return new Object[] { new Timestamp(num + (counter++)) };
72+
return new Object[] { new Timestamp((long) num + (counter++)) };
7273
}
7374
});
7475
}

clickhouse-benchmark/src/main/java/tech/clickhouse/benchmark/JdbcBenchmark.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,17 @@ protected Statement executeQuery(ClientState state, String sql, Object... values
114114
final Connection conn = state.getConnection();
115115

116116
if (state.usePreparedStatement()) {
117-
PreparedStatement s = conn.prepareStatement(sql);
118-
s.setFetchSize(fetchSize);
119-
setParameters(s, values).executeQuery();
120-
stmt = s;
117+
try (PreparedStatement s = conn.prepareStatement(sql)) {
118+
stmt = s;
119+
s.setFetchSize(fetchSize);
120+
setParameters(s, values).executeQuery();
121+
}
121122
} else {
122-
stmt = conn.createStatement();
123-
stmt.setFetchSize(fetchSize);
124-
stmt.executeQuery(replaceParameters(sql, values));
123+
try (Statement s = conn.createStatement()) {
124+
stmt = s;
125+
stmt.setFetchSize(fetchSize);
126+
stmt.executeQuery(replaceParameters(sql, values));
127+
}
125128
}
126129

127130
return stmt;

clickhouse-benchmark/src/main/java/tech/clickhouse/benchmark/Query.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import java.sql.ResultSet;
44
import java.sql.Statement;
55
import java.sql.Timestamp;
6+
import java.util.Random;
67
import org.openjdk.jmh.annotations.Benchmark;
78

89
public class Query extends JdbcBenchmark {
910
@Benchmark
1011
public int select10kUInt64Rows(ClientState state) throws Throwable {
1112
int rows = 10000;
12-
int num = (int) (Math.random() * rows);
13+
int num = new Random().nextInt(rows);
1314
try (Statement stmt = executeQuery(state, "select * from system.numbers where number > ? limit " + rows, num)) {
1415
ResultSet rs = stmt.getResultSet();
1516

@@ -30,7 +31,7 @@ public int select10kUInt64Rows(ClientState state) throws Throwable {
3031
@Benchmark
3132
public int select10kStringRows(ClientState state) throws Throwable {
3233
int rows = 10000;
33-
int num = (int) (Math.random() * rows);
34+
int num = new Random().nextInt(rows);
3435
try (Statement stmt = executeQuery(state,
3536
"select toString(number) as s from system.numbers where number > ? limit " + rows, num)) {
3637
ResultSet rs = stmt.getResultSet();
@@ -53,7 +54,7 @@ public int select10kStringRows(ClientState state) throws Throwable {
5354
@Benchmark
5455
public int select10kTimestampRows(ClientState state) throws Throwable {
5556
int rows = 10000;
56-
int num = (int) (Math.random() * rows);
57+
int num = new Random().nextInt(rows);
5758
try (Statement stmt = executeQuery(state,
5859
"select toDateTime('2021-02-20 13:15:20') + number as d from system.numbers where number > ? limit "
5960
+ rows,

clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseStatementImplTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ru.yandex.clickhouse.integration;
22

3+
import static org.testng.Assert.assertEquals;
34
import static org.testng.AssertJUnit.assertNotNull;
45
import static org.testng.AssertJUnit.assertNull;
56
import static org.testng.AssertJUnit.assertTrue;
@@ -43,6 +44,7 @@ public class ClickHouseStatementImplTest {
4344
public void setUp() throws Exception {
4445
dataSource = ClickHouseContainerForTest.newDataSource();
4546
connection = dataSource.getConnection();
47+
connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test");
4648
}
4749

4850
@AfterTest
@@ -165,6 +167,7 @@ private boolean genNextString() {
165167
return true;
166168
}
167169

170+
@Override
168171
public int read() {
169172
if (si >= s.length()) {
170173
if (!genNextString()) {
@@ -384,6 +387,25 @@ public void testArrayMetaActualExecutiom() throws SQLException {
384387

385388
}
386389

390+
@Test
391+
public void testInsertQueryUUIDArray() throws SQLException {
392+
// issue #569
393+
connection.createStatement().execute(
394+
"DROP TABLE IF EXISTS test.uuidArray");
395+
connection.createStatement().execute(
396+
"CREATE TABLE IF NOT EXISTS test.uuidArray"
397+
+ "(id UInt8, arr Array(UUID)) "
398+
+ "ENGINE = TinyLog");
399+
connection.createStatement().execute(
400+
"INSERT INTO test.uuidArray VALUES(1, ['5ff22319-793d-4e6c-bdc1-916095a5a496'])");
401+
ResultSet rs = connection.createStatement().executeQuery(
402+
"SELECT * FROM test.uuidArray");
403+
rs.next();
404+
assertEquals(
405+
rs.getArray(2).getArray(),
406+
new UUID[] {UUID.fromString("5ff22319-793d-4e6c-bdc1-916095a5a496")});
407+
}
408+
387409
private static Object readField(Object object, String fieldName, long timeoutSecs) {
388410
long start = System.currentTimeMillis();
389411
Object value;

0 commit comments

Comments
 (0)