This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 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 d90f0a1fa7 [hive] The Hive connector encounters time offset issues
when reading and writing data of the timestamp with local time zone field type
(#5571)
d90f0a1fa7 is described below
commit d90f0a1fa7149f520d3d56d38e9ca4ea85672aee
Author: Jack1007 <[email protected]>
AuthorDate: Fri Jun 6 11:08:19 2025 +0800
[hive] The Hive connector encounters time offset issues when reading and
writing data of the timestamp with local time zone field type (#5571)
---
.../PaimonTimestampLocalTZObjectInspector.java | 15 ++++++++++++---
.../PaimonTimestampLocalTZObjectInspectorTest.java | 19 +++++++++++++------
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git
a/paimon-hive/paimon-hive-connector-3.1/src/main/java/org/apache/paimon/hive/objectinspector/PaimonTimestampLocalTZObjectInspector.java
b/paimon-hive/paimon-hive-connector-3.1/src/main/java/org/apache/paimon/hive/objectinspector/PaimonTimestampLocalTZObjectInspector.java
index 27af89e901..c405d6025e 100644
---
a/paimon-hive/paimon-hive-connector-3.1/src/main/java/org/apache/paimon/hive/objectinspector/PaimonTimestampLocalTZObjectInspector.java
+++
b/paimon-hive/paimon-hive-connector-3.1/src/main/java/org/apache/paimon/hive/objectinspector/PaimonTimestampLocalTZObjectInspector.java
@@ -26,7 +26,10 @@ import
org.apache.hadoop.hive.serde2.objectinspector.primitive.AbstractPrimitive
import
org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampLocalTZObjectInspector;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import java.time.Instant;
import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
/**
* {@link AbstractPrimitiveJavaObjectInspector} for TIMESTAMP WITH LOCAL TIME
ZONE type. The
@@ -45,7 +48,9 @@ public class PaimonTimestampLocalTZObjectInspector extends
AbstractPrimitiveJava
return null;
}
- return new TimestampTZ(((Timestamp)
o).toLocalDateTime().atZone(ZoneId.systemDefault()));
+ Instant instant = ((Timestamp)
o).toLocalDateTime().toInstant(ZoneOffset.UTC);
+ ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault());
+ return new TimestampTZ(zonedDateTime);
}
@Override
@@ -72,8 +77,12 @@ public class PaimonTimestampLocalTZObjectInspector extends
AbstractPrimitiveJava
return null;
}
if (value instanceof TimestampTZ) {
- return Timestamp.fromLocalDateTime(
- ((TimestampTZ)
value).getZonedDateTime().toLocalDateTime());
+ TimestampTZ timestampTZ = (TimestampTZ) value;
+ long millisecond =
+ timestampTZ.getEpochSecond() * 1000L
+ + (long) (timestampTZ.getNanos() / 1000000);
+ int nanoOfMillisecond = timestampTZ.getNanos() % 1000000;
+ return Timestamp.fromEpochMillis(millisecond, nanoOfMillisecond);
} else {
return null;
}
diff --git
a/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/objectinspector/PaimonTimestampLocalTZObjectInspectorTest.java
b/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/objectinspector/PaimonTimestampLocalTZObjectInspectorTest.java
index 23932dddcc..a98811a1ce 100644
---
a/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/objectinspector/PaimonTimestampLocalTZObjectInspectorTest.java
+++
b/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/objectinspector/PaimonTimestampLocalTZObjectInspectorTest.java
@@ -26,6 +26,7 @@ import
org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
import org.junit.jupiter.api.Test;
+import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -50,8 +51,10 @@ public class PaimonTimestampLocalTZObjectInspectorTest {
public void testGetPrimitiveJavaObject() {
PaimonTimestampLocalTZObjectInspector oi = new
PaimonTimestampLocalTZObjectInspector();
- LocalDateTime now = LocalDateTime.now().plusNanos(123);
- Timestamp input = Timestamp.fromLocalDateTime(now);
+ long nowMs = System.currentTimeMillis();
+ LocalDateTime now =
+ LocalDateTime.ofInstant(Instant.ofEpochMilli(nowMs),
ZoneId.systemDefault());
+ Timestamp input = Timestamp.fromEpochMillis(nowMs);
TimestampTZ expected = new
TimestampTZ(now.atZone(ZoneId.systemDefault()));
assertThat(oi.getPrimitiveJavaObject(input)).isEqualTo(expected);
@@ -62,8 +65,10 @@ public class PaimonTimestampLocalTZObjectInspectorTest {
public void testGetPrimitiveWritableObject() {
PaimonTimestampLocalTZObjectInspector oi = new
PaimonTimestampLocalTZObjectInspector();
- LocalDateTime now = LocalDateTime.now().plusNanos(123);
- Timestamp input = Timestamp.fromLocalDateTime(now);
+ long nowMs = System.currentTimeMillis();
+ LocalDateTime now =
+ LocalDateTime.ofInstant(Instant.ofEpochMilli(nowMs),
ZoneId.systemDefault());
+ Timestamp input = Timestamp.fromEpochMillis(nowMs);
TimestampTZ expected = new
TimestampTZ(now.atZone(ZoneId.systemDefault()));
assertThat(oi.getPrimitiveWritableObject(input).getTimestampTZ()).isEqualTo(expected);
@@ -92,8 +97,10 @@ public class PaimonTimestampLocalTZObjectInspectorTest {
public void testConvertObject() {
PaimonTimestampLocalTZObjectInspector oi = new
PaimonTimestampLocalTZObjectInspector();
- LocalDateTime now = LocalDateTime.now().plusNanos(123);
- Timestamp expected = Timestamp.fromLocalDateTime(now);
+ long nowMs = System.currentTimeMillis();
+ LocalDateTime now =
+ LocalDateTime.ofInstant(Instant.ofEpochMilli(nowMs),
ZoneId.systemDefault());
+ Timestamp expected = Timestamp.fromEpochMillis(nowMs);
TimestampTZ input = new
TimestampTZ(now.atZone(ZoneId.systemDefault()));
assertThat(oi.convert(input)).isEqualTo(expected);