Open kuangye098 opened 5 years ago
It took me 2 hours of debugging and found that the time zone setting of the ClickHouse client was incorrect. The following code has logical processing that is not rigorous enough. I think it should be handled this way.
ClickHouseConnectionImpl.java
private void initTimeZone(ClickHouseProperties properties) {
if (properties.isUseServerTimeZone() && !Strings.isNullOrEmpty(properties.getUseTimeZone())) {
throw new IllegalArgumentException(String.format("only one of %s or %s must be enabled", ClickHouseConnectionSettings.USE_SERVER_TIME_ZONE.getKey(), ClickHouseConnectionSettings.USE_TIME_ZONE.getKey()));
}
if (properties.isUseServerTimeZone()) {
ResultSet rs = null;
try {
timezone = TimeZone.getTimeZone("UTC"); // just for next query
rs = createStatement().executeQuery("select timezone()");
rs.next();
String timeZoneName = rs.getString(1);
timezone = TimeZone.getTimeZone(timeZoneName);
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
StreamUtils.close(rs);
}
} else if (!Strings.isNullOrEmpty(properties.getUseTimeZone())) {
timezone = TimeZone.getTimeZone(properties.getUseTimeZone());
}
}
Obviously, the first IF statement in this code does not judge that their values are False, and then does not check the TimeZone value, causing the above exception to occur. But I think the JDK is also responsible, not doing a non-empty check :).
JDBC version : 0.1.48 and JDK 1.8.171