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

Prepare for JDBC 4.2 #406 #418

Merged
merged 10 commits into from
Feb 26, 2021
Merged

Prepare for JDBC 4.2 #406 #418

merged 10 commits into from
Feb 26, 2021

Conversation

enqueue
Copy link
Contributor

@enqueue enqueue commented Jan 11, 2020

Enhance parsing and retrieving of date time values, especially using java.time objects (issue #406 )

  • Remove support for Java 1.6, add Java 11 checks (this will also allow us to use newer library versions soon, and perhaps get rid of some altogether)
  • Update maven plugins
  • Fix some Javadocs to make it work with Java 11 build
  • Implement "old" methods in PreparedStatement
  • Support java.time Objects
  • Breaking change: SQL type FLOAT is strange, Float32 is actually a SQL type REAL according to my understanding. I do not have access to any of the SQL standards, but see for example PostgreSQL manual, MS SQL Server manual, Oracle Datatypes
  • Deprecate non-JDBC methods
  • Remove ByteFragmentUtils
  • Add a test for JDBC Table B-3 conformance
  • Add a test for JDBC Table B-1 conformance
  • Added two tables to explain how the PreparedStatement and ResultSet implementations deal with different date time values (see docs/datetime.md).

I am sorry this PR is so large. I tried to create individual commits at least for some specific parts. If you have a good suggestion on how to split the PR, please let me know.

@enqueue enqueue changed the title Prepare for JDBC 4.2 #406 WIP Prepare for JDBC 4.2 #406 Feb 7, 2020
@enqueue
Copy link
Contributor Author

enqueue commented Feb 25, 2020

@alex-krash did you have time to take a look at this PR? I am happy to discuss any issues. Have a good day!

@alex-krash
Copy link
Contributor

@enqueue , sorry for delay. Will take a look now.
Looks like it's time to start new release (0.3), with breaking Java6 support, and incorporating your changes.

pom.xml Outdated
@@ -4,7 +4,7 @@

<groupId>ru.yandex.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.2.4</version>
<version>0.2.4-enqueue</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, avoid changes like this, in order not to pollute master branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, this was a mistake

case UInt32:
case UInt64:
try {
long l = Long.parseLong(s);
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. We may have UInt64 overflow here
  2. Why all these things in class ClickHouseDateValueParser? That's really confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Thanks, I had not thought of this. New implementation truncates to milliseconds.
  2. The code should not be confusing, let's see if we can improve it. ClickHouseDateValueParser provides basic functionality for all date/time parsing. This makes the individual implementations much easier to read. We could move the "utility" methods (lines 146 ff.) into the actual implementations. Do you think that this would help overall simplicity?

LocalTime parseDate(String value, ClickHouseColumnInfo columnInfo,
TimeZone timeZone)
{
return LocalTime.MIDNIGHT;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure, that it is ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the most straightforward response in my opinion. The ClickHouse column is of type Date, e.g. "2020-03-07". If we adjusted midnight server time zone into JVM time zone, we would perhaps cause more confusion.

@enqueue
Copy link
Contributor Author

enqueue commented Mar 8, 2020

Hi @alex-krash , thank you for taking the time to review this very large PR ❤️

Moving to Java 8 is an important step that will also help to keep libraries up to date. 0.2 releases containing the state of development as of now will still available for die-hard Java 6 users.

@hopsoft
Copy link

hopsoft commented Nov 17, 2020

Any updates on when this PR might get merged and released?

For Date and DateTime fields, the JDBC driver has enough time zone related information available, so these methods would only be relevant for String or other typed fields. There might be valid use cases, but for now we think that adding such an option would make things even more complicated.

Requested Type | Number | Date | DateTime | Other
---------------| ----------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

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

missing |

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @pan3793 ! After almost a year, someone stumbles upon wrongly formatted tables in the documentation... 😃 I added a couple of pipes, and the table looks better now in the preview.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are so many tricks about timezone, especially in legacy Java Date API. I also encountered some issues when migrated to java.time API from legacy Date API in another ClickHouse JDBC driver implement in native protocol. And would you mind me pick up some code and doc from this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, life would be boring without time zones and leap seconds. Feel free to use the code in this PR, but please let me know when you find any error, so I can fix it. Have a good weekend!

@alongls
Copy link

alongls commented Dec 13, 2020

Hello
is there any update regarding the driver compatibility to the current release of Metabase ?
thanks.

@enqueue
Copy link
Contributor Author

enqueue commented Dec 13, 2020

Hi @alongls

this PR is for improvements in the official ClickHouse JDBC driver. Please follow ClickHouse/metabase-clickhouse-driver#58 for an updated Metabase driver.

We use this branch for the driver, so it would be nice to see the PR reviewed and merged and use the official distribution, but perhaps it's too much work for maintainer due to size or other reasons.

@enqueue enqueue changed the base branch from master to develop February 1, 2021 18:28
@zhicwu
Copy link
Contributor

zhicwu commented Feb 18, 2021

Thanks @enqueue. This is really a large PR. I quickly walked through the changes today, but I still need a few more days to play with the code(and maybe benchmark too).

@github-actions
Copy link

🟢 verify using JDK [13] and ClickHouse [21.2]: success

@github-actions
Copy link

🔴 verify using JDK [15.0.2] and ClickHouse [21]: failure

@github-actions
Copy link

🟢 benchmark using JDK [8] and ClickHouse [latest]: success

Expand to see details...
Benchmark                                                                 (client)  (statement)   Mode  Cnt         Score         Error   Units
Insertion.insert10kStringRows                                      clickhouse-jdbc       normal  thrpt   20       796.889 ±       7.491   ops/s
Insertion.insert10kStringRows                                      clickhouse-jdbc     prepared  thrpt   20        25.315 ±       2.982   ops/s
Insertion.insert10kTimestampRows                                   clickhouse-jdbc       normal  thrpt   20       251.606 ±       3.919   ops/s
Insertion.insert10kTimestampRows                                   clickhouse-jdbc     prepared  thrpt   20        26.276 ±       2.793   ops/s
Insertion.insert10kUInt64Rows                                      clickhouse-jdbc       normal  thrpt   20       946.238 ±      19.478   ops/s
Insertion.insert10kUInt64Rows                                      clickhouse-jdbc     prepared  thrpt   20        24.932 ±       2.948   ops/s
Query.select10kStringRows                                          clickhouse-jdbc       normal  thrpt   20       457.826 ±      32.503   ops/s
Query.select10kStringRows                                          clickhouse-jdbc     prepared  thrpt   20       443.620 ±      32.391   ops/s
Query.select10kTimestampRows                                       clickhouse-jdbc       normal  thrpt   20        86.249 ±       4.698   ops/s
Query.select10kTimestampRows                                       clickhouse-jdbc     prepared  thrpt   20        90.834 ±       4.697   ops/s
Query.select10kUInt64Rows                                          clickhouse-jdbc       normal  thrpt   20       487.490 ±      21.605   ops/s
Query.select10kUInt64Rows                                          clickhouse-jdbc     prepared  thrpt   20       438.861 ±      31.040   ops/s

@zhicwu
Copy link
Contributor

zhicwu commented Feb 24, 2021

@enqueue, the build break is caused by below code snippets in TimeZoneTest:

Long offset = Long.valueOf(
    TimeUnit.MILLISECONDS.toHours(
        connectionServerTz.getTimeZone().getOffset(currentTime)) - 1);

I'm not sure why we need to deduct one here - it works if I remove that part. Could you take a look?

@zhicwu
Copy link
Contributor

zhicwu commented Feb 26, 2021

I'll take the risk to merge this large PR in order to unblock future development. I'll create separate PR to fix above issues as well as existing ones in ClickHousePreparedStatementTest and those introduced in PR #571.

@zhicwu zhicwu merged commit 1e6896a into ClickHouse:develop Feb 26, 2021
@zhicwu
Copy link
Contributor

zhicwu commented Feb 27, 2021

@enqueue, I'm not sure if Date is handled properly, but now Time and Timestamp seem good. I think we probably need some more time to compare the tests against clickhouse-client and other drivers. As you may noticed, I removed the hard-coded timezone in pom.xml and enhanced build process to test a few selected timezones. In addition to that, you can now use below command to test more scenarios:

mvn -Duser.timezone=Etc/UTC -DclickhouseTimezone=Europe/Moscow clean verify

Anyway, I'll restructure directories tomorrow and start to add more features in the next following days. If you have time, you may want to review the changes I made in PR #580 and the 3 test cases I temporarily disabled(search @Test(enabled = false)).

This was linked to issues Mar 2, 2021
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.

clickhouse-jdbc not support localDateTime JDBC 4.2 Support
6 participants