You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by lz...@apache.org on 2026/04/29 14:18:24 UTC
(paimon) branch master updated: [iceberg] Support timestamp conversion for IcebergDataField (#7734)
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 91f9d6774a [iceberg] Support timestamp conversion for IcebergDataField (#7734)
91f9d6774a is described below
commit 91f9d6774a52c61b920bb0e32bac5d9819c717b4
Author: Arnav Balyan <60...@users.noreply.github.com>
AuthorDate: Wed Apr 29 19:48:17 2026 +0530
[iceberg] Support timestamp conversion for IcebergDataField (#7734)
---
.../iceberg/manifest/IcebergConversions.java | 19 ++++++
.../paimon/iceberg/metadata/IcebergDataField.java | 9 +++
.../manifest/IcebergConversionsTimeTest.java | 68 ++++++++++++++++++++++
3 files changed, 96 insertions(+)
diff --git a/paimon-core/src/main/java/org/apache/paimon/iceberg/manifest/IcebergConversions.java b/paimon-core/src/main/java/org/apache/paimon/iceberg/manifest/IcebergConversions.java
index 4998d0db14..b1cc1abf0c 100644
--- a/paimon-core/src/main/java/org/apache/paimon/iceberg/manifest/IcebergConversions.java
+++ b/paimon-core/src/main/java/org/apache/paimon/iceberg/manifest/IcebergConversions.java
@@ -24,6 +24,7 @@ import org.apache.paimon.data.Timestamp;
import org.apache.paimon.types.DataType;
import org.apache.paimon.types.DecimalType;
import org.apache.paimon.types.LocalZonedTimestampType;
+import org.apache.paimon.types.TimeType;
import org.apache.paimon.types.TimestampType;
import org.apache.paimon.utils.Preconditions;
@@ -109,6 +110,8 @@ public class IcebergConversions {
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
return timestampToByteBuffer(
(Timestamp) value, ((LocalZonedTimestampType) type).getPrecision());
+ case TIME_WITHOUT_TIME_ZONE:
+ return timeToByteBuffer((Integer) value, ((TimeType) type).getPrecision());
default:
throw new UnsupportedOperationException("Cannot serialize type: " + type);
}
@@ -123,6 +126,15 @@ public class IcebergConversions {
.putLong(0, timestamp.toMicros());
}
+ private static ByteBuffer timeToByteBuffer(int millisOfDay, int precision) {
+ Preconditions.checkArgument(
+ precision >= 0 && precision <= 3,
+ "Paimon Iceberg compatibility only support time type with precision from 0 to 3.");
+ return ByteBuffer.allocate(8)
+ .order(ByteOrder.LITTLE_ENDIAN)
+ .putLong(0, millisOfDay * 1000L);
+ }
+
public static Object toPaimonObject(DataType type, byte[] bytes) {
switch (type.getTypeRoot()) {
case BOOLEAN:
@@ -163,6 +175,13 @@ public class IcebergConversions {
return Timestamp.fromEpochMillis(timestampLong);
}
return Timestamp.fromMicros(timestampLong);
+ case TIME_WITHOUT_TIME_ZONE:
+ int timePrecision = ((TimeType) type).getPrecision();
+ Preconditions.checkArgument(
+ timePrecision >= 0 && timePrecision <= 3,
+ "Paimon Iceberg compatibility only support time type with precision from 0 to 3.");
+ long timeMicros = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getLong();
+ return (int) (timeMicros / 1000L);
default:
throw new UnsupportedOperationException("Cannot deserialize type: " + type);
}
diff --git a/paimon-core/src/main/java/org/apache/paimon/iceberg/metadata/IcebergDataField.java b/paimon-core/src/main/java/org/apache/paimon/iceberg/metadata/IcebergDataField.java
index 55d67e55ee..ca557fc1d0 100644
--- a/paimon-core/src/main/java/org/apache/paimon/iceberg/metadata/IcebergDataField.java
+++ b/paimon-core/src/main/java/org/apache/paimon/iceberg/metadata/IcebergDataField.java
@@ -33,6 +33,7 @@ import org.apache.paimon.types.IntType;
import org.apache.paimon.types.LocalZonedTimestampType;
import org.apache.paimon.types.MapType;
import org.apache.paimon.types.RowType;
+import org.apache.paimon.types.TimeType;
import org.apache.paimon.types.TimestampType;
import org.apache.paimon.types.VarBinaryType;
import org.apache.paimon.types.VarCharType;
@@ -163,6 +164,12 @@ public class IcebergDataField {
return "double";
case DATE:
return "date";
+ case TIME_WITHOUT_TIME_ZONE:
+ int timePrecision = ((TimeType) dataType).getPrecision();
+ Preconditions.checkArgument(
+ timePrecision >= 0 && timePrecision <= 3,
+ "Paimon Iceberg compatibility only support time type with precision from 0 to 3.");
+ return "time";
case CHAR:
case VARCHAR:
return "string";
@@ -235,6 +242,8 @@ public class IcebergDataField {
return new DoubleType(!isRequired);
case "date":
return new DateType(!isRequired);
+ case "time":
+ return new TimeType(!isRequired, 3);
case "string":
return new VarCharType(!isRequired, VarCharType.MAX_LENGTH);
case "binary":
diff --git a/paimon-core/src/test/java/org/apache/paimon/iceberg/manifest/IcebergConversionsTimeTest.java b/paimon-core/src/test/java/org/apache/paimon/iceberg/manifest/IcebergConversionsTimeTest.java
new file mode 100644
index 0000000000..0dfdce8dc8
--- /dev/null
+++ b/paimon-core/src/test/java/org/apache/paimon/iceberg/manifest/IcebergConversionsTimeTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.iceberg.manifest;
+
+import org.apache.paimon.iceberg.metadata.IcebergDataField;
+import org.apache.paimon.types.DataField;
+import org.apache.paimon.types.DataTypes;
+import org.apache.paimon.types.TimeType;
+
+import org.junit.jupiter.api.Test;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class IcebergConversionsTimeTest {
+
+ private static final int MIDDAY_MS = 47_003_524; // 13:03:03.524
+
+ @Test
+ void testTimeToByteBuffer() {
+ ByteBuffer buffer = IcebergConversions.toByteBuffer(DataTypes.TIME(3), MIDDAY_MS);
+ assertThat(buffer.order()).isEqualTo(ByteOrder.LITTLE_ENDIAN);
+ assertThat(buffer.getLong(0)).isEqualTo(MIDDAY_MS * 1000L);
+ }
+
+ @Test
+ void testToPaimonObjectForTime() {
+ byte[] bytes = new byte[8];
+ ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).putLong(MIDDAY_MS * 1000L);
+
+ Object actual = IcebergConversions.toPaimonObject(DataTypes.TIME(3), bytes);
+
+ assertThat(actual).isEqualTo(MIDDAY_MS);
+ }
+
+ @Test
+ void testIcebergDataFieldToTypeObjectForTime() {
+ DataField field = new DataField(0, "event_time", DataTypes.TIME(3));
+ IcebergDataField icebergField = new IcebergDataField(field);
+
+ assertThat(icebergField.type()).isEqualTo("time");
+ }
+
+ @Test
+ void testIcebergDataFieldFromTypeForTime() {
+ IcebergDataField field = new IcebergDataField(0, "event_time", false, "time", null);
+
+ assertThat(field.dataType()).isInstanceOf(TimeType.class);
+ }
+}