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

kerwin 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 e4ba677e1 [core] Fix PredicateBuilder.convertJavaObject with timestamp 
with local zone (#3752)
e4ba677e1 is described below

commit e4ba677e1ae995ccbe5a4e98e6487e855b2b3495
Author: Jingsong Lee <[email protected]>
AuthorDate: Mon Jul 15 21:12:57 2024 +0800

    [core] Fix PredicateBuilder.convertJavaObject with timestamp with local 
zone (#3752)
---
 .../apache/paimon/predicate/PredicateBuilder.java  | 26 ++++++++++++----------
 .../SearchArgumentToPredicateConverterTest.java    |  6 +++++
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git 
a/paimon-common/src/main/java/org/apache/paimon/predicate/PredicateBuilder.java 
b/paimon-common/src/main/java/org/apache/paimon/predicate/PredicateBuilder.java
index 71f02e9b6..c54fc31b1 100644
--- 
a/paimon-common/src/main/java/org/apache/paimon/predicate/PredicateBuilder.java
+++ 
b/paimon-common/src/main/java/org/apache/paimon/predicate/PredicateBuilder.java
@@ -283,30 +283,32 @@ public class PredicateBuilder {
                 int scale = decimalType.getScale();
                 return Decimal.fromBigDecimal((BigDecimal) o, precision, 
scale);
             case TIMESTAMP_WITHOUT_TIME_ZONE:
-                Timestamp timestamp;
                 if (o instanceof java.sql.Timestamp) {
-                    timestamp = 
Timestamp.fromSQLTimestamp((java.sql.Timestamp) o);
+                    return Timestamp.fromSQLTimestamp((java.sql.Timestamp) o);
                 } else if (o instanceof Instant) {
                     Instant o1 = (Instant) o;
                     LocalDateTime dateTime = 
o1.atZone(ZoneId.systemDefault()).toLocalDateTime();
-                    timestamp = Timestamp.fromLocalDateTime(dateTime);
+                    return Timestamp.fromLocalDateTime(dateTime);
                 } else if (o instanceof LocalDateTime) {
-                    timestamp = Timestamp.fromLocalDateTime((LocalDateTime) o);
+                    return Timestamp.fromLocalDateTime((LocalDateTime) o);
                 } else {
-                    throw new UnsupportedOperationException("Unsupported 
object: " + o);
+                    throw new UnsupportedOperationException(
+                            String.format(
+                                    "Unsupported class %s for timestamp 
without timezone ",
+                                    o.getClass()));
                 }
-                return timestamp;
             case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
                 if (o instanceof java.sql.Timestamp) {
-                    timestamp = 
Timestamp.fromSQLTimestamp((java.sql.Timestamp) o);
+                    java.sql.Timestamp timestamp = (java.sql.Timestamp) o;
+                    return Timestamp.fromInstant(timestamp.toInstant());
                 } else if (o instanceof Instant) {
-                    timestamp = Timestamp.fromInstant((Instant) o);
-                } else if (o instanceof LocalDateTime) {
-                    timestamp = Timestamp.fromLocalDateTime((LocalDateTime) o);
+                    return Timestamp.fromInstant((Instant) o);
                 } else {
-                    throw new UnsupportedOperationException("Unsupported 
object: " + o);
+                    throw new UnsupportedOperationException(
+                            String.format(
+                                    "Unsupported class %s for timestamp with 
local time zone ",
+                                    o.getClass()));
                 }
-                return timestamp;
             default:
                 throw new UnsupportedOperationException(
                         "Unsupported predicate leaf type " + 
literalType.getTypeRoot().name());
diff --git 
a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/SearchArgumentToPredicateConverterTest.java
 
b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/SearchArgumentToPredicateConverterTest.java
index c66fe5e10..7599cf127 100644
--- 
a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/SearchArgumentToPredicateConverterTest.java
+++ 
b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/SearchArgumentToPredicateConverterTest.java
@@ -75,6 +75,12 @@ public class SearchArgumentToPredicateConverterTest {
                 java.sql.Timestamp.valueOf("2022-05-17 16:25:53"),
                 DataTypes.TIMESTAMP(3),
                 
Timestamp.fromSQLTimestamp(java.sql.Timestamp.valueOf("2022-05-17 16:25:53")));
+        testLiteral(
+                PredicateLeaf.Type.TIMESTAMP,
+                java.sql.Timestamp.valueOf("2022-05-17 16:25:53"),
+                DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(3),
+                Timestamp.fromInstant(
+                        java.sql.Timestamp.valueOf("2022-05-17 
16:25:53").toInstant()));
     }
 
     private void testLiteral(

Reply via email to