diff --git a/.pom.xml.swp b/.pom.xml.swp deleted file mode 100644 index 4e088c4fe..000000000 Binary files a/.pom.xml.swp and /dev/null differ diff --git a/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/ConsumeValueFunction.java b/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/ConsumeValueFunction.java index e5b3f5a36..5a390d360 100644 --- a/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/ConsumeValueFunction.java +++ b/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/ConsumeValueFunction.java @@ -7,5 +7,5 @@ @FunctionalInterface public interface ConsumeValueFunction { - void consume(Blackhole blackhole, ResultSet rs, int columnIndex) throws SQLException; + void consume(Blackhole blackhole, ResultSet rs, int rowIndex, int columnIndex) throws SQLException; } diff --git a/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/DriverState.java b/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/DriverState.java index f3d38b3df..618f382f3 100644 --- a/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/DriverState.java +++ b/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/DriverState.java @@ -129,11 +129,11 @@ public boolean usePreparedStatement() { public ConsumeValueFunction getConsumeFunction(ConsumeValueFunction defaultFunc) { if ("string".equals(type)) { - return (b, r, i) -> b.consume(r.getString(i)); + return (b, r, l, i) -> b.consume(r.getString(i)); } else if ("object".equals(type)) { - return (b, r, i) -> b.consume(r.getObject(i)); + return (b, r, l, i) -> b.consume(r.getObject(i)); } else if (defaultFunc == null) { - return (b, r, i) -> b.consume(i); + return (b, r, l, i) -> b.consume(i); } else { return defaultFunc; } diff --git a/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/Query.java b/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/Query.java index 09d2554a7..ef5f49eb2 100644 --- a/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/Query.java +++ b/clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/Query.java @@ -2,6 +2,8 @@ import java.sql.ResultSet; import java.sql.Statement; +import java.util.Locale; + import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.infra.Blackhole; @@ -10,162 +12,210 @@ public class Query extends DriverBenchmark { public void selectArrayOfUInt16(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getArray(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getArray(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select range(100, number % 600) as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectMapOfInt32(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getObject(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getObject(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select cast((arrayMap(x->x+1000, range(1, number % 100)), arrayMap(x->x+10000, range(1, number %100))) as Map(Int32, Int32)) as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectTupleOfInt16(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getObject(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getObject(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select tuple(arrayMap(x -> cast(x as Int16), range(100, number % 600))) as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectDateTime32(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getTimestamp(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getTimestamp(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select toDateTime32(1613826920 + number) as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectDateTime64(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getTimestamp(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getTimestamp(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select toDateTime64(1613826920 + number / 1000000000, 9) as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectInt8(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getByte(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getByte(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select toInt8(number % 256) as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectUInt8(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getShort(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getShort(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select toUInt8(number % 256) as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectUuid(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getString(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getString(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select generateUUIDv4() as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectInt32(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getInt(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getInt(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select toInt32(number) as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectString(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getString(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getString(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select toString(number/3) as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectUInt64(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getLong(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getLong(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select number as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } @Benchmark public void selectDecimal64(Blackhole blackhole, DriverState state) throws Throwable { int num = state.getRandomNumber(); int rows = state.getSampleSize() + num; - ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getBigDecimal(i))); + ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getBigDecimal(i))); + int l = 0; try (Statement stmt = executeQuery(state, "select toDecimal64(number + number / 10000, 4) as v from numbers(?)", rows)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { - func.consume(blackhole, rs, 1); + func.consume(blackhole, rs, l++, 1); } } + if (l != rows) { + throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l)); + } } }