Skip to content

Commit 3e7cc63

Browse files
committed
Added information about insert and read
1 parent afea1b7 commit 3e7cc63

File tree

1 file changed

+46
-0
lines changed
  • docs/integrations/language-clients/java/client

1 file changed

+46
-0
lines changed

docs/integrations/language-clients/java/client/client.mdx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,52 @@ Table below shows what old options are supported in the new client and their new
993993
</TabItem>
994994
</Tabs>
995995

996+
997+
### General Differences
998+
999+
- Client V2 uses less proprietary classes to increase portability. For example, V2 works with any implementation of `java.io.InputStream` for
1000+
writing data to a server.
1001+
- Client V2 `async` settings is `off` by default. It means no extra threads and more application control over client. This setting should be `off` for majority of use cases. Enabling `async` will create a separate thread for a request. It only make sense when using application controlled
1002+
executor (see `com.clickhouse.client.api.Client.Builder#setSharedOperationExecutor`)
1003+
1004+
### Writing Data
1005+
1006+
- use any implementation of `java.io.InputStream`. V1 `com.clickhouse.data.ClickHouseInputStream` is supported but NOT recommended.
1007+
- once end of input stream is detected it handled accordingly. Previously output stream of a request should be closed.
1008+
1009+
```java
1010+
1011+
// V2 Insert TSV formatted data.
1012+
InputStream inData = getInData();
1013+
InsertSettings settings = new InsertSettings().setInputStreamCopyBufferSize(8198 * 2); // set copy buffer size
1014+
try (InsertResponse response = client.insert(tableName, inData, ClickHouseFormat.TSV, settings).get(30, TimeUnit.SECONDS)) {
1015+
1016+
// Insert is complete at this point
1017+
1018+
} catch (Exception e) {
1019+
// Handle exception
1020+
}
1021+
```
1022+
1023+
- new low-level API is available `com.clickhouse.client.api.Client#insert(java.lang.String, java.util.List<java.lang.String>, com.clickhouse.client.api.DataStreamWriter, com.clickhouse.data.ClickHouseFormat, com.clickhouse.client.api.insert.InsertSettings)`. `com.clickhouse.client.api.DataStreamWriter` is designed to implement custom data writing logic. For instance, reading data from a
1024+
queue.
1025+
1026+
1027+
### Reading Data
1028+
1029+
- Data is read in `RowBinaryWithNamesAndTypes` format by default. Currently only this format is supported when data binding is required.
1030+
- Data can be read as a collection of records using `List<GenericRecord> com.clickhouse.client.api.Client#queryAll(java.lang.String)` method. It will read data to a memory and release connection. No need for extra handling. `GenericRecord` gives access to data, implements some conversions.
1031+
1032+
```java
1033+
Collection<GenericRecord> records = client.queryAll("SELECT * FROM table");
1034+
for (GenericRecord record : records) {
1035+
int rowId = record.getInteger("rowID");
1036+
String name = record.getString("name");
1037+
LocalDateTime ts = record.getLocalDateTime("ts");
1038+
}
1039+
1040+
```
1041+
9961042
</Version>
9971043

9981044
<Version>

0 commit comments

Comments
 (0)