This is an automated email from the ASF dual-hosted git repository.

j1wonpark pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/amoro.git


The following commit(s) were added to refs/heads/master by this push:
     new 28c0a5784 [AMORO-4426][AMS] Preserve timestamp without time zone in 
Spark type display (#4428)
28c0a5784 is described below

commit 28c0a57846d22b64bf093227a97c6709440dfd1f
Author: hutiefang76 <[email protected]>
AuthorDate: Fri Oct 16 18:07:31 2026 -0700

    [AMORO-4426][AMS] Preserve timestamp without time zone in Spark type 
display (#4428)
    
    Preserve timestamp without time zone in Spark type display
    
    Co-authored-by: Jiwon Park <[email protected]>
---
 .../component/reverser/IcebergTypeToSparkType.java |  9 +++-
 .../reverser/TestIcebergTypeToSparkType.java       | 52 ++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git 
a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/component/reverser/IcebergTypeToSparkType.java
 
b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/component/reverser/IcebergTypeToSparkType.java
index 89c9a8c68..8dbcdd833 100644
--- 
a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/component/reverser/IcebergTypeToSparkType.java
+++ 
b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/component/reverser/IcebergTypeToSparkType.java
@@ -38,6 +38,7 @@ import org.apache.spark.sql.types.Metadata;
 import org.apache.spark.sql.types.StringType$;
 import org.apache.spark.sql.types.StructField;
 import org.apache.spark.sql.types.StructType$;
+import org.apache.spark.sql.types.TimestampNTZType$;
 import org.apache.spark.sql.types.TimestampType$;
 
 import java.util.List;
@@ -107,7 +108,13 @@ public class IcebergTypeToSparkType extends 
TypeUtil.SchemaVisitor<DataType> {
       case TIME:
         throw new UnsupportedOperationException("Spark does not support time 
fields");
       case TIMESTAMP:
-        return TimestampType$.MODULE$;
+        // Iceberg timestamps without a zone must not be adjusted to UTC, keep 
them apart from
+        // timestamps with a zone instead of mapping both to Spark's 
zone-adjusted timestamp.
+        Types.TimestampType timestamp = (Types.TimestampType) primitive;
+        if (timestamp.shouldAdjustToUTC()) {
+          return TimestampType$.MODULE$;
+        }
+        return TimestampNTZType$.MODULE$;
       case STRING:
         return StringType$.MODULE$;
       case UUID:
diff --git 
a/amoro-ams/src/test/java/org/apache/amoro/server/dashboard/component/reverser/TestIcebergTypeToSparkType.java
 
b/amoro-ams/src/test/java/org/apache/amoro/server/dashboard/component/reverser/TestIcebergTypeToSparkType.java
new file mode 100644
index 000000000..f74ae1b45
--- /dev/null
+++ 
b/amoro-ams/src/test/java/org/apache/amoro/server/dashboard/component/reverser/TestIcebergTypeToSparkType.java
@@ -0,0 +1,52 @@
+/*
+ * 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.amoro.server.dashboard.component.reverser;
+
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.TypeUtil;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestIcebergTypeToSparkType {
+
+  private static String sparkString(Type type) {
+    return TypeUtil.visit(type, new IcebergTypeToSparkType()).catalogString();
+  }
+
+  @Test
+  public void testTimestampWithoutZone() {
+    Assertions.assertEquals("timestamp_ntz", 
sparkString(Types.TimestampType.withoutZone()));
+  }
+
+  @Test
+  public void testTimestampWithZone() {
+    Assertions.assertEquals("timestamp", 
sparkString(Types.TimestampType.withZone()));
+  }
+
+  @Test
+  public void testNestedStructKeepsFieldDataTypes() {
+    Types.StructType struct =
+        Types.StructType.of(
+            Types.NestedField.optional(1, "ts_tz", 
Types.TimestampType.withZone()),
+            Types.NestedField.optional(2, "ts_ntz", 
Types.TimestampType.withoutZone()));
+
+    Assertions.assertEquals("struct<ts_tz:timestamp,ts_ntz:timestamp_ntz>", 
sparkString(struct));
+  }
+}

Reply via email to