Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[client-v2] V2 implement writer api #2034

Merged
merged 7 commits into from
Dec 29, 2024
Merged

[client-v2] V2 implement writer api #2034

merged 7 commits into from
Dec 29, 2024

Conversation

chernser
Copy link
Contributor

@chernser chernser commented Dec 18, 2024

Summary

Implements new Writer style API for insert operations.

  • Handles low-level writes
  • Has advanced writer with set-then-commit style
  • Fixes some issues with date/datetime serialization (more convertible types)

Writer API intended to work:

  • when DTO class requires more precise control over serialization
  • when data is compressed by application by a supported algorithm
  • when data source is collection (queue, list) so wrapping with InputStream is too complex.

Main change:

  • com.clickhouse.client.api.Client#insert(java.lang.String, com.clickhouse.client.api.DataStreamWriter, com.clickhouse.data.ClickHouseFormat, com.clickhouse.client.api.insert.InsertSettings) - intriduces ability to use data stream writer that can control how to write data.

Current PR introduces two new experimental classes:

  • com.clickhouse.client.api.data_formats.RowBinaryFormatWriter - Intend to simplify writing RowBinary encoded data
  • com.clickhouse.client.api.data_formats.RowBinaryFormatSerializer - very low-level serializer for RowBinary encoding. For very advanced users.

Checklist

Delete items not relevant to your PR:

@chernser chernser marked this pull request as ready for review December 28, 2024 06:36
settings.getInputStreamCopyBufferSize();

if (writeBufferSize <= 0) {
throw new IllegalArgumentException("Buffer size must be greater than 0");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we can not do that in InsertSettings and throw the exception from there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this value can be set by two method setInputStreamCopyBufferSize and setOption and here I'm doing specific calculation.
One more reason - I keep validation here because it is implementation specific code for this operation. InsertSettings should not be aware of this validation because they may be used for other purposes.

@@ -104,7 +104,7 @@ public enum ClientConfigProperties {

QUERY_ID("query_id"), // actually a server setting, but has client effect too

CLIENT_NETWORK_BUFFER_SIZE("client_network_buffer_size"),
CLIENT_NETWORK_BUFFER_SIZE("client_network_buffer_size", "8192"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets extract it to a const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done -> com.clickhouse.client.api.Client.Builder#DEFAULT_BUFFER_SIZE

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
29.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@chernser chernser merged commit a599876 into main Dec 29, 2024
29 of 30 checks passed
@chernser chernser deleted the v2_implement_writer_api branch December 29, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants