-
Notifications
You must be signed in to change notification settings - Fork 618
Description
Hi. We noticed a change in behavior when upgraded clickhouse driver and started using com.clickhouse.jdbc.ClickHouseDriver instead of the legacy driver from ru.yandex.*. More specifically, the change is in the way the dates are written into tables. Here are the details:
The new clickhouse-jdbc driver is using a different implementation of PreparedStatement which is InputBasedPreparedStatement whereas the previous version from the legacy driver ru.yandex.* was using SqlBasedPreparedStatement implementation. They have different implementation code in terms of how the datetime values are written into the database. The way we populate the datetime column in our code is as follows:
ps.setLong(i, statistic.getDate().getTime() / 1000L);
So in other words, we take the epoch time, remove millisecond part and let it write to the database as is. So the final value would be stored in UTC and when we read it, it would be translated to whatever timezone is set in the server configs or connection string params(we rely on the former).
In the new version of the driver, InputBasedPreparedStatement is using a different approach:
- It takes an epoch time which we provide.
- It translates it to the DateTime value such as YYYY-MM-DD HH:MM:SS in UTC timezone.
- When it is saved to DB, it is treated in the timezone which is set in the server OR the timezone set via connection string params.
- Since we have America/Toronto set in the server, the DateTime value which was converted to UTC is treated in the America/Toronto timezone.
- Once it is saved on the server side, it would be converted again to UTC, i.e., DateTime value + 5h.
As a result of that, we see all stats shifted by 5 hours ahead. We found that in order to remediate this issue, we have to set the following connection string params:
jdbc:clickhouse://127.0.0.1:18123/ssdsp?use_server_time_zone=false&use_time_zone=UTC
Now the questions. Why does the new driver use InputBasedPreparedStatement and not SqlBasedPreparedStatement anymore? Is there a better way to handle this? Unfortunately, I wasn't able to find any comments in the release notes relating to that change. Please advise.