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 bbe2d10934 [spark] Add legacy timestamp mapping option (#8433)
bbe2d10934 is described below

commit bbe2d109347271c9bb5a6829cf8fe9dc355ac300
Author: Kerwin Zhang <[email protected]>
AuthorDate: Fri Jul 3 13:12:06 2026 +0800

    [spark] Add legacy timestamp mapping option (#8433)
    
    Add `spark.paimon.legacy-timestamp-mapping.enabled` for Spark 3.4+ users
    who need to expose Paimon `TIMESTAMP` as Spark `TIMESTAMP` instead of
    `TIMESTAMP_NTZ`. The option is disabled by default, so existing Spark
    3.4+ behavior is unchanged.
    
    When enabled, Paimon reuses the existing legacy timestamp conversion
    path. This helps workloads migrating from Spark 3.3 keep expressions
    such as `unix_timestamp(ts)` followed by `from_unixtime(...)` consistent
    with their previous behavior.
---
 docs/generated/spark_connector_configuration.html  |  6 ++
 .../apache/paimon/spark/SparkConnectorOptions.java |  7 +++
 .../org/apache/paimon/spark/util/OptionUtils.scala |  4 ++
 .../apache/paimon/spark/util/shim/TypeUtils.scala  |  6 +-
 .../spark/SparkLegacyTimestampMappingTest.java     | 71 ++++++++++++++++++++++
 .../org/apache/paimon/spark/sql/DDLTestBase.scala  | 35 +++++++++++
 6 files changed, 128 insertions(+), 1 deletion(-)

diff --git a/docs/generated/spark_connector_configuration.html 
b/docs/generated/spark_connector_configuration.html
index c9b5cab70f..6937d85757 100644
--- a/docs/generated/spark_connector_configuration.html
+++ b/docs/generated/spark_connector_configuration.html
@@ -26,6 +26,12 @@ under the License.
         </tr>
     </thead>
     <tbody>
+        <tr>
+            <td><h5>legacy-timestamp-mapping.enabled</h5></td>
+            <td style="word-wrap: break-word;">false</td>
+            <td>Boolean</td>
+            <td>If true, map Paimon TIMESTAMP to Spark TIMESTAMP instead of 
TIMESTAMP_NTZ.</td>
+        </tr>
         <tr>
             <td><h5>read.allow.fullScan</h5></td>
             <td style="word-wrap: break-word;">true</td>
diff --git 
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkConnectorOptions.java
 
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkConnectorOptions.java
index 4138ae295a..6e0bbf9c58 100644
--- 
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkConnectorOptions.java
+++ 
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkConnectorOptions.java
@@ -32,6 +32,13 @@ public class SparkConnectorOptions {
                     .withDescription(
                             "Whether to verify SparkSession is initialized 
with required configurations.");
 
+    public static final ConfigOption<Boolean> LEGACY_TIMESTAMP_MAPPING =
+            key("legacy-timestamp-mapping.enabled")
+                    .booleanType()
+                    .defaultValue(false)
+                    .withDescription(
+                            "If true, map Paimon TIMESTAMP to Spark TIMESTAMP 
instead of TIMESTAMP_NTZ.");
+
     public static final ConfigOption<Boolean> MERGE_SCHEMA =
             key("write.merge-schema")
                     .booleanType()
diff --git 
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/util/OptionUtils.scala
 
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/util/OptionUtils.scala
index 7aff2966e6..37521ceda6 100644
--- 
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/util/OptionUtils.scala
+++ 
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/util/OptionUtils.scala
@@ -126,6 +126,10 @@ object OptionUtils extends SQLConfHelper with Logging {
     
getOptionString(SparkConnectorOptions.DATA_EVOLUTION_UPDATE_CONFLICT_RETRY_WAIT_MS).toLong
   }
 
+  def legacyTimestampMappingEnabled(): Boolean = {
+    getOptionString(SparkConnectorOptions.LEGACY_TIMESTAMP_MAPPING).toBoolean
+  }
+
   def v1FunctionEnabled(): Boolean = {
     getOptionString(SparkCatalogOptions.V1FUNCTION_ENABLED).toBoolean
   }
diff --git 
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/util/shim/TypeUtils.scala
 
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/util/shim/TypeUtils.scala
index 8e70432bd1..effbebc579 100644
--- 
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/util/shim/TypeUtils.scala
+++ 
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/util/shim/TypeUtils.scala
@@ -18,7 +18,11 @@
 
 package org.apache.paimon.spark.util.shim
 
+import org.apache.paimon.spark.util.OptionUtils
+
 object TypeUtils {
 
-  def treatPaimonTimestampTypeAsSparkTimestampType(): Boolean = false
+  def treatPaimonTimestampTypeAsSparkTimestampType(): Boolean = {
+    OptionUtils.legacyTimestampMappingEnabled()
+  }
 }
diff --git 
a/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkLegacyTimestampMappingTest.java
 
b/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkLegacyTimestampMappingTest.java
new file mode 100644
index 0000000000..57bc65b1f4
--- /dev/null
+++ 
b/paimon-spark/paimon-spark-common/src/test/java/org/apache/paimon/spark/SparkLegacyTimestampMappingTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.spark;
+
+import org.apache.paimon.types.DataTypes;
+import org.apache.paimon.types.RowType;
+
+import org.apache.spark.sql.internal.SQLConf;
+import org.apache.spark.sql.types.StructType;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.paimon.spark.SparkTypeUtils.fromPaimonRowType;
+import static org.apache.paimon.spark.SparkTypeUtils.toPaimonType;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Test for legacy timestamp mapping. */
+public class SparkLegacyTimestampMappingTest {
+
+    private static final String LEGACY_TIMESTAMP_MAPPING_KEY =
+            "spark.paimon.legacy-timestamp-mapping.enabled";
+
+    @Test
+    public void testLegacyTimestampMapping() {
+        RowType paimonType = RowType.builder().field("ts", 
DataTypes.TIMESTAMP()).build();
+
+        assertThat(fromPaimonRowType(paimonType).apply("ts").dataType())
+                
.isEqualTo(org.apache.spark.sql.types.DataTypes.TimestampNTZType);
+
+        withSQLConf(
+                LEGACY_TIMESTAMP_MAPPING_KEY,
+                "true",
+                () -> {
+                    StructType sparkType = fromPaimonRowType(paimonType);
+                    assertThat(sparkType.apply("ts").dataType())
+                            
.isEqualTo(org.apache.spark.sql.types.DataTypes.TimestampType);
+                    assertThat(toPaimonType(sparkType)).isEqualTo(paimonType);
+                });
+    }
+
+    private static void withSQLConf(String key, String value, Runnable test) {
+        SQLConf conf = SQLConf.get();
+        boolean contains = conf.contains(key);
+        String originalValue = contains ? conf.getConfString(key) : null;
+        conf.setConfString(key, value);
+        try {
+            test.run();
+        } finally {
+            if (contains) {
+                conf.setConfString(key, originalValue);
+            } else {
+                conf.unsetConf(key);
+            }
+        }
+    }
+}
diff --git 
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/DDLTestBase.scala
 
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/DDLTestBase.scala
index 53e4594578..2c2405c366 100644
--- 
a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/DDLTestBase.scala
+++ 
b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/DDLTestBase.scala
@@ -25,6 +25,7 @@ import org.apache.paimon.types.DataTypes
 
 import org.apache.spark.sql.{AnalysisException, Row}
 import org.apache.spark.sql.catalyst.analysis.NoSuchPartitionsException
+import org.apache.spark.sql.types.TimestampType
 import org.junit.jupiter.api.Assertions
 
 import java.sql.{Date, Timestamp}
@@ -651,6 +652,40 @@ abstract class DDLTestBase extends PaimonSparkTestBase {
     }
   }
 
+  test("Paimon DDL: legacy timestamp mapping") {
+    assume(gteqSpark3_4)
+
+    Seq("orc", "parquet").foreach {
+      format =>
+        withSparkSQLConf("spark.paimon.legacy-timestamp-mapping.enabled" -> 
"true") {
+          withTimeZone("Asia/Shanghai") {
+            withTable("paimon_tbl") {
+              sql(s"""
+                     |CREATE TABLE paimon_tbl (reported_time timestamp)
+                     |USING paimon
+                     |TBLPROPERTIES ('file.format'='$format')
+                     |""".stripMargin)
+
+              sql("INSERT INTO paimon_tbl VALUES (timestamp'2026-06-30 
23:47:51')")
+
+              Assertions.assertEquals(
+                TimestampType,
+                spark.table("paimon_tbl").schema("reported_time").dataType)
+              checkAnswer(
+                sql("""
+                      |SELECT from_unixtime(
+                      |  unix_timestamp(reported_time) + 24 * 3600,
+                      |  'yyyy-MM-dd HH:mm:ss'
+                      |) FROM paimon_tbl
+                      |""".stripMargin),
+                Row("2026-07-01 23:47:51") :: Nil
+              )
+            }
+          }
+        }
+    }
+  }
+
   test("Paimon DDL: create table with timestamp/timestamp_ntz using table 
API") {
     val identifier = Identifier.create("test", "paimon_tbl")
     try {

Reply via email to