|
4 | 4 | import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
|
5 | 5 | import com.clickhouse.client.api.query.QueryResponse;
|
6 | 6 | import com.clickhouse.client.config.ClickHouseClientOption;
|
| 7 | +import com.clickhouse.data.ClickHouseColumn; |
7 | 8 | import com.clickhouse.data.ClickHouseFormat;
|
8 | 9 | import com.clickhouse.data.ClickHouseRecord;
|
| 10 | +import com.clickhouse.data.ClickHouseValue; |
9 | 11 | import org.openjdk.jmh.annotations.Benchmark;
|
10 | 12 | import org.openjdk.jmh.annotations.Scope;
|
11 | 13 | import org.openjdk.jmh.annotations.State;
|
12 | 14 | import org.openjdk.jmh.infra.Blackhole;
|
13 | 15 | import org.slf4j.Logger;
|
14 | 16 | import org.slf4j.LoggerFactory;
|
15 | 17 |
|
| 18 | +import java.util.List; |
| 19 | + |
16 | 20 | import static com.clickhouse.benchmark.TestEnvironment.getServer;
|
17 | 21 |
|
18 | 22 | @State(Scope.Benchmark)
|
@@ -53,4 +57,47 @@ public void queryV2(DataState dataState, Blackhole blackhole) {
|
53 | 57 | LOGGER.error("Error: ", e);
|
54 | 58 | }
|
55 | 59 | }
|
| 60 | + |
| 61 | + @Benchmark |
| 62 | + public void queryV1WithTypes(DataState dataState, Blackhole blackhole) throws Exception { |
| 63 | + try (ClickHouseResponse response = clientV1.read(getServer()) |
| 64 | + .query(BenchmarkBase.getSelectQuery(dataState.tableNameFilled)) |
| 65 | + .format(ClickHouseFormat.RowBinaryWithNamesAndTypes) |
| 66 | + .option(ClickHouseClientOption.ASYNC, false) |
| 67 | + .executeAndWait()) { |
| 68 | + List<ClickHouseColumn> columns = dataState.dataSet.getSchema().getColumns(); |
| 69 | + for (ClickHouseRecord record: response.records()) {//Compiler optimization avoidance |
| 70 | + for (int i = 0; i < columns.size(); i++) { |
| 71 | + ClickHouseValue value = record.getValue(i); |
| 72 | + ClickHouseColumn column = columns.get(i); |
| 73 | + switch (column.getDataType()) { |
| 74 | + case Int64: blackhole.consume(value.asLong()); break; |
| 75 | + case Float64: blackhole.consume(value.asDouble()); break; |
| 76 | + case String: blackhole.consume(value.asString()); break; |
| 77 | + default: throw new IllegalStateException(); |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + @Benchmark |
| 85 | + public void queryV2WithTypes(DataState dataState, Blackhole blackhole) throws Exception { |
| 86 | + try(QueryResponse response = clientV2.query(BenchmarkBase.getSelectQuery(dataState.tableNameFilled)).get()) { |
| 87 | + ClickHouseBinaryFormatReader reader = clientV2.newBinaryFormatReader(response); |
| 88 | + List<ClickHouseColumn> columns = dataState.dataSet.getSchema().getColumns(); |
| 89 | + while (reader.next() != null) {//Compiler optimization avoidance |
| 90 | + for (int i = 1; i <= columns.size(); i++) { |
| 91 | + blackhole.consume(reader.readValue(i)); |
| 92 | + ClickHouseColumn column = columns.get(i - 1); |
| 93 | + switch (column.getDataType()) { |
| 94 | + case Int64: blackhole.consume(reader.getLong(i)); break; |
| 95 | + case Float64: blackhole.consume(reader.getDouble(i)); break; |
| 96 | + case String: blackhole.consume(reader.getString(i)); break; |
| 97 | + default: throw new IllegalStateException(); |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
56 | 103 | }
|
0 commit comments