com.clickhouse.benchmark.jdbc.Insertion Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clickhouse-benchmark Show documentation
Show all versions of clickhouse-benchmark Show documentation
Benchmarks for ClickHouse clients
The newest version!
package com.clickhouse.benchmark.jdbc;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Enumeration;
import java.util.Locale;
import java.util.UUID;
import org.openjdk.jmh.annotations.Benchmark;
public class Insertion extends DriverBenchmark {
private void checkResult(DriverState state, String batchId, int expectedRows, int actualResult) throws Exception {
boolean isValid = actualResult == expectedRows;
if (isValid) {
try (Statement stmt = executeQuery(state,
"select toInt32(count(1)) from system.test_insert where b=?", batchId)) {
ResultSet rs = stmt.getResultSet();
isValid = rs.next() && (actualResult = rs.getInt(1)) == expectedRows;
}
}
if (!isValid) {
throw new IllegalStateException(String.format(Locale.ROOT,
"Expected %d rows being inserted but we got %d", expectedRows, actualResult));
}
}
@Benchmark
public void insertInt64(DriverState state) throws Throwable {
final int range = state.getRandomNumber();
final int rows = state.getSampleSize() + range;
final String batchId = UUID.randomUUID().toString();
SupplyValueFunction func = state.getSupplyFunction((p, v, l, i) -> p.setLong(i, (long) v));
int result = executeInsert(state,
"insert into system.test_insert(b,i) -- select b,v from input('b String, v Int64')\nvalues(?,?)", func,
new Enumeration