clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

problem with dates + timezones

Open mtselishchev opened this issue 3 years ago • 5 comments

This issue arises in v.0.3.2

Suppose a Clickhouse server is located in UTC+0 timezone, while the client is on UTC-x timezone. Then the following query

SELECT toDate('2022-10-27')

will return 2022-10-26 on the client side.

It seems that somewhere inside Java the date '2022-10-27' turns into '2022-10-27 00:00:00 UTC', which is the same as '2022-10-26 20:00:00 NY(UTC-4)', and the latter converts to '2022-10-26'.

Legacy version (v.0.2.6) works fine by the way.

mtselishchev avatar Oct 27 '22 20:10 mtselishchev

Thanks for the report @mtselishchev, it does sound like an issue. However, I was not able to reproduce the issue using v0.3.2-patch11 and v0.3.2. Could you share code snippet or the database client you're using?

zhicwu avatar Oct 27 '22 23:10 zhicwu

@zhicwu I'm using dbeaver v. 22.2.3 with JDBC driver v.0.3.2 If that matters Clickhouse version is 22.2.2 revision 54455. And yeah, client's Java is OpenJDK 11

mtselishchev avatar Oct 28 '22 10:10 mtselishchev

Guys,

I have been using clickhouse and clickhouse-jdbc for a year now in my current company and I want to start to contribute now.

This issue seems interesting to me and I have started looking into it.

Can anyone please give me some pointers for getting started?

DEBOJYOTI11 avatar Nov 22 '22 12:11 DEBOJYOTI11

Thanks @DEBOJYOTI11, that'd be great.

Do you want to investigate this specific issue? If not, perhaps you can start with unit test and integration test for the JDBC driver and Java client, and then later performance tuning. If you prefer to start with new feature, I think you may introduce ClickHouse query parameter to replace named parameter.

zhicwu avatar Nov 22 '22 23:11 zhicwu

Triage Report

  • requires more date-time examples
  • com.clickhouse.client.config.ClickHouseClientOption#USE_SERVER_TIME_ZONE_FOR_DATES should be a true by default

chernser avatar Aug 16 '24 19:08 chernser

All Date and Time values should be normalized to modern Date/Time classes like LocaDate. Then this classes should be used to convert into a string representing value. Handling different configuration layers regarding timezone is a mistake and leads to errors.

JDBC should use Calendar methods to specify timezone or use LocaDate/LocaTime to set values and avoid additional conversion.

chernser avatar Dec 17 '25 05:12 chernser