This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 66156311a9 [common] Fix incorrect date for casting pre epoch time
(#9203)
66156311a9 is described below
commit 66156311a901572074803f3c4cb48d1467eeae66
Author: Arnav Balyan <[email protected]>
AuthorDate: Thu Aug 13 19:25:37 2026 +0530
[common] Fix incorrect date for casting pre epoch time (#9203)
---
.../apache/paimon/casting/TimestampToDateCastRule.java | 3 ++-
.../org/apache/paimon/casting/CastExecutorTest.java | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git
a/paimon-common/src/main/java/org/apache/paimon/casting/TimestampToDateCastRule.java
b/paimon-common/src/main/java/org/apache/paimon/casting/TimestampToDateCastRule.java
index 23d3633968..6587b5a26b 100644
---
a/paimon-common/src/main/java/org/apache/paimon/casting/TimestampToDateCastRule.java
+++
b/paimon-common/src/main/java/org/apache/paimon/casting/TimestampToDateCastRule.java
@@ -45,7 +45,8 @@ class TimestampToDateCastRule extends
AbstractCastRule<Timestamp, Number> {
@Override
public CastExecutor<Timestamp, Number> create(DataType inputType, DataType
targetType) {
if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
- return value -> (int) (value.getMillisecond() /
DateTimeUtils.MILLIS_PER_DAY);
+ return value ->
+ (int) Math.floorDiv(value.getMillisecond(),
DateTimeUtils.MILLIS_PER_DAY);
} else if (inputType.is(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
return value ->
DateTimeUtils.timestampWithLocalZoneToDate(value,
TimeZone.getDefault());
diff --git
a/paimon-common/src/test/java/org/apache/paimon/casting/CastExecutorTest.java
b/paimon-common/src/test/java/org/apache/paimon/casting/CastExecutorTest.java
index 7a4ddc7097..adea8d08d6 100644
---
a/paimon-common/src/test/java/org/apache/paimon/casting/CastExecutorTest.java
+++
b/paimon-common/src/test/java/org/apache/paimon/casting/CastExecutorTest.java
@@ -827,6 +827,24 @@ public class CastExecutorTest {
DateTimeUtils.timestampWithLocalZoneToTime(timestamp,
TimeZone.getDefault()));
}
+ @Test
+ public void testTimestampToDatePreEpoch() {
+ CastExecutor<?, ?> cast = CastExecutors.resolve(new TimestampType(6),
new DateType());
+ LocalDateTime[] timestamps = {
+ LocalDateTime.of(1969, 12, 31, 23, 59, 59),
+ LocalDateTime.of(1960, 6, 15, 10, 30),
+ LocalDateTime.of(1969, 12, 31, 0, 0),
+ LocalDateTime.of(2024, 3, 4, 5, 6, 7)
+ };
+
+ for (LocalDateTime timestamp : timestamps) {
+ compareCastResult(
+ cast,
+ Timestamp.fromLocalDateTime(timestamp),
+ (int) timestamp.toLocalDate().toEpochDay());
+ }
+ }
+
@Test
public void testTimestampToTimePreEpoch() {
CastExecutor<?, ?> cast = CastExecutors.resolve(new TimestampType(3),
new TimeType(3));