You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "predator4ann (via GitHub)" <gi...@apache.org> on 2025/08/20 09:27:36 UTC

[PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

predator4ann opened a new pull request, #8216:
URL: https://github.com/apache/gravitino/pull/8216

   ### Why are the changes needed?
   
   Fix: #8215 
   
   ### Does this PR introduce _any_ user-facing change?
   
   No
   
   ### How was this patch tested?
   
   UT already added.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "predator4ann (via GitHub)" <gi...@apache.org>.
predator4ann commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2297586363


##########
trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-postgresql/00006_datatype.txt:
##########
@@ -17,17 +17,17 @@ CREATE TABLE
    f11 integer,
    f12 bigint,
    f13 date,
-   f14 time(6),
-   f15 timestamp(6),
-   f16 timestamp(6) with time zone
+   f14 time(3),
+   f15 timestamp(3),
+   f16 timestamp(3) with time zone
 )

Review Comment:
   When creating a pg table using Trino, if precision is not specified, the default value is 3. Although this change aligns with Trino's behavior, there are compatibility issues with Gravitino's historical data, and the necessity of this change needs to be considered. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "predator4ann (via GitHub)" <gi...@apache.org>.
predator4ann commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2297330379


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/utils/TypeUtils.java:
##########
@@ -36,6 +36,14 @@
 
 public class TypeUtils {
 
+  // Flink supports time/timestamp precision from 0 to 9 (nanosecond precision).
+  // @see
+  // https://nightlies.apache.org/flink/flink-docs-release-2.1/docs/dev/table/types/#date-and-time
+  protected static final int FLINK_SECONDS_PRECISION = 0;
+  protected static final int FLINK_MILLIS_PRECISION = 3;

Review Comment:
   done



##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/iceberg/IcebergDataTypeTransformer.java:
##########
@@ -59,14 +59,50 @@ public io.trino.spi.type.Type getTrinoType(Type type) {
     if (Name.FIXED == type.name()) {
       return VarbinaryType.VARBINARY;
     } else if (Name.TIME == type.name()) {
+      Types.TimeType timeType = (Types.TimeType) type;
+      if (timeType.hasPrecisionSet()) {
+        int precision = timeType.precision();
+        if (precision == TRINO_SECONDS_PRECISION) {
+          return TimeType.TIME_SECONDS;
+        } else if (precision <= TRINO_MILLIS_PRECISION) {
+          return TimeType.TIME_MILLIS;
+        } else if (precision <= TRINO_MICROS_PRECISION) {
+          return TimeType.TIME_MICROS;

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 merged PR #8216:
URL: https://github.com/apache/gravitino/pull/8216


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "predator4ann (via GitHub)" <gi...@apache.org>.
predator4ann commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2324606836


##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/iceberg/IcebergDataTypeTransformer.java:
##########
@@ -49,6 +49,15 @@ public Type getGravitinoType(io.trino.spi.type.Type type) {
             "Iceberg does not support the datatype VARCHAR with length");
       }
       return Types.StringType.get();
+    } else if (io.trino.spi.type.TimeType.class.isAssignableFrom(typeClass)) {
+      // Iceberg only supports time type with microsecond (6) precision
+      return Types.TimeType.of(TRINO_MICROS_PRECISION);

Review Comment:
   When creating an Iceberg table via Trino, whether it is timestamp or timestamp(0...12), the final mapped Iceberg data type is always timestamp(6).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2305928426


##########
trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-postgresql/00006_datatype.txt:
##########
@@ -17,17 +17,17 @@ CREATE TABLE
    f11 integer,
    f12 bigint,
    f13 date,
-   f14 time(6),
-   f15 timestamp(6),
-   f16 timestamp(6) with time zone
+   f14 time(3),
+   f15 timestamp(3),
+   f16 timestamp(3) with time zone
 )

Review Comment:
   OK



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2324216727


##########
trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-postgresql/00006_datatype.txt:
##########
@@ -17,17 +17,17 @@ CREATE TABLE
    f11 integer,
    f12 bigint,
    f13 date,
-   f14 time(6),
-   f15 timestamp(6),
-   f16 timestamp(6) with time zone
+   f14 time(3),
+   f15 timestamp(3),
+   f16 timestamp(3) with time zone
 )

Review Comment:
   Could you add tests without time precision?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2289704605


##########
flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/utils/TestTypeUtils.java:
##########


Review Comment:
   could you plz help review the Trino part? thanks! @diqiu50 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "predator4ann (via GitHub)" <gi...@apache.org>.
predator4ann commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2324608733


##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/hive/HiveDataTypeTransformer.java:
##########
@@ -72,6 +75,10 @@ public Type getGravitinoType(io.trino.spi.type.Type type) {
       }
 
       return Types.FixedCharType.of(charType.getLength());
+    } else if (io.trino.spi.type.TimestampType.class.isAssignableFrom(typeClass)) {
+      // When creating a table in Hive, the timestamp data type only supports not specifying
+      // precision, with the default precision being 3 (milliseconds precision)
+      return Types.TimestampType.withoutTimeZone();

Review Comment:
   When creating a Hive table via Trino, only timestamp and timestamp(3) are accepted, and the ultimately mapped Hive data type is always timestamp(3). Other types will result in an error. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "predator4ann (via GitHub)" <gi...@apache.org>.
predator4ann commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2297592143


##########
trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-postgresql/00006_datatype.txt:
##########
@@ -17,17 +17,17 @@ CREATE TABLE
    f11 integer,
    f12 bigint,
    f13 date,
-   f14 time(6),
-   f15 timestamp(6),
-   f16 timestamp(6) with time zone
+   f14 time(3),
+   f15 timestamp(3),
+   f16 timestamp(3) with time zone
 )

Review Comment:
   For trino-connector, the current behavior remains consistent with its original state: 
   - For mysql catalog, any precision or unspecified is precision=0 
   - For iceberg catalog, any precision or unspecified is precision=6
   - For postgresql catalog, when not specified, the default is 3; otherwise, it is min(precision, 6) 
   - For Hive catalog, it only accepts cases where precision is not specified, but the underlying precision is actually 3 
   - Default behavior, precision=3 if not specified, otherwise according to input (TIME is an alias for TIME(3) (millisecond precision). https://trino.io/docs/current/language/types.html#time)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2292522752


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/utils/TypeUtils.java:
##########
@@ -36,6 +36,14 @@
 
 public class TypeUtils {
 
+  // Flink supports time/timestamp precision from 0 to 9 (nanosecond precision).
+  // @see
+  // https://nightlies.apache.org/flink/flink-docs-release-2.1/docs/dev/table/types/#date-and-time
+  protected static final int FLINK_SECONDS_PRECISION = 0;
+  protected static final int FLINK_MILLIS_PRECISION = 3;

Review Comment:
   I don't see the usage of `FLINK_MILLIS_PRECISION`



##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/iceberg/IcebergDataTypeTransformer.java:
##########
@@ -59,14 +59,50 @@ public io.trino.spi.type.Type getTrinoType(Type type) {
     if (Name.FIXED == type.name()) {
       return VarbinaryType.VARBINARY;
     } else if (Name.TIME == type.name()) {
+      Types.TimeType timeType = (Types.TimeType) type;
+      if (timeType.hasPrecisionSet()) {
+        int precision = timeType.precision();
+        if (precision == TRINO_SECONDS_PRECISION) {
+          return TimeType.TIME_SECONDS;
+        } else if (precision <= TRINO_MILLIS_PRECISION) {
+          return TimeType.TIME_MILLIS;
+        } else if (precision <= TRINO_MICROS_PRECISION) {
+          return TimeType.TIME_MICROS;

Review Comment:
   why don't you use `TimeType.createTimeType(precision)` to use the corresponding precision?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2289695531


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/utils/TypeUtils.java:
##########
@@ -36,6 +36,12 @@
 
 public class TypeUtils {
 
+  // Flink supports timestamp precision from 0 to 9 (nanosecond precision).
+  protected static final int FLINK_SECONDS_PRECISION = 0;
+  protected static final int FLINK_MILLIS_PRECISION = 3;
+  protected static final int FLINK_MICROS_PRECISION = 6;
+  protected static final int FLINK_NANOS_PRECISION = 9;

Review Comment:
   Is there any Flink official doc description about this? If so, please attach to the code comment, thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2323951518


##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/iceberg/IcebergDataTypeTransformer.java:
##########
@@ -49,6 +49,15 @@ public Type getGravitinoType(io.trino.spi.type.Type type) {
             "Iceberg does not support the datatype VARCHAR with length");
       }
       return Types.StringType.get();
+    } else if (io.trino.spi.type.TimeType.class.isAssignableFrom(typeClass)) {
+      // Iceberg only supports time type with microsecond (6) precision
+      return Types.TimeType.of(TRINO_MICROS_PRECISION);

Review Comment:
   Same question as above: How does the behavior compare to the original Trino Iceberg connector?



##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/hive/HiveDataTypeTransformer.java:
##########
@@ -72,6 +75,10 @@ public Type getGravitinoType(io.trino.spi.type.Type type) {
       }
 
       return Types.FixedCharType.of(charType.getLength());
+    } else if (io.trino.spi.type.TimestampType.class.isAssignableFrom(typeClass)) {
+      // When creating a table in Hive, the timestamp data type only supports not specifying
+      // precision, with the default precision being 3 (milliseconds precision)
+      return Types.TimestampType.withoutTimeZone();

Review Comment:
   what's the result of creating a table using data type `timestamp(6)` by the original Trino Hive connector? 
   Will it throw an error, or will it silently use `timestamp(3)`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2305941115


##########
trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-postgresql/00006_datatype.txt:
##########
@@ -17,17 +17,17 @@ CREATE TABLE
    f11 integer,
    f12 bigint,
    f13 date,
-   f14 time(6),
-   f15 timestamp(6),
-   f16 timestamp(6) with time zone
+   f14 time(3),
+   f15 timestamp(3),
+   f16 timestamp(3) with time zone
 )

Review Comment:
   I see all the test cases for time without precision. Let me add more tests for time precision.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2297403704


##########
trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-postgresql/00006_datatype.txt:
##########
@@ -17,17 +17,17 @@ CREATE TABLE
    f11 integer,
    f12 bigint,
    f13 date,
-   f14 time(6),
-   f15 timestamp(6),
-   f16 timestamp(6) with time zone
+   f14 time(3),
+   f15 timestamp(3),
+   f16 timestamp(3) with time zone
 )

Review Comment:
   What is the reason for making this change?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "predator4ann (via GitHub)" <gi...@apache.org>.
predator4ann commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2297592143


##########
trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-postgresql/00006_datatype.txt:
##########
@@ -17,17 +17,17 @@ CREATE TABLE
    f11 integer,
    f12 bigint,
    f13 date,
-   f14 time(6),
-   f15 timestamp(6),
-   f16 timestamp(6) with time zone
+   f14 time(3),
+   f15 timestamp(3),
+   f16 timestamp(3) with time zone
 )

Review Comment:
   For trino-connector, the current behavior remains consistent with its original state: 
   - For mysql catalog, any precision or unspecified is precision=0 
   - For iceberg catalog, any precision or unspecified is precision=6
   - For postgresql catalog, when not specified, the default is 3; otherwise, it is min(precision, 6) 
   - For Hive catalog, it only accepts cases where precision is not specified, but the underlying precision is actually 3 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8215] connector(trino/flink): Support for reading/writing time precision [gravitino]

Posted by "predator4ann (via GitHub)" <gi...@apache.org>.
predator4ann commented on code in PR #8216:
URL: https://github.com/apache/gravitino/pull/8216#discussion_r2289779259


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/utils/TypeUtils.java:
##########
@@ -36,6 +36,12 @@
 
 public class TypeUtils {
 
+  // Flink supports timestamp precision from 0 to 9 (nanosecond precision).
+  protected static final int FLINK_SECONDS_PRECISION = 0;
+  protected static final int FLINK_MILLIS_PRECISION = 3;
+  protected static final int FLINK_MICROS_PRECISION = 6;
+  protected static final int FLINK_NANOS_PRECISION = 9;

Review Comment:
   Thanks for your time, comments added.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org