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

Localdatetime always uses the server time zone #888

Closed
nie-xh opened this issue Apr 1, 2022 · 7 comments
Closed

Localdatetime always uses the server time zone #888

nie-xh opened this issue Apr 1, 2022 · 7 comments
Labels

Comments

@nie-xh
Copy link

nie-xh commented Apr 1, 2022

clickhouse-jdbc version 0.3.1
clickhouse fieldtype : Nullable(DateTime)
clickhouse timezone:Asia/Shanghai
46e4ee36e47961ed3ccac1c10d0518de

the java entity type is LocalDateTime

now ,i hava a record from clickhouse and the value is field start_time 2022-03-31 19:31:15, I use mybatis-pius to query the data.
but the java entity result is 2022-03-31 11:31:15,I track the code and found the value is changed in ru.yandex.clickhouse.response.parser.ClickHouseDateValueParser.dateTimeToLocalDateTime()

ea8f9d13b1ce4ec33dd816bc8b4bca24

and then return 2022-03-31 11:31:15.

image

I found the columnInfo.getTimeZone() is afferent by ru.yandex.clickhouse.response.ClickHouseResultSet.

8469a853efebbd3e8189ef6165065da4

in ClickHOuseResultSet.java ,TimeZone is from ((ClickHouseConnection)statement.getConnection()).getServerTimeZone();
I found the serverTimeZone field init in ru.yandex.clickhouse.ClickHouseConnectionImpl. initConnection
c2b00e0fa3ee1124e3c8c92d14578b57

so ,the serverTimeZone is equals clickhouse timezone , both are Asia/Shanghai.

In my app,I only want to query the fieldValue equals clickhouse value,both are 2022-03-31 19:31:15,I dont know why ClickHouseDateValueParser.dateTimeToLocalDateTime() trans the value to UTC time.

if this problem open in mysql ,i can add the serverTimezone=Asia/Shanghai after the connect url ,but clickhouse not have this connetcion param,i use the use_server_time_zone to the url but not use.

what should i do?

@zhicwu
Copy link
Contributor

zhicwu commented Apr 1, 2022

Hi @779833371, is there any specific reason of using legacy driver? If not, I'd strongly suggest you to upgrade to 0.3.2, which is a complete rewrite with improved timezone support. In addition, it is recommended to use LocalDateTime/OffsetDateTime etc instead of java.sql.Timestamp.

@nie-xh
Copy link
Author

nie-xh commented Apr 2, 2022

Hi @779833371, is there any specific reason of using legacy driver? If not, I'd strongly suggest you to upgrade to 0.3.2, which is a complete rewrite with improved timezone support. In addition, it is recommended to use LocalDateTime/OffsetDateTime etc instead of java.sql.Timestamp.

my java entity is used LocalDateTime not Timestamp, I upgrade to upgrade to 0.3.2 ,but useless

@zhicwu
Copy link
Contributor

zhicwu commented Apr 2, 2022

my java entity is used LocalDateTime not Timestamp, I upgrade to upgrade to 0.3.2 ,but useless

You need to use the new driver com.clickhouse.jdbc.ClickHouseDriver or it won't change. Everything under ru.yandex will be removed.

And please refer to this and this for more information.

@zhicwu zhicwu added the question label Apr 2, 2022
@nie-xh
Copy link
Author

nie-xh commented Apr 2, 2022

i switch driver to com.clickhouse.jdbc.ClickHouseDriver but also useless
image
i want to know why the value trans to UTC time in there, i track the code ,found before call this method,value is 2022-03-31 19:31:15 ,equals database value,but my serverTimeZone is Asia/Shanghai,and enter the if branch,so the value are changed to 2022-03-31 11:31:15

@nie-xh
Copy link
Author

nie-xh commented Apr 2, 2022

my java entity is used LocalDateTime not Timestamp, I upgrade to upgrade to 0.3.2 ,but useless

You need to use the new driver com.clickhouse.jdbc.ClickHouseDriver or it won't change. Everything under ru.yandex will be removed.

And please refer to this and this for more information.

@nie-xh nie-xh closed this as completed Apr 2, 2022
@nie-xh
Copy link
Author

nie-xh commented Apr 2, 2022

I am sorry ,i only switch the driver-class-name but not upgeade pom.xml, i use group id com.clickhouse an upgeade to 0.3.2,and the problem are resloved,thanks!

com.clickhouse
clickhouse-jdbc
0.3.2

@zhicwu
Copy link
Contributor

zhicwu commented Apr 2, 2022

Good to know. The latest version is 0.3.2-patch7, and patch8 will be released soon.

In case anyone else ran into similar issue, please refer to examples above and #623.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants