You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by lz...@apache.org on 2023/09/08 09:21:54 UTC
[incubator-paimon-trino] branch main updated: fix timestamp problem between trino schema and paimon schema (#28) (#29)
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 651adde fix timestamp problem between trino schema and paimon schema (#28) (#29)
651adde is described below
commit 651adde20b7d61687bf12ac274af95a576bb7166
Author: jjrrzxc <jj...@163.com>
AuthorDate: Fri Sep 8 17:21:49 2023 +0800
fix timestamp problem between trino schema and paimon schema (#28) (#29)
---
.../org/apache/paimon/trino/TrinoTypeUtils.java | 6 ++++--
.../java/org/apache/paimon/trino/TestTrinoType.java | 21 ++++++++++++++++-----
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/paimon-trino-common/src/main/java/org/apache/paimon/trino/TrinoTypeUtils.java b/paimon-trino-common/src/main/java/org/apache/paimon/trino/TrinoTypeUtils.java
index aec48df..5c7f8d8 100644
--- a/paimon-trino-common/src/main/java/org/apache/paimon/trino/TrinoTypeUtils.java
+++ b/paimon-trino-common/src/main/java/org/apache/paimon/trino/TrinoTypeUtils.java
@@ -152,7 +152,8 @@ public class TrinoTypeUtils {
@Override
public Type visit(TimestampType timestampType) {
- return io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS;
+ int precision = timestampType.getPrecision();
+ return io.trino.spi.type.TimestampType.createTimestampType(precision);
}
@Override
@@ -243,7 +244,8 @@ public class TrinoTypeUtils {
} else if (trinoType instanceof io.trino.spi.type.TimeType) {
return new TimeType();
} else if (trinoType instanceof io.trino.spi.type.TimestampType) {
- return DataTypes.TIMESTAMP();
+ int precision = ((io.trino.spi.type.TimestampType) trinoType).getPrecision();
+ return new TimestampType(precision);
} else if (trinoType instanceof TimestampWithTimeZoneType) {
return DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE();
} else if (trinoType instanceof io.trino.spi.type.ArrayType) {
diff --git a/paimon-trino-common/src/test/java/org/apache/paimon/trino/TestTrinoType.java b/paimon-trino-common/src/test/java/org/apache/paimon/trino/TestTrinoType.java
index 603fa8b..cdb52c3 100644
--- a/paimon-trino-common/src/test/java/org/apache/paimon/trino/TestTrinoType.java
+++ b/paimon-trino-common/src/test/java/org/apache/paimon/trino/TestTrinoType.java
@@ -103,9 +103,14 @@ public class TestTrinoType {
Type timeType = TrinoTypeUtils.fromPaimonType(new TimeType());
assertThat(Objects.requireNonNull(timeType).getDisplayName()).isEqualTo("time(3)");
- Type timestampType = TrinoTypeUtils.fromPaimonType(DataTypes.TIMESTAMP());
- assertThat(Objects.requireNonNull(timestampType).getDisplayName())
- .isEqualTo("timestamp(3)");
+ Type timestampType6 = TrinoTypeUtils.fromPaimonType(DataTypes.TIMESTAMP());
+ assertThat(Objects.requireNonNull(timestampType6).getDisplayName())
+ .isEqualTo("timestamp(6)");
+
+ Type timestampType0 =
+ TrinoTypeUtils.fromPaimonType(new org.apache.paimon.types.TimestampType(0));
+ assertThat(Objects.requireNonNull(timestampType0).getDisplayName())
+ .isEqualTo("timestamp(0)");
Type localZonedTimestampType =
TrinoTypeUtils.fromPaimonType(DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE());
@@ -176,8 +181,14 @@ public class TestTrinoType {
DataType timeType = TrinoTypeUtils.toPaimonType(io.trino.spi.type.TimeType.TIME_MILLIS);
assertThat(timeType.asSQLString()).isEqualTo("TIME(0)");
- DataType timestampType = TrinoTypeUtils.toPaimonType(TimestampType.TIMESTAMP_MILLIS);
- assertThat(timestampType.asSQLString()).isEqualTo("TIMESTAMP(6)");
+ DataType timestampType0 = TrinoTypeUtils.toPaimonType(TimestampType.TIMESTAMP_SECONDS);
+ assertThat(timestampType0.asSQLString()).isEqualTo("TIMESTAMP(0)");
+
+ DataType timestampType3 = TrinoTypeUtils.toPaimonType(TimestampType.TIMESTAMP_MILLIS);
+ assertThat(timestampType3.asSQLString()).isEqualTo("TIMESTAMP(3)");
+
+ DataType timestampType6 = TrinoTypeUtils.toPaimonType(TimestampType.TIMESTAMP_MICROS);
+ assertThat(timestampType6.asSQLString()).isEqualTo("TIMESTAMP(6)");
DataType timestampWithTimeZoneType =
TrinoTypeUtils.toPaimonType(TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS);