Open piotrp opened 2 years ago
I believe the issue is in the way getTimestamp
works. Value is read correctly from database, as 2021-08-13 11:00:00
at UTC
:
but here:
it's read into dt
as LocalDateTime(2021-08-13T11:00)
(tz
is null here, but both possible code paths give the same result). Then it's copied into defaultCalendar
which is at JVM's time zone.
Hi @piotrp, sorry for the late response. The behavior is same as MySQL and legacy driver, but I agree that use_server_time_zone
option is really confusing. Perhaps you can use DateTime column with timezone argument or use_time_zone
option as shown in below example?
No, the legacy driver worked correctly. I stumbled upon this issue when I tried upgrading and my JDBC code using getTimestamp
failed.
I created a test case at https://github.com/piotrp/clickhouse-driver-issue-1048, where you can see that the same test passes when run with legacy driver, and fails with the new one. I also added a test demonstrating that round trip with setTimestamp
/getTimesatamp
doesn't work correctly. This should be runnable under Java 17 by:
docker-compose up -d
mvn --fail-at-end test
Thanks for this pointer, for now I worked around this by using getObject(.., Instant.class)
. Fortunately I'm using hand-crafted row mappers, so it was easy to do.
Thanks for sharing the test case. Legacy driver does not support timezone very well mainly due to the text-based data format. It's been enhanced in the new driver and this test case was added to ensure the driver works in the same way as MySQL.
It's recommended to use getObject instead of getTimestamp/getDate not only because it turns LocalDate/LocalDateTime/OffsetDateTime over legacy Date/Timestamp, but also ~10x better performance.
Let me see if I can fix this together with #955.
When reading a DateTime value I get a timestamp that is shifted back by my JVM timezone offset.
Server is in UTC, JVM in Europe/Warsaw (UTC+2). When I try to read a DateTime value
2021-08-13T11:00:00Z
I get2021-08-13T09:00:00Z
.Is this driver bug or am I doing something wrong?
I'm using clickhouse-jdbc 0.3.2-patch11 (revision: 27f8951). ClickHouse 22.6.3.35.