|
7 | 7 | import com.clickhouse.client.api.command.CommandResponse; |
8 | 8 | import com.clickhouse.client.api.command.CommandSettings; |
9 | 9 | import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader; |
| 10 | +import com.clickhouse.client.api.data_formats.NativeFormatReader; |
| 11 | +import com.clickhouse.client.api.data_formats.RowBinaryFormatReader; |
10 | 12 | import com.clickhouse.client.api.data_formats.RowBinaryWithNamesAndTypesFormatReader; |
| 13 | +import com.clickhouse.client.api.data_formats.RowBinaryWithNamesFormatReader; |
11 | 14 | import com.clickhouse.client.api.data_formats.internal.MapBackedRecord; |
12 | 15 | import com.clickhouse.client.api.data_formats.internal.ProcessParser; |
13 | 16 | import com.clickhouse.client.api.enums.Protocol; |
@@ -1361,6 +1364,39 @@ public CompletableFuture<CommandResponse> execute(String sql) { |
1361 | 1364 | }, sharedOperationExecutor); |
1362 | 1365 | } |
1363 | 1366 |
|
| 1367 | + /** |
| 1368 | + * <p>Create an instance of {@link ClickHouseBinaryFormatReader} based on response. Table schema is option and only |
| 1369 | + * required for {@link ClickHouseFormat#RowBinaryWithNames}, {@link ClickHouseFormat#RowBinary}. |
| 1370 | + * Format {@link ClickHouseFormat#RowBinaryWithDefaults} is not supported for output (read operations).</p> |
| 1371 | + * @param response |
| 1372 | + * @param schema |
| 1373 | + * @return |
| 1374 | + */ |
| 1375 | + public static ClickHouseBinaryFormatReader newBinaryFormatReader(QueryResponse response, TableSchema schema) { |
| 1376 | + ClickHouseBinaryFormatReader reader = null; |
| 1377 | + switch (response.getFormat()) { |
| 1378 | + case Native: |
| 1379 | + reader = new NativeFormatReader(response.getInputStream(), response.getSettings()); |
| 1380 | + break; |
| 1381 | + case RowBinaryWithNamesAndTypes: |
| 1382 | + reader = new RowBinaryWithNamesAndTypesFormatReader(response.getInputStream(), response.getSettings()); |
| 1383 | + break; |
| 1384 | + case RowBinaryWithNames: |
| 1385 | + reader = new RowBinaryWithNamesFormatReader(response.getInputStream(), response.getSettings(), schema); |
| 1386 | + break; |
| 1387 | + case RowBinary: |
| 1388 | + reader = new RowBinaryFormatReader(response.getInputStream(), response.getSettings(), schema); |
| 1389 | + break; |
| 1390 | + default: |
| 1391 | + throw new IllegalArgumentException("Unsupported format: " + response.getFormat()); |
| 1392 | + } |
| 1393 | + return reader; |
| 1394 | + } |
| 1395 | + |
| 1396 | + public static ClickHouseBinaryFormatReader newBinaryFormatReader(QueryResponse response) { |
| 1397 | + return newBinaryFormatReader(response, null); |
| 1398 | + } |
| 1399 | + |
1364 | 1400 | private String startOperation() { |
1365 | 1401 | String operationId = UUID.randomUUID().toString(); |
1366 | 1402 | globalClientStats.put(operationId, new ClientStatisticsHolder()); |
|
0 commit comments