-
Notifications
You must be signed in to change notification settings - Fork 614
[jdbc] Fix prepared statement impl #2508
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
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
JDBC V1 CoverageCoverage Report
Class Coverage
|
Client V1 CoverageCoverage Report
Class Coverage
|
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 improves the PreparedStatementImpl implementation by adding comprehensive test coverage, implementing missing parameter validation, and introducing type casting functionality. The changes address issue #2418 by ensuring proper prepared statement behavior.
- Adds extensive test coverage for various prepared statement methods including streams, type casts, and parameter validation
- Implements validation to ensure all parameters are set before query execution
- Adds support for SQL type casting with ClickHouse data types
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| PreparedStatementTest.java | Comprehensive test coverage for prepared statement functionality including streams, type casts, and parameter validation |
| PreparedStatementImpl.java | Core implementation changes including parameter validation, type casting, and improved stream handling |
| JdbcUtils.java | Added SQL-to-ClickHouse type mapping and tuple conversion utility |
| Tuple.java | Added equals and hashCode methods for proper object comparison |
| SQLUtils.java | Added utility method for escaping single quotes in SQL strings |
| DataTypeUtils.java | Updated date formatters to use 'uuuu' pattern for better year handling |
| ClickHouseDataType.java | Implemented SQLType interface to enable type casting functionality |
jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java
Outdated
Show resolved
Hide resolved
jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java
Outdated
Show resolved
Hide resolved
jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java
Outdated
Show resolved
Hide resolved
jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java
Outdated
Show resolved
Hide resolved
| * Formatter for the DateTime type. | ||
| */ | ||
| public static DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
| public static DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss"); |
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.
Do you have a link or explanation for doing that, since you do not see that so often (using the format with uuuu)
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.
y if for year in era and u is for just year.
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { |
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.
Let's check if obj is null
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.
ok. The null check is done on obj instanceof Tuple.
| String val = values[i]; | ||
| compiledSql.replace(p, p+1, val == null ? "NULL" : val); | ||
| posOffset += val == null ? 0 : val.length() - 1; | ||
| if (val == null) { |
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.
A remark for before and after the string will be great here
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.
Previously we did not check if all parameters are set. This change just moved lines 122 and 123 below the check.
val is null only when we have not set any value. NULL will be a "NULL" string.
| @DataProvider(name = "testTypeCastsDP") | ||
| public static Object[][] testTypeCastsDP() { | ||
| return new Object[][] { | ||
| {100, ClickHouseDataType.Int8, ClickHouseDataType.Int8}, |
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.
{100, ClickHouseDataType.Int8, ClickHouseDataType.Int8} according to method signutare testTypeCastsWithoutArgument(Object value, SQLType targetType, ClickHouseDataType expectedType)
SQLType targetType -> ClickHouseDataType expectedType)
I'm missing something here
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.
I've made ClickHouseDataType to implement SQLType what is valid according to the spec.
I do always convert any type to ClickHouseDataType. In this case first ClickHouseDataType.Int8 acts as some SQLType instance. The second ClickHouseDataType.Int8 used to check if name of the type returned correctly. For that I use toTypeName function.
|




Summary
Closes #2418
Closes #2391
Checklist
Delete items not relevant to your PR: