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

[jdbc] Incorrect DateTime results when writing numeric data with use_time_zone property #2065

Open
haishui126 opened this issue Jan 2, 2025 · 1 comment
Labels
bug data-type data type processing issues

Comments

@haishui126
Copy link
Contributor

haishui126 commented Jan 2, 2025

Describe the bug

The DateTime results will -8h when inserting long values using PrepareStatement with use_server_time_zone=false&use_time_zone=Asia/Shanghai. (ClickHouse Server timezone is UTC)

Expected: '1970-01-01 08:00:00.001000000'
Actual: '1970-01-01 00:00:00.001000000'
(timezone is Asia/Shanghai)

Code example

CREATE TABLE t_test
(
    `timestamp` DateTime64(3)
)
ENGINE = Log;
try (
    Connection connection = DriverManager.getConnection("jdbc:ch://localhost:8123/default?use_server_time_zone=false&use_time_zone=Asia/Shanghai", "default", "");
    PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO t_test VALUES (?)")
) {
    preparedStatement.setLong(1, 1);
    preparedStatement.execute();
}

Configuration

Environment

  • Client version: 0.7.2
  • Language version: java11
@haishui126
Copy link
Contributor Author

Hi team,
I think the method in com.clickhouse.data.ClickHouseValues.java:282 is incorrect. Why should a numeric type representing a Unix timestamp, which inherently lacks timezone context, be directly converted to a LocalDateTime assuming it's in the UTC time zone?

public static LocalDateTime convertToDateTime(BigDecimal value) {
    return value != null ? LocalDateTime.ofInstant(convertToInstant(value), ZoneOffset.UTC) : null;
}

The concern here is that the conversion assumes the input Unix timestamp is in UTC without verifying if this is correct for all cases, which can lead to time zone discrepancies when clients operate in different time zones.

@chernser chernser added the data-type data type processing issues label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug data-type data type processing issues
Projects
None yet
Development

No branches or pull requests

2 participants