-
Notifications
You must be signed in to change notification settings - Fork 579
[jdbc-v2] Base implementation of RowBinaryFormatWriter support in JDBC #2316
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR provides a base implementation for RowBinaryFormatWriter support in JDBC and refactors PreparedStatement to handle batch insertions with enhanced parameter handling. Key changes include:
- Adding tests and utility methods (e.g. unQuoteTableName) to support quoting operations.
- Refactoring statement and prepared statement implementations for better batch handling and logging.
- Updating RowBinaryFormatWriter to implement the new ClickHouseBinaryFormatWriter interface with additional tracking features.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcUtilsTest.java | Adds unit test for unQuoteTableName utility method |
jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java | Refactors parameter count checks and adds batch insert tests |
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcUtils.java | Introduces unQuoteTableName method with regex pattern |
jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java | Updates method accessibility and logging level improvements |
jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java | Refactors SQL segmentation, parameter handling and batch insert logic |
jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java | Adds condition for using the WriterStatementImpl for INSERT queries |
client-v2/src/main/java/com/clickhouse/client/api/data_formats/RowBinaryFormatWriter.java | Implements ClickHouseBinaryFormatWriter with row count tracking and new value-setting methods |
client-v2/src/main/java/com/clickhouse/client/api/data_formats/ClickHouseBinaryFormatWriter.java | Introduces a new interface for binary format writers |
jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java
Outdated
Show resolved
Hide resolved
jdbc-v2/src/main/java/com/clickhouse/jdbc/WriterStatementImpl.java
Outdated
Show resolved
Hide resolved
jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java
Outdated
Show resolved
Hide resolved
stmt.setInt(1, rnd.nextInt()); | ||
stmt.setFloat(2, rnd.nextFloat()); | ||
stmt.setInt(3, rnd.nextInt()); | ||
stmt.addBatch(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also test with clearParameters()
and also extending the data types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
"INSERT INTO \n `%s` \nVALUES (?, multiply(?, 10), ?)", // only string possible | ||
"INSERT INTO\n `%s` \nVALUES (?, ?, ?)", // row binary writer | ||
}; | ||
Class<?>[] impl = new Class<?>[]{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to add a JMH to test show check the differences in performance between two implementation (so we could explain why it is more beneficial to use the rowbinary )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is possible. With a feature flag it is possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds beta support for the RowBinaryFormatWriter in simple insert statements for the JDBC driver and fixes/improves related parsing logic. Key changes include updated statement parsing using the new StatementParser, introduction of a BETA_ROW_BINARY_WRITER driver property with accompanying implementation in PreparedStatementImpl and ConnectionImpl, and enhancements for the RowBinaryFormatWriter to manage row state and count.
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/StatementParserTest.java | Added tests for various SQL types and comment handling. |
jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcUtilsTest.java | Added tests for unquoting table names. |
jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java | Updated tests to cover parameter type changes and beta batch insert functionality. |
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/StatementParser.java | Refactored SQL statement parsing logic and added table name extraction. |
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/DriverProperties.java | Introduced new beta property for the row binary writer. |
jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java | New prepareStatement logic conditionally returns WriterStatementImpl based on beta configuration. |
client-v2/src/main/java/com/clickhouse/client/api/data_formats/RowBinaryFormatWriter.java | Updated RowBinaryFormatWriter to implement ClickHouseBinaryFormatWriter, managing row state and count. |
client-v2/src/main/java/com/clickhouse/client/api/data_formats/ClickHouseBinaryFormatWriter.java | Added new interface for binary format writers. |
Comments suppressed due to low confidence (2)
client-v2/src/main/java/com/clickhouse/client/api/data_formats/RowBinaryFormatWriter.java:90
- Consider adding tests to cover the behavior of commitRow when no values have been set, ensuring that the rowCount is only incremented when a row is actually started.
if (rowStarted) {
jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java:370
- Consider adding tests to verify that the beta writer path correctly selects WriterStatementImpl, and that the conditions (absence of a column list and function parameters) are properly validated.
if (config.isBetaFeatureEnabled(DriverProperties.BETA_ROW_BINARY_WRITER)) {
|
|
||
if (this.statementType == StatementType.INSERT) { | ||
if (this.statementType == StatementParser.StatementType.INSERT) { | ||
insertIntoSQL = originalSql.substring(0, originalSql.indexOf("VALUES") + 6); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #2283 a reported probleam for indexOf("VALUES")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the problem. But with parser. This PR should not fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you open an issues for the parser implementation
Summary
Adds support for RowBinaryFormatWriter and fixes some issues:
Additional work is needed further:
Closes #2171
Checklist
Delete items not relevant to your PR: