-
Notifications
You must be signed in to change notification settings - Fork 614
Instant / DateTime64 via parameter #2501
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
|
I added a test for unusual String parameters which fails for multi-line Strings and quoted Strings. I had to disable the tests because I was not able to make this work. I think this is related to query parameter parsing downstream, see issues ClickHouse/ClickHouse#70240 and ClickHouse/ClickHouse#69656 |
|
Good day, @enqueue ! Here are some answer to the general remarks :
As for integration tests - we mostly test against real DB and just mark tests with |
client-v2/src/main/java/com/clickhouse/client/api/DataTypeUtils.java
Outdated
Show resolved
Hide resolved
client-v2/src/main/java/com/clickhouse/client/api/DataTypeUtils.java
Outdated
Show resolved
Hide resolved
|
@enqueue please see my comments. |
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 support for using java.time.Instant as query parameters in ClickHouse queries. The driver automatically converts Java Instant objects into appropriate ClickHouse DateTime/DateTime64 formats, with configurable time zone handling for Date types.
- Implements
DataTypeUtils.format()methods to convertInstantobjects to ClickHouse-compatible string formats - Adds query parameter formatting in the
Clientclass to handle object-to-string conversion - Includes comprehensive integration and unit tests for datetime parameter handling
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| ParameterizedQueryTest.java | New integration test class for parameterized queries with datetime types |
| BinaryStreamReaderTests.java | Added datetime serialization/deserialization tests with timezone handling |
| ClickHouseBinaryFormatReaderTest.java | Updated test assertions to remove redundant type casting |
| DataTypeUtilsTests.java | Added comprehensive unit tests for Instant formatting methods |
| HttpAPIClientHelper.java | Refactored query parameter handling with constant for statement params key |
| SerializerUtils.java | Added support for OffsetDateTime serialization and cleaned up imports |
| BinaryStreamReader.java | Simplified datetime reading logic and removed redundant type casting |
| RowBinaryFormatSerializer.java | Fixed timezone handling in date serialization |
| DataTypeUtils.java | Core implementation of Instant formatting for various ClickHouse data types |
| Client.java | Added query parameter formatting and deprecated method annotation |
Comments suppressed due to low confidence (1)
client-v2/src/test/java/com/clickhouse/client/api/DataTypeUtilsTests.java:16
- Test class should be declared as 'public' to follow standard testing conventions and ensure proper test discovery
class DataTypeUtilsTests {
Summary
This PR adds support for supplying a
java.time.Instantas query parameter to a query. The driver will take care to translate the JavaInstantinto a format ClickHouse server will understand. In some use cases, user will have to perform the mapping themself.This is only the start into a great journey. As outlined in #2456 , clients will also expect this to work with Array, probably Tuple etc. as well. Nice candidates with time zone madness are also
LocalDateTimeand friends.I decided against exposing individual mapping methods via API in
DataTypeUtils, because they are subject to change. Instead, clients should be able to rely on default behavior.This feels very similar to requirements from JDBC, where Java objects have to be serialized somehow (see PreparedStatementImpl.encodeObject(). We have to be cautious not to have different ways of serializing stuff for ClickHouse queries. N.b.: That method uses a dirty hack to dynamically invoke
fromUnixTimestamp64Nanoon server for all modern Java time data types which are time-zone based.I did not know where to place the integration tests, really. I first started adding a method to
QueryTests, but I reckoned that this class' primary purpose was to ensure the same behavior using different configuration options (compression etc.) via sub classes. I also consideredDataTypeTests, but this class mainly deals with some complex, nested stuff. So I created a new test,com.clickhouse.client.e2e.ParameterizedQueryTest. Please let me know if you see a better place for this integration test.The
formatmethods inDataTypeUtilscreate an empty String fornullvalues. This might not always be the best default value for every ClickHouse data type. There are different options:ClickHouseDataTypeor here, in theDataTypeUilsclass.Please suggest the most practical way you would expect the API to work.
Some more general remarks:
lomboklibrary. This is not very practical because you have to set up your IDE to pre-compile this stuff etc. Either stick to "old-school" Java, let IDE generate getters/setters for you or go current Java standard, records.Closes #2456
Checklist
Delete items not relevant to your PR: