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 e4f5b31d3 [core] Fix partition type batch write with DATE and TIME 
(#3284)
e4f5b31d3 is described below

commit e4f5b31d3fee67b5b04ce9bb5b1b5681bea02750
Author: Jingsong Lee <[email protected]>
AuthorDate: Tue Apr 30 07:27:34 2024 +0800

    [core] Fix partition type batch write with DATE and TIME (#3284)
---
 .../java/org/apache/paimon/utils/BinaryStringUtils.java | 14 ++++++++++++--
 .../main/java/org/apache/paimon/utils/StringUtils.java  | 13 +++++++++++++
 .../apache/paimon/spark/sql/InsertOverwriteTest.scala   | 17 +++++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git 
a/paimon-common/src/main/java/org/apache/paimon/utils/BinaryStringUtils.java 
b/paimon-common/src/main/java/org/apache/paimon/utils/BinaryStringUtils.java
index dabd1f0ac..a5e12e344 100644
--- a/paimon-common/src/main/java/org/apache/paimon/utils/BinaryStringUtils.java
+++ b/paimon-common/src/main/java/org/apache/paimon/utils/BinaryStringUtils.java
@@ -276,7 +276,12 @@ public class BinaryStringUtils {
     }
 
     public static int toDate(BinaryString input) throws DateTimeException {
-        Integer date = DateTimeUtils.parseDate(input.toString());
+        String str = input.toString();
+        if (StringUtils.isNumeric(str)) {
+            // for Integer.toString conversion
+            return toInt(input);
+        }
+        Integer date = DateTimeUtils.parseDate(str);
         if (date == null) {
             throw new DateTimeException("For input string: '" + input + "'.");
         }
@@ -285,7 +290,12 @@ public class BinaryStringUtils {
     }
 
     public static int toTime(BinaryString input) throws DateTimeException {
-        Integer date = DateTimeUtils.parseTime(input.toString());
+        String str = input.toString();
+        if (StringUtils.isNumeric(str)) {
+            // for Integer.toString conversion
+            return toInt(input);
+        }
+        Integer date = DateTimeUtils.parseTime(str);
         if (date == null) {
             throw new DateTimeException("For input string: '" + input + "'.");
         }
diff --git 
a/paimon-common/src/main/java/org/apache/paimon/utils/StringUtils.java 
b/paimon-common/src/main/java/org/apache/paimon/utils/StringUtils.java
index adc4ce553..94ce975aa 100644
--- a/paimon-common/src/main/java/org/apache/paimon/utils/StringUtils.java
+++ b/paimon-common/src/main/java/org/apache/paimon/utils/StringUtils.java
@@ -554,4 +554,17 @@ public class StringUtils {
     public static String caseSensitiveConversion(String str, boolean 
caseSensitive) {
         return caseSensitive ? str : str.toLowerCase();
     }
+
+    public static boolean isNumeric(final CharSequence cs) {
+        if (isEmpty(cs)) {
+            return false;
+        }
+        final int sz = cs.length();
+        for (int i = 0; i < sz; i++) {
+            if (!Character.isDigit(cs.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
+    }
 }
diff --git 
a/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/sql/InsertOverwriteTest.scala
 
b/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/sql/InsertOverwriteTest.scala
index 5802e6b06..f33c49f82 100644
--- 
a/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/sql/InsertOverwriteTest.scala
+++ 
b/paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/sql/InsertOverwriteTest.scala
@@ -23,6 +23,8 @@ import org.apache.paimon.spark.PaimonSparkTestBase
 import org.apache.spark.sql.Row
 import org.apache.spark.sql.types._
 
+import java.sql.Date
+
 class InsertOverwriteTest extends PaimonSparkTestBase {
 
   withPk.foreach {
@@ -328,4 +330,19 @@ class InsertOverwriteTest extends PaimonSparkTestBase {
       }
   }
 
+  test(s"insert overwrite date type partition table") {
+    spark.sql(s"""
+                 |CREATE TABLE T (
+                 |  id STRING,
+                 |  dt date)
+                 |PARTITIONED BY (dt)
+                 |TBLPROPERTIES (
+                 |  'primary-key' = 'id,dt',
+                 |  'bucket' = '3'
+                 |);
+                 |""".stripMargin)
+
+    spark.sql("INSERT OVERWRITE T partition (dt='2024-04-18') values(1)")
+    checkAnswer(spark.sql("SELECT * FROM T"), Row("1", 
Date.valueOf("2024-04-18")))
+  }
 }

Reply via email to