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

lzljs3620320 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-paimon-trino.git


The following commit(s) were added to refs/heads/main by this push:
     new 6f09a7b  Fix the problem of query failure for timestamp with timezone 
type field (#39)
6f09a7b is described below

commit 6f09a7be220b9037f08781c6eda287faf536dc54
Author: groobyming <[email protected]>
AuthorDate: Mon Nov 20 12:51:49 2023 +0800

    Fix the problem of query failure for timestamp with timezone type field 
(#39)
---
 .../org/apache/paimon/trino/TrinoPageSourceBase.java   |  5 +++++
 .../java/org/apache/paimon/trino/TestTrinoITCase.java  | 18 +++++++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git 
a/paimon-trino-common/src/main/java/org/apache/paimon/trino/TrinoPageSourceBase.java
 
b/paimon-trino-common/src/main/java/org/apache/paimon/trino/TrinoPageSourceBase.java
index 8c724e3..d900eb3 100644
--- 
a/paimon-trino-common/src/main/java/org/apache/paimon/trino/TrinoPageSourceBase.java
+++ 
b/paimon-trino-common/src/main/java/org/apache/paimon/trino/TrinoPageSourceBase.java
@@ -60,6 +60,7 @@ import java.util.OptionalLong;
 import static io.airlift.slice.Slices.wrappedBuffer;
 import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
 import static io.trino.spi.type.BigintType.BIGINT;
+import static io.trino.spi.type.DateTimeEncoding.packDateTimeWithZone;
 import static io.trino.spi.type.DateType.DATE;
 import static io.trino.spi.type.Decimals.encodeShortScaledValue;
 import static io.trino.spi.type.IntegerType.INTEGER;
@@ -213,6 +214,10 @@ public abstract class TrinoPageSourceBase implements 
ConnectorPageSource {
                         ((Timestamp) value).getMillisecond() * 
MICROSECONDS_PER_MILLISECOND);
             } else if (type.equals(TIMESTAMP_MICROS)) {
                 type.writeLong(output, ((Timestamp) value).toMicros());
+            } else if (type.equals(TIMESTAMP_TZ_MILLIS)) {
+                type.writeLong(
+                        output,
+                        packDateTimeWithZone(((Timestamp) 
value).getMillisecond(), UTC_KEY));
             } else if (type.equals(TIME_MICROS)) {
                 type.writeLong(output, (int) value * 
MICROSECONDS_PER_MILLISECOND);
             } else {
diff --git 
a/paimon-trino-common/src/test/java/org/apache/paimon/trino/TestTrinoITCase.java
 
b/paimon-trino-common/src/test/java/org/apache/paimon/trino/TestTrinoITCase.java
index 64140d9..b994c75 100644
--- 
a/paimon-trino-common/src/test/java/org/apache/paimon/trino/TestTrinoITCase.java
+++ 
b/paimon-trino-common/src/test/java/org/apache/paimon/trino/TestTrinoITCase.java
@@ -169,7 +169,12 @@ public abstract class TestTrinoITCase extends 
AbstractTestQueryFramework {
                                     new DataField(0, "i", new IntType()),
                                     new DataField(1, "createdtime", new 
TimestampType(0)),
                                     new DataField(2, "updatedtime", new 
TimestampType(3)),
-                                    new DataField(3, "microtime", new 
TimestampType(6))));
+                                    new DataField(3, "microtime", new 
TimestampType(6)),
+                                    new DataField(
+                                            4,
+                                            "localzonedtime",
+                                            new 
org.apache.paimon.types.LocalZonedTimestampType(
+                                                    3))));
             new SchemaManager(LocalFileIO.create(), tablePath6)
                     .createTable(
                             new Schema(
@@ -186,7 +191,8 @@ public abstract class TestTrinoITCase extends 
AbstractTestQueryFramework {
                             1,
                             Timestamp.fromMicros(1694505288000000L),
                             Timestamp.fromMicros(1694505288001000L),
-                            Timestamp.fromMicros(1694505288001001L)));
+                            Timestamp.fromMicros(1694505288001001L),
+                            Timestamp.fromMicros(1694505288002001L)));
             commit.commit(0, writer.prepareCommit(true, 0));
         }
 
@@ -453,11 +459,17 @@ public abstract class TestTrinoITCase extends 
AbstractTestQueryFramework {
 
     @Test
     public void testTimestamp0AndTimestamp3() {
-        assertThat(sql("SELECT * FROM paimon.default.t99"))
+        assertThat(sql("SELECT i, createdtime, updatedtime, microtime FROM 
paimon.default.t99"))
                 .isEqualTo(
                         "[[1, 2023-09-12T07:54:48, 2023-09-12T07:54:48.001, 
2023-09-12T07:54:48.001001]]");
     }
 
+    @Test
+    public void testTimestampWithTimeZone() {
+        assertThat(sql("SELECT localzonedtime FROM paimon.default.t99"))
+                .isEqualTo("[[2023-09-12T07:54:48.002Z[UTC]]]");
+    }
+
     private String sql(String sql) {
         MaterializedResult result = getQueryRunner().execute(sql);
         return result.getMaterializedRows().toString();

Reply via email to