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

DateTime/Date limits not compatible with CH server limits

Open subkanthi opened this issue 2 years ago • 4 comments

        DATETIME64_MAX = LocalDateTime.of(LocalDate.of(2283, 11, 11), LocalTime.MAX).toEpochSecond(ZoneOffset.UTC);

In Java 11, the nanosecond part is lost because of converting to LocalDateTime, maybe it should be kept as Instant.

Also the limits for DATETIME64 and DATE does not align with the latest CH server limits, is there a strategy to support limits that change across server versions?

        DATETIME64_MAX = LocalDateTime.of(LocalDate.of(2283, 11, 11), LocalTime.MAX).toEpochSecond(ZoneOffset.UTC);
        DATETIME64_MIN = LocalDateTime.of(LocalDate.of(1925, 1, 1), LocalTime.MIN).toEpochSecond(ZoneOffset.UTC);

    public static final int DATE32_MAX = (int)LocalDate.of(2283, 11, 11).toEpochDay();
    public static final int DATE32_MIN = (int)LocalDate.of(1925, 1, 1).toEpochDay();

Supported range of values: [1900-01-01 00:00:00, 2299-12-31 23:59:59.99999999] https://clickhouse.com/docs/en/sql-reference/data-types/datetime64/

subkanthi avatar Oct 07 '22 16:10 subkanthi

Thanks @subkanthi. And the upper limit is different when scale is 9 🤦

As to support limits across server versions, I'm not sure if it's worthy of doing that, but let me investigate once I completed refactoring.

zhicwu avatar Oct 07 '22 22:10 zhicwu

I can take a shot at fixing the MAX value if it's OK, recently have been looking at a lot of java datetime classes

subkanthi avatar Oct 07 '22 23:10 subkanthi

Thanks for helping, that'd be great! I'm refactoring *Value classes and data processors to better support unsigned types along with performance improvement of handling arrays and tuples. There's no conflict if the changes are mainly about Date & DateTime.

zhicwu avatar Oct 07 '22 23:10 zhicwu

There is no any issue with scale (8/9) for Date32 but DATE32_MIN and DATE32_MAX are out of supported by ClickHouse range [1900-01-01, 2299-12-31]. BTW attached pull request is for DateTime64 only and won't close Date32 issue.

TimonSP avatar Jan 09 '24 12:01 TimonSP