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

WIP - Lower the datetime limit to what CH also accepts - 1900-01-01 #1386

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,11 @@ public ClickHouseValue deserialize(ClickHouseValue ref, ClickHouseInputStream in
@Override
public void serialize(ClickHouseValue value, ClickHouseOutputStream output) throws IOException {
LocalDateTime dt = value.asDateTime(scale);
long v = ClickHouseChecker.between(
ClickHouseValues.UTC_ZONE.equals(zoneId) ? dt.toEpochSecond(ZoneOffset.UTC)
: dt.atZone(zoneId).toEpochSecond(),
ClickHouseValues.TYPE_DATE_TIME, BinaryStreamUtils.DATETIME64_MIN,
BinaryStreamUtils.DATETIME64_MAX);
if (ClickHouseChecker.between(scale, ClickHouseValues.PARAM_SCALE, 0, 9) > 0) {
v *= BASES[scale];
int nanoSeconds = dt.getNano();
if (nanoSeconds > 0L) {
v += nanoSeconds / BASES[9 - scale];
}
long v = dt.toEpochSecond(ZoneOffset.UTC);
v *= BASES[scale];
int nanoSeconds = dt.getNano();
if (nanoSeconds > 0L) {
v += nanoSeconds / BASES[9 - scale];
}

BinaryStreamUtils.writeInt64(output, v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public final class BinaryStreamUtils {
public static final BigDecimal DECIMAL256_MIN = new BigDecimal(
"-10000000000000000000000000000000000000000000000000000000000000000000000000000");

public static final long DATETIME64_MAX = LocalDateTime.of(LocalDate.of(2283, 11, 11), LocalTime.MAX)
public static final long DATETIME64_MAX = LocalDateTime.of(LocalDate.of(2299, 12, 31), LocalTime.MAX)
.toEpochSecond(ZoneOffset.UTC);
public static final long DATETIME64_MIN = LocalDateTime.of(LocalDate.of(1925, 1, 1), LocalTime.MIN)
public static final long DATETIME64_MIN = LocalDateTime.of(LocalDate.of(1900, 1, 1), LocalTime.MIN)
.toEpochSecond(ZoneOffset.UTC);

public static final long MILLIS_IN_DAY = TimeUnit.DAYS.toMillis(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1256,12 +1256,12 @@ public void testWriteDateTime64() throws IOException {

Assert.assertThrows(IllegalArgumentException.class,
() -> getWrittenBytes(o -> BinaryStreamUtils.writeDateTime64(o,
LocalDateTime.of(LocalDate.of(1925, 1, 1).minus(1L, ChronoUnit.DAYS),
LocalDateTime.of(LocalDate.of(1900, 1, 1).minus(1L, ChronoUnit.DAYS),
LocalTime.MAX),
null)));
Assert.assertThrows(IllegalArgumentException.class,
() -> getWrittenBytes(o -> BinaryStreamUtils.writeDateTime64(o,
LocalDateTime.of(LocalDate.of(2283, 11, 11).plus(1L, ChronoUnit.DAYS),
LocalDateTime.of(LocalDate.of(2299, 12, 31).plus(1L, ChronoUnit.DAYS),
LocalTime.MIN),
null)));
}
Expand Down Expand Up @@ -1325,7 +1325,7 @@ public void testWriteDateTime64WithTimeZone(String timeZoneId) throws IOExceptio
() -> getWrittenBytes(
o -> BinaryStreamUtils.writeDateTime64(o,
LocalDateTime.of(
LocalDate.of(1925, 1, 1).minus(1L,
LocalDate.of(1900, 1, 1).minus(1L,
ChronoUnit.DAYS),
LocalTime.MAX)
.atOffset(ZoneOffset.UTC)
Expand All @@ -1336,7 +1336,7 @@ public void testWriteDateTime64WithTimeZone(String timeZoneId) throws IOExceptio
() -> getWrittenBytes(
o -> BinaryStreamUtils.writeDateTime64(o,
LocalDateTime.of(
LocalDate.of(2283, 11, 11).plus(1L,
LocalDate.of(2299, 12, 31).plus(1L,
ChronoUnit.DAYS),
LocalTime.MIN)
.atOffset(ZoneOffset.UTC)
Expand Down