Skip to content

Commit ac871a9

Browse files
committed
reader factory method
1 parent 1ceb2b0 commit ac871a9

File tree

1 file changed

+36
-0
lines changed
  • client-v2/src/main/java/com/clickhouse/client/api

1 file changed

+36
-0
lines changed

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import com.clickhouse.client.api.command.CommandResponse;
88
import com.clickhouse.client.api.command.CommandSettings;
99
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;
1012
import com.clickhouse.client.api.data_formats.RowBinaryWithNamesAndTypesFormatReader;
13+
import com.clickhouse.client.api.data_formats.RowBinaryWithNamesFormatReader;
1114
import com.clickhouse.client.api.data_formats.internal.MapBackedRecord;
1215
import com.clickhouse.client.api.data_formats.internal.ProcessParser;
1316
import com.clickhouse.client.api.enums.Protocol;
@@ -1361,6 +1364,39 @@ public CompletableFuture<CommandResponse> execute(String sql) {
13611364
}, sharedOperationExecutor);
13621365
}
13631366

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+
13641400
private String startOperation() {
13651401
String operationId = UUID.randomUUID().toString();
13661402
globalClientStats.put(operationId, new ClientStatisticsHolder());

0 commit comments

Comments
 (0)