World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#6656] fix(catalog): support read time/datetime/timestamp columns with precision (#6657)
predator4ann5aa1adc081c8
diff --git a/api/src/main/java/org/apache/gravitino/rel/types/Type.java b/api/src/main/java/org/apache/gravitino/rel/types/Type.javaindex bfb7408dd9..fe6d72f6b9 100644--- a/api/src/main/java/org/apache/gravitino/rel/types/Type.java+++ b/api/src/main/java/org/apache/gravitino/rel/types/Type.java@@ -106,7 +106,23 @@ public interface Type {abstract class NumericType extends PrimitiveType {}/** The base type of all date/time types. */- abstract class DateTimeType extends PrimitiveType {}+ abstract class DateTimeType extends PrimitiveType {+ /**+ * Indicates that precision for the date/time type was not explicitly set by the user. The value+ * should be converted to the catalog's default precision.+ */+ protected static final int DATE_TIME_PRECISION_NOT_SET = -1;+ /**+ * Represents the minimum precision range for timestamp, time and other date/time types. The+ * minimum precision is 0, which means second-level precision.+ */+ protected static final int MIN_ALLOWED_PRECISION = 0;+ /**+ * Represents the maximum precision allowed for timestamp, time and other date/time types. The+ * maximum precision is 12, which means picosecond-level precision.+ */+ protected static final int MAX_ALLOWED_PRECISION = 12;+ }/** The base type of all interval types. */abstract class IntervalType extends PrimitiveType {}diff --git a/api/src/main/java/org/apache/gravitino/rel/types/Types.java b/api/src/main/java/org/apache/gravitino/rel/types/Types.javaindex 660ce3935f..61520f4220 100644--- a/api/src/main/java/org/apache/gravitino/rel/types/Types.java+++ b/api/src/main/java/org/apache/gravitino/rel/types/Types.java@@ -337,7 +337,39 @@ public class Types {return INSTANCE;}- private TimeType() {}+ /**+ * @param precision The precision of the time type.+ * @return A {@link TimeType} with the given precision.+ */+ public static TimeType of(int precision) {+ Preconditions.checkArgument(+ precision >= MIN_ALLOWED_PRECISION && precision <= MAX_ALLOWED_PRECISION,+ "precision must be in range [%s, %s]: precision: %s",+ MIN_ALLOWED_PRECISION,+ MAX_ALLOWED_PRECISION,+ precision);+ return new TimeType(precision);+ }++ private final int precision;++ private TimeType() {+ this(DATE_TIME_PRECISION_NOT_SET);+ }++ private TimeType(int precision) {+ this.precision = precision;+ }++ /** @return The precision of the time type. */+ public int precision() {+ return precision;+ }++ /** @return True if the time type has precision set, false otherwise. */+ public boolean hasPrecisionSet() {+ return precision != DATE_TIME_PRECISION_NOT_SET;+ }@Overridepublic Name name() {@@ -346,7 +378,25 @@ public class Types {@Overridepublic String simpleString() {- return "time";+ return hasPrecisionSet() ? String.format("time(%d)", precision) : "time";+ }++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (!(o instanceof TimeType)) return false;+ TimeType that = (TimeType) o;+ return precision == that.precision;+ }++ @Override+ public int hashCode() {+ return precision;+ }++ @Override+ public String toString() {+ return "TimeType{" + "precision=" + precision + '}';}}@@ -355,20 +405,54 @@ public class Types {private static final TimestampType INSTANCE_WITHOUT_TIME_ZONE = new TimestampType(false);private static final TimestampType INSTANCE_WITH_TIME_ZONE = new TimestampType(true);+ /** @return A {@link TimestampType} without time zone. */+ public static TimestampType withoutTimeZone() {+ return INSTANCE_WITHOUT_TIME_ZONE;+ }+/** @return A {@link TimestampType} with time zone. */public static TimestampType withTimeZone() {return INSTANCE_WITH_TIME_ZONE;}- /** @return A {@link TimestampType} without time zone. */- public static TimestampType withoutTimeZone() {- return INSTANCE_WITHOUT_TIME_ZONE;+ /**+ * @param precision The precision of the timestamp type.+ * @return A {@link TimestampType} with the given precision and without time zone.+ */+ public static TimestampType withoutTimeZone(int precision) {+ Preconditions.checkArgument(+ precision >= MIN_ALLOWED_PRECISION && precision <= MAX_ALLOWED_PRECISION,+ "precision must be in range [%s, %s]: precision: %s",+ MIN_ALLOWED_PRECISION,+ MAX_ALLOWED_PRECISION,+ precision);+ return new TimestampType(false, precision);+ }++ /**+ * @param precision The precision of the timestamp type.+ * @return A {@link TimestampType} with the given precision and time zone.+ */+ public static TimestampType withTimeZone(int precision) {+ Preconditions.checkArgument(+ precision >= MIN_ALLOWED_PRECISION && precision <= MAX_ALLOWED_PRECISION,+ "precision must be in range [%s, %s]: precision: %s",+ MIN_ALLOWED_PRECISION,+ MAX_ALLOWED_PRECISION,+ precision);+ return new TimestampType(true, precision);}private final boolean withTimeZone;+ private final int precision;private TimestampType(boolean withTimeZone) {+ this(withTimeZone, DATE_TIME_PRECISION_NOT_SET);+ }++ private TimestampType(boolean withTimeZone, int precision) {this.withTimeZone = withTimeZone;+ this.precision = precision;}/** @return True if the timestamp type has time zone, false otherwise. */@@ -376,6 +460,16 @@ public class Types {return withTimeZone;}+ /** @return The precision of the timestamp type. */+ public int precision() {+ return precision;+ }++ /** @return True if the timestamp type has precision set, false otherwise. */+ public boolean hasPrecisionSet() {+ return precision != DATE_TIME_PRECISION_NOT_SET;+ }+@Overridepublic Name name() {return Name.TIMESTAMP;@@ -384,7 +478,29 @@ public class Types {/** @return The simple string representation of the timestamp type. */@Overridepublic String simpleString() {- return withTimeZone ? "timestamp_tz" : "timestamp";+ return hasPrecisionSet()+ ? withTimeZone+ ? String.format("timestamp_tz(%d)", precision)+ : String.format("timestamp(%d)", precision)+ : withTimeZone ? "timestamp_tz" : "timestamp";+ }++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (!(o instanceof TimestampType)) return false;+ TimestampType that = (TimestampType) o;+ return withTimeZone == that.withTimeZone && precision == that.precision;+ }++ @Override+ public int hashCode() {+ return Objects.hash(withTimeZone, precision);+ }++ @Override+ public String toString() {+ return "TimestampType{" + "withTimeZone=" + withTimeZone + ", precision=" + precision + '}';}}diff --git a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/converter/JdbcTypeConverter.java b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/converter/JdbcTypeConverter.javaindex 140d93e879..6a0e9bbcd8 100644--- a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/converter/JdbcTypeConverter.java+++ b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/converter/JdbcTypeConverter.java@@ -29,6 +29,7 @@ public abstract class JdbcTypeConverterpublic static final String TIMESTAMP = "timestamp";public static final String VARCHAR = "varchar";public static final String TEXT = "text";+ public static final int PRECISION_SECOND = 0;public static class JdbcTypeBean {/** Data type name. */@@ -40,6 +41,8 @@ public abstract class JdbcTypeConverter/** Scale. For example: 2 in decimal (10,2). */private Integer scale;+ private Integer datetimePrecision;+public JdbcTypeBean(String typeName) {this.typeName = typeName;}@@ -68,6 +71,14 @@ public abstract class JdbcTypeConverterthis.scale = scale;}+ public Integer getDatetimePrecision() {+ return datetimePrecision;+ }++ public void setDatetimePrecision(Integer datetimePrecision) {+ this.datetimePrecision = datetimePrecision;+ }+@Overridepublic boolean equals(Object o) {if (this == o) return true;@@ -75,12 +86,13 @@ public abstract class JdbcTypeConverterJdbcTypeBean typeBean = (JdbcTypeBean) o;return Objects.equals(typeName, typeBean.typeName)&& Objects.equals(columnSize, typeBean.columnSize)- && Objects.equals(scale, typeBean.scale);+ && Objects.equals(scale, typeBean.scale)+ && Objects.equals(datetimePrecision, typeBean.datetimePrecision);}@Overridepublic int hashCode() {- return Objects.hash(typeName, columnSize, scale);+ return Objects.hash(typeName, columnSize, scale, datetimePrecision);}@Override@@ -95,6 +107,9 @@ public abstract class JdbcTypeConverter+ ", scale='"+ scale+ '\''+ + ", datetimePrecision='"+ + datetimePrecision+ + '\''+ '}';}}diff --git a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.javaindex 532921af9b..b421694f29 100644--- a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java+++ b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java@@ -33,6 +33,8 @@ import java.util.Map;import java.util.Objects;import java.util.Optional;import java.util.Set;+import java.util.regex.Matcher;+import java.util.regex.Pattern;import java.util.stream.Collectors;import javax.sql.DataSource;import org.apache.commons.lang3.StringUtils;@@ -66,6 +68,8 @@ public abstract class JdbcTableOperations implements TableOperation {public static final String COMMENT = "COMMENT";public static final String SPACE = " ";+ public static final String TIME_FORMAT_WITH_DOT = "HH:MM:SS.";+ public static final String DATETIME_FORMAT_WITH_DOT = "YYYY-MM-DD HH:MM:SS.";public static final String MODIFY_COLUMN = "MODIFY COLUMN ";public static final String AFTER = "AFTER ";@@ -607,10 +611,15 @@ public abstract class JdbcTableOperations implements TableOperation {}protected JdbcColumn.Builder getBasicJdbcColumnInfo(ResultSet column) throws SQLException {- JdbcTypeConverter.JdbcTypeBean typeBean =- new JdbcTypeConverter.JdbcTypeBean(column.getString("TYPE_NAME"));- typeBean.setColumnSize(column.getInt("COLUMN_SIZE"));- typeBean.setScale(column.getInt("DECIMAL_DIGITS"));+ String typeName = column.getString("TYPE_NAME");+ int columnSize = column.getInt("COLUMN_SIZE");+ int scale = column.getInt("DECIMAL_DIGITS");+ JdbcTypeConverter.JdbcTypeBean typeBean = new JdbcTypeConverter.JdbcTypeBean(typeName);+ typeBean.setColumnSize(columnSize);+ typeBean.setScale(scale);+ Integer datetimePrecision = calculateDatetimePrecision(typeName, columnSize, scale);+ typeBean.setDatetimePrecision(datetimePrecision);+String comment = column.getString("REMARKS");boolean nullable = column.getBoolean("NULLABLE");@@ -626,4 +635,123 @@ public abstract class JdbcTableOperations implements TableOperation {.withNullable(nullable).withDefaultValue(defaultValue);}++ /**+ * Calculate the precision for time/datetime/timestamp types.+ *+ * <p>This method provides a default behavior returning null for catalogs that do not implement+ * this method. Developers should override this method when their database supports precision+ * specification for datetime types.+ *+ * <p><strong>When to return null:</strong>+ *+ * <ul>+ * <li>When the database does not support precision for datetime types+ * <li>When the driver version is incompatible (e.g., MySQL driver < 8.0.16)+ * <li>When the type is not a datetime type (TIME, TIMESTAMP, DATETIME)+ * <li>When the precision cannot be accurately calculated from the provided parameters+ * </ul>+ *+ * <p><strong>When to return non-null:</strong>+ *+ * <ul>+ * <li>When the database supports precision for datetime types and the driver version is+ * compatible+ * <li>When the precision can be accurately calculated from columnSize (e.g., columnSize -+ * format_length)+ * <li>For TIME types: return columnSize - 8 (for 'HH:MM:SS' format)+ * <li>For TIMESTAMP/DATETIME types: return columnSize - 19 (for 'YYYY-MM-DD HH:MM:SS' format)+ * </ul>+ *+ * <p><strong>Examples:</strong>+ *+ * <ul>+ * <li>TIME(3) with columnSize=11: return 3 (11-8)+ * <li>TIMESTAMP(6) with columnSize=25: return 6 (25-19)+ * <li>DATETIME(0) with columnSize=19: return 0 (19-19)+ * </ul>+ *+ * @param typeName the type name from database (e.g., "TIME", "TIMESTAMP", "DATETIME")+ * @param columnSize the column size from database (total length including format and precision)+ * @param scale the scale from database (usually 0 for datetime types)+ * @return the precision of the time/datetime/timestamp type, or null if not supported/calculable+ */+ public Integer calculateDatetimePrecision(String typeName, int columnSize, int scale) {+ return null;+ }++ /**+ * Get MySQL driver version from DatabaseMetaData+ *+ * @return the driver version string, or null if not available+ */+ protected String getMySQLDriverVersion() {+ try {+ if (dataSource != null) {+ try (Connection connection = dataSource.getConnection()) {+ return connection.getMetaData().getDriverVersion();+ }+ }+ } catch (SQLException e) {+ LOG.debug("Failed to get driver version", e);+ }+ return null;+ }++ /**+ * Check if driver version supports accurate columnSize for precision calculation. For MySQL+ * driver: Only versions >= 8.0.16 return accurate columnSize for datetime precision. For other+ * drivers (like OceanBase): Assume they support accurate precision calculation+ *+ * <p>MySQL Connector/J 8.0.16 fixed the wrong handling of temporal type precision in the+ * DatabaseMetaDataUsingInfoSchema interface, where getColumns() method returned wrong results for+ * the COLUMN_SIZE column. Prior versions had errors in temporal type precision handling.+ *+ * @param driverVersion the driver version string to check+ * @return true if the driver version supports accurate precision calculation, false otherwise+ * @see <a href="https://dev.mysql.com/doc/relnotes/connector-j/en/news-8-0-16.html">MySQL+ * Connector/J 8.0.16 Release Notes</a>+ */+ public boolean isMySQLDriverVersionSupported(String driverVersion) {+ if (StringUtils.isBlank(driverVersion)) {+ return false;+ }++ // For non-MySQL drivers, assume they support accurate precision calculation+ if (!driverVersion.startsWith("mysql-connector-java-")) {+ LOG.debug(+ "Non-MySQL driver detected: {}. Assuming it supports accurate precision calculation.",+ driverVersion);+ return true;+ }++ // Extract version from driver string like "mysql-connector-java-8.0.19 (Revision: ...)"+ String versionPattern = "mysql-connector-java-(\\d+\\.\\d+\\.\\d+)";+ Pattern pattern = Pattern.compile(versionPattern);+ Matcher matcher = pattern.matcher(driverVersion);++ if (matcher.find()) {+ String versionStr = matcher.group(1);+ try {+ String[] parts = versionStr.split("\\.");+ int major = Integer.parseInt(parts[0]);+ int minor = Integer.parseInt(parts[1]);+ int patch = Integer.parseInt(parts[2]);++ // Check if version >= 8.0.16+ if (major > 8) {+ return true;+ } else if (major == 8 && minor > 0) {+ return true;+ } else {+ return major == 8 && minor == 0 && patch >= 16;+ }+ } catch (NumberFormatException e) {+ LOG.debug("Failed to parse driver version: {}", versionStr, e);+ return false;+ }+ }++ return false;+ }}diff --git a/catalogs/catalog-jdbc-common/src/test/java/org/apache/gravitino/catalog/jdbc/operation/TestJdbcTableOperations.java b/catalogs/catalog-jdbc-common/src/test/java/org/apache/gravitino/catalog/jdbc/operation/TestJdbcTableOperations.javaindex 3e3172cddc..ff8fcf8bb7 100644--- a/catalogs/catalog-jdbc-common/src/test/java/org/apache/gravitino/catalog/jdbc/operation/TestJdbcTableOperations.java+++ b/catalogs/catalog-jdbc-common/src/test/java/org/apache/gravitino/catalog/jdbc/operation/TestJdbcTableOperations.java@@ -211,6 +211,40 @@ public class TestJdbcTableOperations {JDBC_TABLE_OPERATIONS.drop(DATABASE_NAME, newName), "table should be non-existent");}+ @Test+ public void testDriverVersionParsing() {+ // Test supported MySQL versions+ Assertions.assertTrue(+ JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("mysql-connector-java-8.0.16"));+ Assertions.assertTrue(+ JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("mysql-connector-java-8.0.19"));+ Assertions.assertTrue(+ JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("mysql-connector-java-8.1.0"));+ Assertions.assertTrue(+ JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("mysql-connector-java-9.0.0"));++ // Test unsupported MySQL versions+ Assertions.assertFalse(+ JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("mysql-connector-java-8.0.15"));+ Assertions.assertFalse(+ JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("mysql-connector-java-8.0.11"));+ Assertions.assertFalse(+ JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("mysql-connector-java-5.1.24"));++ // Test invalid MySQL formats+ Assertions.assertFalse(+ JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("mysql-connector-java-invalid"));+ Assertions.assertFalse(JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported(""));+ Assertions.assertFalse(JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported(null));++ // Test non-MySQL drivers (should be supported)+ Assertions.assertTrue(+ JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("com.oceanbase.jdbc.Driver"));+ Assertions.assertTrue(+ JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("org.postgresql.Driver"));+ Assertions.assertTrue(JDBC_TABLE_OPERATIONS.isMySQLDriverVersionSupported("org.sqlite.JDBC"));+ }+private static JdbcColumn[] generateRandomColumn(int minSize, int maxSize) {Random r = new Random();String prefixColName = "col_";diff --git a/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/converter/DorisTypeConverter.java b/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/converter/DorisTypeConverter.javaindex abc85c4c7f..6fa342aef6 100644--- a/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/converter/DorisTypeConverter.java+++ b/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/converter/DorisTypeConverter.java@@ -18,6 +18,7 @@*/package org.apache.gravitino.catalog.doris.converter;+import java.util.Optional;import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.rel.types.Types;@@ -58,7 +59,9 @@ public class DorisTypeConverter extends JdbcTypeConverter {case DATE:return Types.DateType.get();case DATETIME:- return Types.TimestampType.withoutTimeZone();+ return Optional.ofNullable(typeBean.getDatetimePrecision())+ .map(Types.TimestampType::withoutTimeZone)+ .orElseGet(Types.TimestampType::withoutTimeZone);case CHAR:return Types.FixedCharType.of(typeBean.getColumnSize());case VARCHAR:@@ -97,7 +100,10 @@ public class DorisTypeConverter extends JdbcTypeConverter {} else if (type instanceof Types.DateType) {return DATE;} else if (type instanceof Types.TimestampType) {- return DATETIME;+ Types.TimestampType timestampType = (Types.TimestampType) type;+ return timestampType.hasPrecisionSet()+ ? String.format("%s(%d)", DATETIME, timestampType.precision())+ : DATETIME;} else if (type instanceof Types.VarCharType) {int length = ((Types.VarCharType) type).length();if (length < 1 || length > 65533) {diff --git a/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java b/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.javaindex 4a15e23449..108d0440d2 100644--- a/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java+++ b/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java@@ -795,4 +795,33 @@ public class DorisTableOperations extends JdbcTableOperations {return DorisUtils.extractDistributionInfoFromSql(createTableSyntax);}}++ @Override+ public Integer calculateDatetimePrecision(String typeName, int columnSize, int scale) {+ String upperTypeName = typeName.toUpperCase();++ // Check driver version compatibility first+ boolean isDatetimeType = "DATETIME".equals(upperTypeName);++ if (isDatetimeType) {+ String driverVersion = getMySQLDriverVersion();+ if (driverVersion != null && !isMySQLDriverVersionSupported(driverVersion)) {+ LOG.warn(+ "MySQL driver version {} is below 8.0.16, columnSize may not be accurate for precision calculation. "+ + "Returning null for {} type precision. Driver version: {}",+ driverVersion,+ upperTypeName,+ driverVersion);+ return null;+ }+ }++ if (upperTypeName.equals("DATETIME")) {+ // DATETIME format: 'YYYY-MM-DD HH:MM:SS' (19 chars) + decimal point + precision+ return columnSize >= DATETIME_FORMAT_WITH_DOT.length()+ ? columnSize - DATETIME_FORMAT_WITH_DOT.length()+ : 0;+ }+ return null;+ }}diff --git a/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/converter/TestDorisTypeConverter.java b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/converter/TestDorisTypeConverter.javanew file mode 100644index 0000000000..2b5a50d310--- /dev/null+++ b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/converter/TestDorisTypeConverter.java@@ -0,0 +1,116 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one+ * or more contributor license agreements. See the NOTICE file+ * distributed with this work for additional information+ * regarding copyright ownership. The ASF licenses this file+ * to you under the Apache License, Version 2.0 (the+ * "License"); you may not use this file except in compliance+ * with the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing,+ * software distributed under the License is distributed on an+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+ * KIND, either express or implied. See the License for the+ * specific language governing permissions and limitations+ * under the License.+ */+package org.apache.gravitino.catalog.doris.converter;++import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.BIGINT;+import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.BOOLEAN;+import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.CHAR;+import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.DATETIME;+import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.DECIMAL;+import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.DOUBLE;+import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.FLOAT;+import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.INT;+import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.SMALLINT;+import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.STRING;+import static org.apache.gravitino.catalog.doris.converter.DorisTypeConverter.TINYINT;+import static org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter.DATE;+import static org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter.TEXT;+import static org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter.VARCHAR;++import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;+import org.apache.gravitino.rel.types.Type;+import org.apache.gravitino.rel.types.Types;+import org.junit.jupiter.api.Assertions;+import org.junit.jupiter.api.Test;++/** Test class for {@link org.apache.gravitino.catalog.doris.converter.DorisTypeConverter} */+public class TestDorisTypeConverter {++ private static final DorisTypeConverter DORIS_TYPE_CONVERTER = new DorisTypeConverter();+ private static final String USER_DEFINED_TYPE = "user-defined";++ @Test+ public void testToGravitinoType() {+ checkJdbcTypeToGravitinoType(Types.BooleanType.get(), BOOLEAN, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.ByteType.get(), TINYINT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.ShortType.get(), SMALLINT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.IntegerType.get(), INT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.LongType.get(), BIGINT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.FloatType.get(), FLOAT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.DoubleType.get(), DOUBLE, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.DateType.get(), DATE, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(0), DATETIME, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(0), DATETIME, 19, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(3), DATETIME, 23, null, 3);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(6), DATETIME, 26, null, 6);+ checkJdbcTypeToGravitinoType(Types.DecimalType.of(10, 2), DECIMAL, 10, 2, 0);+ checkJdbcTypeToGravitinoType(Types.VarCharType.of(20), VARCHAR, 20, null, 0);+ checkJdbcTypeToGravitinoType(Types.FixedCharType.of(20), CHAR, 20, null, 0);+ checkJdbcTypeToGravitinoType(Types.StringType.get(), STRING, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.StringType.get(), TEXT, null, null, 0);+ checkJdbcTypeToGravitinoType(+ Types.ExternalType.of(USER_DEFINED_TYPE), USER_DEFINED_TYPE, null, null, 0);+ }++ @Test+ public void testFromGravitinoType() {+ checkGravitinoTypeToJdbcType(BOOLEAN, Types.BooleanType.get());+ checkGravitinoTypeToJdbcType(TINYINT, Types.ByteType.get());+ checkGravitinoTypeToJdbcType(SMALLINT, Types.ShortType.get());+ checkGravitinoTypeToJdbcType(INT, Types.IntegerType.get());+ checkGravitinoTypeToJdbcType(BIGINT, Types.LongType.get());+ checkGravitinoTypeToJdbcType(FLOAT, Types.FloatType.get());+ checkGravitinoTypeToJdbcType(DOUBLE, Types.DoubleType.get());+ checkGravitinoTypeToJdbcType(DATE, Types.DateType.get());+ checkGravitinoTypeToJdbcType(DATETIME, Types.TimestampType.withoutTimeZone());+ checkGravitinoTypeToJdbcType(DECIMAL + "(10,2)", Types.DecimalType.of(10, 2));+ checkGravitinoTypeToJdbcType(VARCHAR + "(20)", Types.VarCharType.of(20));+ checkGravitinoTypeToJdbcType(CHAR + "(20)", Types.FixedCharType.of(20));+ checkGravitinoTypeToJdbcType(STRING, Types.StringType.get());+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () -> DORIS_TYPE_CONVERTER.fromGravitino(Types.UnparsedType.of(USER_DEFINED_TYPE)));+ }++ protected void checkGravitinoTypeToJdbcType(String jdbcTypeName, Type gravitinoType) {+ Assertions.assertEquals(jdbcTypeName, DORIS_TYPE_CONVERTER.fromGravitino(gravitinoType));+ }++ protected void checkJdbcTypeToGravitinoType(+ Type gravitinoType,+ String jdbcTypeName,+ Integer columnSize,+ Integer scale,+ Integer datetimePrecision) {+ JdbcTypeConverter.JdbcTypeBean typeBean =+ createTypeBean(jdbcTypeName, columnSize, scale, datetimePrecision);+ Assertions.assertEquals(gravitinoType, DORIS_TYPE_CONVERTER.toGravitino(typeBean));+ }++ protected static JdbcTypeConverter.JdbcTypeBean createTypeBean(+ String typeName, Integer columnSize, Integer scale, Integer datetimePrecision) {+ return new JdbcTypeConverter.JdbcTypeBean(typeName) {+ {+ setColumnSize(columnSize);+ setScale(scale);+ setDatetimePrecision(datetimePrecision);+ }+ };+ }+}diff --git a/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/integration/test/CatalogDorisIT.java b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/integration/test/CatalogDorisIT.javaindex 11911bba47..47d9f851f3 100644--- a/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/integration/test/CatalogDorisIT.java+++ b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/integration/test/CatalogDorisIT.java@@ -877,12 +877,17 @@ public class CatalogDorisIT extends BaseIT {@Testvoid testTableWithTimeStampColumn() {- // create a tableString tableName = GravitinoITUtils.genRandomName("test_table_with_timestamp_column");NameIdentifier tableIdentifier = NameIdentifier.of(schemaName, tableName);Column[] columns = createColumns();columns =- ArrayUtils.add(columns, Column.of("timestamp_col", Types.TimestampType.withoutTimeZone()));+ ArrayUtils.addAll(+ columns,+ Column.of("datetime_col", Types.TimestampType.withoutTimeZone()),+ Column.of("datetime_col_0", Types.TimestampType.withoutTimeZone(0)),+ Column.of("datetime_col_1", Types.TimestampType.withoutTimeZone(1)),+ Column.of("datetime_col_3", Types.TimestampType.withoutTimeZone(3)),+ Column.of("datetime_col_6", Types.TimestampType.withoutTimeZone(6)));Distribution distribution = createDistribution();Index[] indexes =new Index[] {@@ -900,15 +905,35 @@ public class CatalogDorisIT extends BaseIT {null,indexes);- // load tableTable loadTable = tableCatalog.loadTable(tableIdentifier);- Column timestampColumn =- Arrays.stream(loadTable.columns())- .filter(c -> "timestamp_col".equals(c.name()))- .findFirst()- .get();- Assertions.assertEquals(Types.TimestampType.withoutTimeZone(), timestampColumn.dataType());+ // Verify datetime type precisions+ Column[] datetimeColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("datetime_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(5, datetimeColumns.length);++ for (Column column : datetimeColumns) {+ switch (column.name()) {+ case "datetime_col":+ case "datetime_col_0":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(0), column.dataType());+ break;+ case "datetime_col_1":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(1), column.dataType());+ break;+ case "datetime_col_3":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(3), column.dataType());+ break;+ case "datetime_col_6":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected datetime column: " + column.name());+ }+ }}@Testdiff --git a/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperations.java b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperations.javaindex dd164473b4..a35d165843 100644--- a/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperations.java+++ b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperations.java@@ -436,7 +436,7 @@ public class TestDorisTableOperations extends TestDoris {columns.add(JdbcColumn.builder().withName("col_14")- .withType(Types.TimestampType.withoutTimeZone())+ .withType(Types.TimestampType.withoutTimeZone(0)).build());Distribution distribution =@@ -688,4 +688,55 @@ public class TestDorisTableOperations extends TestDoris {sql = DorisTableOperations.deleteIndexDefinition(load, deleteIndex3);Assertions.assertEquals("DROP INDEX uk_2", sql);}++ @Test+ public void testCalculateDatetimePrecision() {+ Assertions.assertNull(+ TABLE_OPERATIONS.calculateDatetimePrecision("DATE", 10, 0),+ "DATE type should return 0 precision");++ Assertions.assertEquals(+ 0,+ TABLE_OPERATIONS.calculateDatetimePrecision("DATETIME", 20, 0),+ "TIME type should return 0 precision");++ Assertions.assertEquals(+ 3,+ TABLE_OPERATIONS.calculateDatetimePrecision("DATETIME", 23, 0),+ "TIMESTAMP type should return 0 precision");++ Assertions.assertEquals(+ 6,+ TABLE_OPERATIONS.calculateDatetimePrecision("DATETIME", 26, 0),+ "TIMESTAMP type should return 0 precision");++ Assertions.assertEquals(+ 9,+ TABLE_OPERATIONS.calculateDatetimePrecision("DATETIME", 29, 0),+ "Lower case type name should work");++ Assertions.assertNull(+ TABLE_OPERATIONS.calculateDatetimePrecision("VARCHAR", 50, 0),+ "Non-datetime type should return 0 precision");+ }++ @Test+ public void testCalculateDatetimePrecisionWithUnsupportedDriverVersion() {+ DorisTableOperations operationsWithOldDriver =+ new DorisTableOperations() {+ @Override+ protected String getMySQLDriverVersion() {+ return "mysql-connector-java-8.0.11 (Revision: a0ca826f5cdf51a98356fdfb1bf251eb042f80bf)";+ }++ @Override+ public boolean isMySQLDriverVersionSupported(String driverVersion) {+ return false;+ }+ };++ Assertions.assertNull(+ operationsWithOldDriver.calculateDatetimePrecision("DATETIME", 26, 0),+ "DATETIME type should return null for unsupported driver version");+ }}diff --git a/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/converter/MysqlColumnDefaultValueConverter.java b/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/converter/MysqlColumnDefaultValueConverter.javaindex 52aa9c86c2..d0acb60387 100644--- a/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/converter/MysqlColumnDefaultValueConverter.java+++ b/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/converter/MysqlColumnDefaultValueConverter.java@@ -24,6 +24,8 @@ import static org.apache.gravitino.rel.Column.DEFAULT_VALUE_OF_CURRENT_TIMESTAMPimport java.time.LocalDate;import java.time.LocalDateTime;import java.time.LocalTime;+import java.time.format.DateTimeFormatter;+import java.time.format.DateTimeParseException;import org.apache.gravitino.catalog.jdbc.converter.JdbcColumnDefaultValueConverter;import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;import org.apache.gravitino.rel.expressions.Expression;@@ -34,6 +36,9 @@ import org.apache.gravitino.rel.types.Types;public class MysqlColumnDefaultValueConverter extends JdbcColumnDefaultValueConverter {+ private static final DateTimeFormatter DATE_TIME_FORMATTER =+ DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss[.SSSSSS][.SSSSS][.SSSS][.SSS][.SS][.S]");+@Overridepublic Expression toGravitino(JdbcTypeConverter.JdbcTypeBean type,@@ -49,7 +54,7 @@ public class MysqlColumnDefaultValueConverter extends JdbcColumnDefaultValueConv}if (isExpression) {- if (columnDefaultValue.equals(CURRENT_TIMESTAMP)) {+ if (columnDefaultValue.startsWith(CURRENT_TIMESTAMP)) {return DEFAULT_VALUE_OF_CURRENT_TIMESTAMP;}// The parsing of MySQL expressions is complex, so we are not currently undertaking the@@ -88,10 +93,16 @@ public class MysqlColumnDefaultValueConverter extends JdbcColumnDefaultValueConvreturn Literals.timeLiteral(LocalTime.parse(columnDefaultValue, DATE_TIME_FORMATTER));case JdbcTypeConverter.TIMESTAMP:case MysqlTypeConverter.DATETIME:- return CURRENT_TIMESTAMP.equals(columnDefaultValue)- ? DEFAULT_VALUE_OF_CURRENT_TIMESTAMP- : Literals.timestampLiteral(- LocalDateTime.parse(columnDefaultValue, DATE_TIME_FORMATTER));+ if (columnDefaultValue.startsWith(CURRENT_TIMESTAMP)) {+ return DEFAULT_VALUE_OF_CURRENT_TIMESTAMP;+ }+ try {+ return Literals.timestampLiteral(+ LocalDateTime.parse(columnDefaultValue, DATE_TIME_FORMATTER));+ } catch (DateTimeParseException e) {+ throw new IllegalArgumentException(+ String.format("Unable to parse datetime value: %s", columnDefaultValue));+ }case JdbcTypeConverter.VARCHAR:return Literals.of(columnDefaultValue, Types.VarCharType.of(type.getColumnSize()));case MysqlTypeConverter.CHAR:diff --git a/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/converter/MysqlTypeConverter.java b/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/converter/MysqlTypeConverter.javaindex 1a0f8a67b8..317263690d 100644--- a/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/converter/MysqlTypeConverter.java+++ b/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/converter/MysqlTypeConverter.java@@ -18,6 +18,7 @@*/package org.apache.gravitino.catalog.mysql.converter;+import java.util.Optional;import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.rel.types.Types;@@ -73,15 +74,21 @@ public class MysqlTypeConverter extends JdbcTypeConverter {case DATE:return Types.DateType.get();case TIME:- return Types.TimeType.get();+ return Optional.ofNullable(typeBean.getDatetimePrecision())+ .map(Types.TimeType::of)+ .orElseGet(Types.TimeType::get);// MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back// from UTC to the current time zone for retrieval. (This does not occur for other types// such as DATETIME.) see more details:// https://dev.mysql.com/doc/refman/8.0/en/datetime.htmlcase TIMESTAMP:- return Types.TimestampType.withTimeZone();+ return Optional.ofNullable(typeBean.getDatetimePrecision())+ .map(Types.TimestampType::withTimeZone)+ .orElseGet(Types.TimestampType::withTimeZone);case DATETIME:- return Types.TimestampType.withoutTimeZone();+ return Optional.ofNullable(typeBean.getDatetimePrecision())+ .map(Types.TimestampType::withoutTimeZone)+ .orElseGet(Types.TimestampType::withoutTimeZone);case DECIMAL_UNSIGNED:case DECIMAL:return Types.DecimalType.of(typeBean.getColumnSize(), typeBean.getScale());@@ -138,7 +145,11 @@ public class MysqlTypeConverter extends JdbcTypeConverter {// MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back// from UTC to the current time zone for retrieval. (This does not occur for other types// such as DATETIME.) see more details: https://dev.mysql.com/doc/refman/8.0/en/datetime.html- return ((Types.TimestampType) type).hasTimeZone() ? TIMESTAMP : DATETIME;+ Types.TimestampType timestampType = (Types.TimestampType) type;+ String baseType = timestampType.hasTimeZone() ? TIMESTAMP : DATETIME;+ return timestampType.hasPrecisionSet()+ ? String.format("%s(%d)", baseType, timestampType.precision())+ : baseType;} else if (type instanceof Types.DecimalType) {return type.simpleString();} else if (type instanceof Types.VarCharType) {diff --git a/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/operation/MysqlTableOperations.java b/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/operation/MysqlTableOperations.javaindex 0c3caf473c..8a5d356847 100644--- a/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/operation/MysqlTableOperations.java+++ b/catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/operation/MysqlTableOperations.java@@ -669,4 +669,43 @@ public class MysqlTableOperations extends JdbcTableOperations {}}}++ @Override+ public Integer calculateDatetimePrecision(String typeName, int columnSize, int scale) {+ String upperTypeName = typeName.toUpperCase();++ // Check driver version compatibility first+ boolean isDatetimeType =+ "TIME".equals(upperTypeName)+ || "TIMESTAMP".equals(upperTypeName)+ || "DATETIME".equals(upperTypeName);++ if (isDatetimeType) {+ String driverVersion = getMySQLDriverVersion();+ if (driverVersion != null && !isMySQLDriverVersionSupported(driverVersion)) {+ LOG.warn(+ "MySQL driver version {} is below 8.0.16, columnSize may not be accurate for precision calculation. "+ + "Returning null for {} type precision. Driver version: {}",+ driverVersion,+ upperTypeName,+ driverVersion);+ return null;+ }+ }++ switch (upperTypeName) {+ case "TIME":+ // TIME format: 'HH:MM:SS' (8 chars) + decimal point + precision+ return columnSize >= TIME_FORMAT_WITH_DOT.length()+ ? columnSize - TIME_FORMAT_WITH_DOT.length()+ : 0;+ case "TIMESTAMP":+ case "DATETIME":+ // TIMESTAMP/DATETIME format: 'YYYY-MM-DD HH:MM:SS' (19 chars) + decimal point + precision+ return columnSize >= DATETIME_FORMAT_WITH_DOT.length()+ ? columnSize - DATETIME_FORMAT_WITH_DOT.length()+ : 0;+ }+ return null;+ }}diff --git a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/converter/TestMysqlTypeConverter.java b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/converter/TestMysqlTypeConverter.javaindex e34c6dc5ea..85ccc85ed9 100644--- a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/converter/TestMysqlTypeConverter.java+++ b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/converter/TestMysqlTypeConverter.java@@ -48,23 +48,38 @@ public class TestMysqlTypeConverter {@Testpublic void testToGravitinoType() {- checkJdbcTypeToGravitinoType(Types.ByteType.get(), TINYINT, null, null);- checkJdbcTypeToGravitinoType(Types.IntegerType.get(), INT, null, null);- checkJdbcTypeToGravitinoType(Types.LongType.get(), BIGINT, null, null);- checkJdbcTypeToGravitinoType(Types.FloatType.get(), FLOAT, null, null);- checkJdbcTypeToGravitinoType(Types.DoubleType.get(), DOUBLE, null, null);- checkJdbcTypeToGravitinoType(Types.DateType.get(), DATE, null, null);- checkJdbcTypeToGravitinoType(Types.TimeType.get(), TIME, null, null);- checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(), DATETIME, null, null);- checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(), TIMESTAMP, null, null);- checkJdbcTypeToGravitinoType(Types.DecimalType.of(10, 2), DECIMAL, 10, 2);- checkJdbcTypeToGravitinoType(Types.DecimalType.of(10, 2), DECIMAL_UNSIGNED, 10, 2);- checkJdbcTypeToGravitinoType(Types.VarCharType.of(20), VARCHAR, 20, null);- checkJdbcTypeToGravitinoType(Types.FixedCharType.of(20), CHAR, 20, null);- checkJdbcTypeToGravitinoType(Types.StringType.get(), TEXT, null, null);- checkJdbcTypeToGravitinoType(Types.BinaryType.get(), BINARY, null, null);+ checkJdbcTypeToGravitinoType(Types.ByteType.get(), TINYINT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.IntegerType.get(), INT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.LongType.get(), BIGINT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.FloatType.get(), FLOAT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.DoubleType.get(), DOUBLE, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.DateType.get(), DATE, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimeType.get(), TIME, null, null, null);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(0), TIME, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(0), TIME, 8, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(3), TIME, 12, null, 3);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(6), TIME, 15, null, 6);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(9), TIME, 18, null, 9);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(), DATETIME, null, null, null);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(0), DATETIME, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(0), DATETIME, 19, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(3), DATETIME, 23, null, 3);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(6), DATETIME, 26, null, 6);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(9), DATETIME, 29, null, 9);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(), TIMESTAMP, null, null, null);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(0), TIMESTAMP, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(0), TIMESTAMP, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(3), TIMESTAMP, 23, null, 3);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(6), TIMESTAMP, 26, null, 6);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(9), TIMESTAMP, 29, null, 9);+ checkJdbcTypeToGravitinoType(Types.DecimalType.of(10, 2), DECIMAL, 10, 2, 0);+ checkJdbcTypeToGravitinoType(Types.DecimalType.of(10, 2), DECIMAL_UNSIGNED, 10, 2, 0);+ checkJdbcTypeToGravitinoType(Types.VarCharType.of(20), VARCHAR, 20, null, 0);+ checkJdbcTypeToGravitinoType(Types.FixedCharType.of(20), CHAR, 20, null, 0);+ checkJdbcTypeToGravitinoType(Types.StringType.get(), TEXT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.BinaryType.get(), BINARY, null, null, 0);checkJdbcTypeToGravitinoType(- Types.ExternalType.of(USER_DEFINED_TYPE), USER_DEFINED_TYPE, null, null);+ Types.ExternalType.of(USER_DEFINED_TYPE), USER_DEFINED_TYPE, null, null, 0);}@Test@@ -94,17 +109,23 @@ public class TestMysqlTypeConverter {}protected void checkJdbcTypeToGravitinoType(- Type gravitinoType, String jdbcTypeName, Integer columnSize, Integer scale) {- JdbcTypeConverter.JdbcTypeBean typeBean = createTypeBean(jdbcTypeName, columnSize, scale);+ Type gravitinoType,+ String jdbcTypeName,+ Integer columnSize,+ Integer scale,+ Integer datetimePrecision) {+ JdbcTypeConverter.JdbcTypeBean typeBean =+ createTypeBean(jdbcTypeName, columnSize, scale, datetimePrecision);Assertions.assertEquals(gravitinoType, MYSQL_TYPE_CONVERTER.toGravitino(typeBean));}protected static JdbcTypeConverter.JdbcTypeBean createTypeBean(- String typeName, Integer columnSize, Integer scale) {+ String typeName, Integer columnSize, Integer scale, Integer datetimePrecision) {return new JdbcTypeConverter.JdbcTypeBean(typeName) {{setColumnSize(columnSize);setScale(scale);+ setDatetimePrecision(datetimePrecision);}};}diff --git a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlDriverIT.java b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlDriverIT.javaindex 79c33399ca..2c7fd7ec95 100644--- a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlDriverIT.java+++ b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlDriverIT.java@@ -26,6 +26,6 @@ public class CatalogMysqlDriverIT extends CatalogMysqlIT {public CatalogMysqlDriverIT() {super();DOWNLOAD_MYSQL_JDBC_DRIVER_URL =- "https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.11/mysql-connector-java-8.0.11.jar";+ "https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.26/mysql-connector-java-8.0.26.jar";}}diff --git a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.javaindex 8b84806ba8..139c608038 100644--- a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java+++ b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java@@ -622,8 +622,7 @@ public class CatalogMysqlIT extends BaseIT {Literals.timestampLiteral("1983-09-05T00:00:00"), column.defaultValue());break;case "timestamp_col_3":- Assertions.assertEquals(- UnparsedExpression.of("CURRENT_TIMESTAMP(6)"), column.defaultValue());+ Assertions.assertEquals(DEFAULT_VALUE_OF_CURRENT_TIMESTAMP, column.defaultValue());break;case "decimal_6_2_col_1":Assertions.assertEquals(@@ -659,8 +658,20 @@ public class CatalogMysqlIT extends BaseIT {+ " double_col double,\n"+ " date_col date,\n"+ " time_col time,\n"+ + " time_col_0 time(0),\n"+ + " time_col_1 time(1),\n"+ + " time_col_3 time(3),\n"+ + " time_col_6 time(6),\n"+ " timestamp_col timestamp,\n"+ + " timestamp_col_0 timestamp(0) default current_timestamp,\n"+ + " timestamp_col_1 timestamp(1) default current_timestamp(1),\n"+ + " timestamp_col_3 timestamp(3) default '2012-12-31 11:30:45.123',\n"+ + " timestamp_col_6 timestamp(6) default '2012-12-31 11:30:45.123456',\n"+ " datetime_col datetime,\n"+ + " datetime_col_0 datetime(0),\n"+ + " datetime_col_1 datetime(1),\n"+ + " datetime_col_3 datetime(3),\n"+ + " datetime_col_6 datetime(6),\n"+ " decimal_6_2_col decimal(6, 2),\n"+ " varchar20_col varchar(20),\n"+ " text_col text,\n"@@ -698,13 +709,43 @@ public class CatalogMysqlIT extends BaseIT {Assertions.assertEquals(Types.DateType.get(), column.dataType());break;case "time_col":- Assertions.assertEquals(Types.TimeType.get(), column.dataType());+ case "time_col_0":+ Assertions.assertEquals(Types.TimeType.of(0), column.dataType());+ break;+ case "time_col_1":+ Assertions.assertEquals(Types.TimeType.of(1), column.dataType());+ break;+ case "time_col_3":+ Assertions.assertEquals(Types.TimeType.of(3), column.dataType());+ break;+ case "time_col_6":+ Assertions.assertEquals(Types.TimeType.of(6), column.dataType());break;case "timestamp_col":- Assertions.assertEquals(Types.TimestampType.withTimeZone(), column.dataType());+ case "timestamp_col_0":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(0), column.dataType());+ break;+ case "timestamp_col_1":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(1), column.dataType());+ break;+ case "timestamp_col_3":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(3), column.dataType());+ break;+ case "timestamp_col_6":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(6), column.dataType());break;case "datetime_col":- Assertions.assertEquals(Types.TimestampType.withoutTimeZone(), column.dataType());+ case "datetime_col_0":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(0), column.dataType());+ break;+ case "datetime_col_1":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(1), column.dataType());+ break;+ case "datetime_col_3":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(3), column.dataType());+ break;+ case "datetime_col_6":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(6), column.dataType());break;case "decimal_6_2_col":Assertions.assertEquals(Types.DecimalType.of(6, 2), column.dataType());@@ -865,7 +906,7 @@ public class CatalogMysqlIT extends BaseIT {TableChange.updateColumnDefaultValue(new String[] {columns[0].name()}, Literals.of("1.2345", Types.FloatType.get())),TableChange.updateColumnDefaultValue(- new String[] {columns[1].name()}, FunctionExpression.of("current_timestamp")),+ new String[] {columns[1].name()}, DEFAULT_VALUE_OF_CURRENT_TIMESTAMP),TableChange.updateColumnDefaultValue(new String[] {columns[2].name()}, Literals.of("hello", Types.VarCharType.of(255))),TableChange.updateColumnDefaultValue(@@ -2100,4 +2141,82 @@ public class CatalogMysqlIT extends BaseIT {loadCatalog.asSchemas().dropSchema("test", true);metalake.dropCatalog(testCatalogName, true);}++ @Test+ void testTimeTypePrecision() {+ // Test different time type precisions+ String tableName = GravitinoITUtils.genRandomName("test_time_precision");+ String fullTableName = schemaName + "." + tableName;+ String sql =+ "CREATE TABLE "+ + fullTableName+ + " (\n"+ + " time_no_precision time,\n"+ + " time_precision_0 time(0),\n"+ + " time_precision_1 time(1),\n"+ + " time_precision_3 time(3),\n"+ + " time_precision_6 time(6),\n"+ + " datetime_no_precision datetime,\n"+ + " datetime_precision_0 datetime(0),\n"+ + " datetime_precision_1 datetime(1),\n"+ + " datetime_precision_3 datetime(3),\n"+ + " datetime_precision_6 datetime(6),\n"+ + " timestamp_no_precision timestamp,\n"+ + " timestamp_precision_0 timestamp(0) default current_timestamp,\n"+ + " timestamp_precision_1 timestamp(1) default current_timestamp(1),\n"+ + " timestamp_precision_3 timestamp(3) default '2012-12-31 11:30:45.123',\n"+ + " timestamp_precision_6 timestamp(6) default '2012-12-31 11:30:45.123456'\n"+ + ");\n";++ mysqlService.executeQuery(sql);+ Table loadedTable =+ catalog.asTableCatalog().loadTable(NameIdentifier.of(schemaName, tableName));++ // Verify time type precisions+ for (Column column : loadedTable.columns()) {+ switch (column.name()) {+ case "time_no_precision":+ case "time_precision_0":+ Assertions.assertEquals(Types.TimeType.of(0), column.dataType());+ break;+ case "time_precision_1":+ Assertions.assertEquals(Types.TimeType.of(1), column.dataType());+ break;+ case "time_precision_3":+ Assertions.assertEquals(Types.TimeType.of(3), column.dataType());+ break;+ case "time_precision_6":+ Assertions.assertEquals(Types.TimeType.of(6), column.dataType());+ break;+ case "datetime_no_precision":+ case "datetime_precision_0":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(0), column.dataType());+ break;+ case "datetime_precision_1":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(1), column.dataType());+ break;+ case "datetime_precision_3":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(3), column.dataType());+ break;+ case "datetime_precision_6":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(6), column.dataType());+ break;+ case "timestamp_no_precision":+ case "timestamp_precision_0":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(0), column.dataType());+ break;+ case "timestamp_precision_1":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(1), column.dataType());+ break;+ case "timestamp_precision_3":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(3), column.dataType());+ break;+ case "timestamp_precision_6":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected column name: " + column.name());+ }+ }+ }}diff --git a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.javaindex e33533742b..b0ea5fb990 100644--- a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java+++ b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java@@ -478,7 +478,7 @@ public class TestMysqlTableOperations extends TestMysql {columns.add(JdbcColumn.builder().withName("col_3")- .withType(Types.TimestampType.withoutTimeZone())+ .withType(Types.TimestampType.withoutTimeZone(0))// MySQL 5.7 doesn't support nullable timestamp.withNullable(false).withComment("timestamp")@@ -563,7 +563,7 @@ public class TestMysqlTableOperations extends TestMysql {columns.add(JdbcColumn.builder().withName("col_3")- .withType(Types.TimestampType.withoutTimeZone())+ .withType(Types.TimestampType.withoutTimeZone(0))// MySQL 5.7 doesn't support nullable timestamp.withNullable(false).withComment("timestamp")@@ -645,13 +645,13 @@ public class TestMysqlTableOperations extends TestMysql {columns.add(JdbcColumn.builder().withName("col_8")- .withType(Types.TimeType.get())+ .withType(Types.TimeType.of(0)).withNullable(false).build());columns.add(JdbcColumn.builder().withName("col_9")- .withType(Types.TimestampType.withoutTimeZone())+ .withType(Types.TimestampType.withoutTimeZone(0)).withNullable(false).build());columns.add(@@ -1105,4 +1105,63 @@ public class TestMysqlTableOperations extends TestMysql {sql = MysqlTableOperations.deleteIndexDefinition(load, deleteIndex3);Assertions.assertEquals("DROP INDEX `uk_2`", sql);}++ @Test+ public void testCalculateDatetimePrecision() {+ Assertions.assertNull(+ TABLE_OPERATIONS.calculateDatetimePrecision("DATE", 10, 0),+ "DATE type should return 0 precision");++ Assertions.assertEquals(+ 1,+ TABLE_OPERATIONS.calculateDatetimePrecision("TIME", 10, 0),+ "TIME type should return 0 precision");++ Assertions.assertEquals(+ 3,+ TABLE_OPERATIONS.calculateDatetimePrecision("TIMESTAMP", 23, 0),+ "TIMESTAMP type should return 0 precision");++ Assertions.assertEquals(+ 6,+ TABLE_OPERATIONS.calculateDatetimePrecision("DATETIME", 26, 0),+ "TIMESTAMP type should return 0 precision");++ Assertions.assertEquals(+ 0,+ TABLE_OPERATIONS.calculateDatetimePrecision("timestamp", 19, 0),+ "Lower case type name should work");++ Assertions.assertNull(+ TABLE_OPERATIONS.calculateDatetimePrecision("VARCHAR", 50, 0),+ "Non-datetime type should return 0 precision");+ }++ @Test+ public void testCalculateDatetimePrecisionWithUnsupportedDriverVersion() {+ MysqlTableOperations operationsWithOldDriver =+ new MysqlTableOperations() {+ @Override+ public String getMySQLDriverVersion() {+ return "mysql-connector-java-8.0.11 (Revision: a0ca826f5cdf51a98356fdfb1bf251eb042f80bf)";+ }++ @Override+ public boolean isMySQLDriverVersionSupported(String driverVersion) {+ return false; // Simulate old driver+ }+ };++ Assertions.assertNull(+ operationsWithOldDriver.calculateDatetimePrecision("TIMESTAMP", 26, 0),+ "TIMESTAMP type should return null for unsupported driver version");++ Assertions.assertNull(+ operationsWithOldDriver.calculateDatetimePrecision("DATETIME", 26, 0),+ "DATETIME type should return null for unsupported driver version");++ Assertions.assertNull(+ operationsWithOldDriver.calculateDatetimePrecision("TIME", 16, 0),+ "TIME type should return null for unsupported driver version");+ }}diff --git a/catalogs/catalog-jdbc-oceanbase/src/main/java/org/apache/gravitino/catalog/oceanbase/converter/OceanBaseTypeConverter.java b/catalogs/catalog-jdbc-oceanbase/src/main/java/org/apache/gravitino/catalog/oceanbase/converter/OceanBaseTypeConverter.javaindex 8f4deb1e77..fe5a43fa4b 100644--- a/catalogs/catalog-jdbc-oceanbase/src/main/java/org/apache/gravitino/catalog/oceanbase/converter/OceanBaseTypeConverter.java+++ b/catalogs/catalog-jdbc-oceanbase/src/main/java/org/apache/gravitino/catalog/oceanbase/converter/OceanBaseTypeConverter.java@@ -18,6 +18,7 @@*/package org.apache.gravitino.catalog.oceanbase.converter;+import java.util.Optional;import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.rel.types.Types;@@ -68,11 +69,17 @@ public class OceanBaseTypeConverter extends JdbcTypeConverter {case DATE:return Types.DateType.get();case TIME:- return Types.TimeType.get();+ return Optional.ofNullable(typeBean.getDatetimePrecision())+ .map(Types.TimeType::of)+ .orElseGet(Types.TimeType::get);case TIMESTAMP:- return Types.TimestampType.withTimeZone();+ return Optional.ofNullable(typeBean.getDatetimePrecision())+ .map(Types.TimestampType::withTimeZone)+ .orElseGet(Types.TimestampType::withTimeZone);case DATETIME:- return Types.TimestampType.withoutTimeZone();+ return Optional.ofNullable(typeBean.getDatetimePrecision())+ .map(Types.TimestampType::withoutTimeZone)+ .orElseGet(Types.TimestampType::withoutTimeZone);case NUMBER:case NUMERIC:case DECIMAL:@@ -129,7 +136,11 @@ public class OceanBaseTypeConverter extends JdbcTypeConverter {} else if (type instanceof Types.TimeType) {return type.simpleString();} else if (type instanceof Types.TimestampType) {- return ((Types.TimestampType) type).hasTimeZone() ? TIMESTAMP : DATETIME;+ Types.TimestampType timestampType = (Types.TimestampType) type;+ String baseType = timestampType.hasTimeZone() ? TIMESTAMP : DATETIME;+ return timestampType.hasPrecisionSet()+ ? String.format("%s(%d)", baseType, timestampType.precision())+ : baseType;} else if (type instanceof Types.DecimalType) {return type.simpleString();} else if (type instanceof Types.VarCharType) {diff --git a/catalogs/catalog-jdbc-oceanbase/src/main/java/org/apache/gravitino/catalog/oceanbase/operation/OceanBaseTableOperations.java b/catalogs/catalog-jdbc-oceanbase/src/main/java/org/apache/gravitino/catalog/oceanbase/operation/OceanBaseTableOperations.javaindex 0428134b0e..f37c1cdfc1 100644--- a/catalogs/catalog-jdbc-oceanbase/src/main/java/org/apache/gravitino/catalog/oceanbase/operation/OceanBaseTableOperations.java+++ b/catalogs/catalog-jdbc-oceanbase/src/main/java/org/apache/gravitino/catalog/oceanbase/operation/OceanBaseTableOperations.java@@ -651,4 +651,43 @@ public class OceanBaseTableOperations extends JdbcTableOperations {}return sqlBuilder;}++ @Override+ public Integer calculateDatetimePrecision(String typeName, int columnSize, int scale) {+ String upperTypeName = typeName.toUpperCase();++ // Check driver version compatibility first+ boolean isDatetimeType =+ "TIME".equals(upperTypeName)+ || "TIMESTAMP".equals(upperTypeName)+ || "DATETIME".equals(upperTypeName);++ if (isDatetimeType) {+ String driverVersion = getMySQLDriverVersion();+ if (driverVersion != null && !isMySQLDriverVersionSupported(driverVersion)) {+ LOG.warn(+ "MySQL driver version {} is below 8.0.16, columnSize may not be accurate for precision calculation. "+ + "Returning null for {} type precision. Driver version: {}",+ driverVersion,+ upperTypeName,+ driverVersion);+ return null;+ }+ }++ switch (upperTypeName) {+ case "TIME":+ // TIME format: 'HH:MM:SS' (8 chars) + decimal point + precision+ return columnSize >= TIME_FORMAT_WITH_DOT.length()+ ? columnSize - TIME_FORMAT_WITH_DOT.length()+ : 0;+ case "TIMESTAMP":+ case "DATETIME":+ // TIMESTAMP/DATETIME format: 'YYYY-MM-DD HH:MM:SS' (19 chars) + decimal point + precision+ return columnSize >= DATETIME_FORMAT_WITH_DOT.length()+ ? columnSize - DATETIME_FORMAT_WITH_DOT.length()+ : 0;+ }+ return null;+ }}diff --git a/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/converter/TestOceanBaseTypeConverter.java b/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/converter/TestOceanBaseTypeConverter.javaindex a8bbb7e259..2026d9140a 100644--- a/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/converter/TestOceanBaseTypeConverter.java+++ b/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/converter/TestOceanBaseTypeConverter.java@@ -50,22 +50,31 @@ public class TestOceanBaseTypeConverter {@Testpublic void testToGravitinoType() {- checkJdbcTypeToGravitinoType(Types.ByteType.get(), TINYINT, null, null);- checkJdbcTypeToGravitinoType(Types.IntegerType.get(), INT, null, null);- checkJdbcTypeToGravitinoType(Types.LongType.get(), BIGINT, null, null);- checkJdbcTypeToGravitinoType(Types.FloatType.get(), FLOAT, null, null);- checkJdbcTypeToGravitinoType(Types.DoubleType.get(), DOUBLE, null, null);- checkJdbcTypeToGravitinoType(Types.DateType.get(), DATE, null, null);- checkJdbcTypeToGravitinoType(Types.TimeType.get(), TIME, null, null);- checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(), DATETIME, null, null);- checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(), TIMESTAMP, null, null);- checkJdbcTypeToGravitinoType(Types.DecimalType.of(10, 2), DECIMAL, 10, 2);- checkJdbcTypeToGravitinoType(Types.VarCharType.of(20), VARCHAR, 20, null);- checkJdbcTypeToGravitinoType(Types.FixedCharType.of(20), CHAR, 20, null);- checkJdbcTypeToGravitinoType(Types.StringType.get(), TEXT, null, null);- checkJdbcTypeToGravitinoType(Types.BinaryType.get(), BINARY, null, null);+ checkJdbcTypeToGravitinoType(Types.ByteType.get(), TINYINT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.IntegerType.get(), INT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.LongType.get(), BIGINT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.FloatType.get(), FLOAT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.DoubleType.get(), DOUBLE, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.DateType.get(), DATE, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(0), TIME, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(0), TIME, 8, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(3), TIME, 12, null, 3);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(6), TIME, 15, null, 6);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(0), DATETIME, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(0), DATETIME, 19, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(3), DATETIME, 23, null, 3);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(6), DATETIME, 26, null, 6);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(0), TIMESTAMP, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(0), TIMESTAMP, 19, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(3), TIMESTAMP, 23, null, 3);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withTimeZone(6), TIMESTAMP, 26, null, 6);+ checkJdbcTypeToGravitinoType(Types.DecimalType.of(10, 2), DECIMAL, 10, 2, 0);+ checkJdbcTypeToGravitinoType(Types.VarCharType.of(20), VARCHAR, 20, null, 0);+ checkJdbcTypeToGravitinoType(Types.FixedCharType.of(20), CHAR, 20, null, 0);+ checkJdbcTypeToGravitinoType(Types.StringType.get(), TEXT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.BinaryType.get(), BINARY, null, null, 0);checkJdbcTypeToGravitinoType(- Types.ExternalType.of(USER_DEFINED_TYPE), USER_DEFINED_TYPE, null, null);+ Types.ExternalType.of(USER_DEFINED_TYPE), USER_DEFINED_TYPE, null, null, 0);}@Test@@ -95,17 +104,23 @@ public class TestOceanBaseTypeConverter {}protected void checkJdbcTypeToGravitinoType(- Type gravitinoType, String jdbcTypeName, Integer columnSize, Integer scale) {- JdbcTypeConverter.JdbcTypeBean typeBean = createTypeBean(jdbcTypeName, columnSize, scale);+ Type gravitinoType,+ String jdbcTypeName,+ Integer columnSize,+ Integer scale,+ Integer datetimePrecision) {+ JdbcTypeConverter.JdbcTypeBean typeBean =+ createTypeBean(jdbcTypeName, columnSize, scale, datetimePrecision);Assertions.assertEquals(gravitinoType, OCEANBASE_TYPE_CONVERTER.toGravitino(typeBean));}protected static JdbcTypeConverter.JdbcTypeBean createTypeBean(- String typeName, Integer columnSize, Integer scale) {+ String typeName, Integer columnSize, Integer scale, Integer datetimePrecision) {return new JdbcTypeConverter.JdbcTypeBean(typeName) {{setColumnSize(columnSize);setScale(scale);+ setDatetimePrecision(datetimePrecision);}};}diff --git a/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java b/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.javaindex 4b5181c74f..c29a34452a 100644--- a/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java+++ b/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java@@ -33,6 +33,7 @@ import java.util.Map;import java.util.Objects;import java.util.Set;import java.util.stream.Collectors;+import org.apache.commons.lang3.ArrayUtils;import org.apache.commons.lang3.StringUtils;import org.apache.gravitino.Catalog;import org.apache.gravitino.NameIdentifier;@@ -640,13 +641,13 @@ public class CatalogOceanBaseIT extends BaseIT {Assertions.assertEquals(Types.DateType.get(), column.dataType());break;case "time_col":- Assertions.assertEquals(Types.TimeType.get(), column.dataType());+ Assertions.assertEquals(Types.TimeType.of(0), column.dataType());break;case "timestamp_col":- Assertions.assertEquals(Types.TimestampType.withTimeZone(), column.dataType());+ Assertions.assertEquals(Types.TimestampType.withTimeZone(0), column.dataType());break;case "datetime_col":- Assertions.assertEquals(Types.TimestampType.withoutTimeZone(), column.dataType());+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(0), column.dataType());break;case "decimal_6_2_col":Assertions.assertEquals(Types.DecimalType.of(6, 2), column.dataType());@@ -1863,4 +1864,126 @@ public class CatalogOceanBaseIT extends BaseIT {Assertions.assertEquals(columns[6].dataType().simpleString(), "long");Assertions.assertEquals(columns[7].dataType().simpleString(), "long unsigned");}++ @Test+ void testTimeTypePrecision() {+ String tableName = GravitinoITUtils.genRandomName("test_time_precision");+ NameIdentifier tableIdentifier = NameIdentifier.of(schemaName, tableName);+ Column[] columns = createColumns();+ columns =+ ArrayUtils.addAll(+ columns,+ // time type+ Column.of("time_col", Types.TimeType.get()),+ Column.of("time_col_0", Types.TimeType.of(0)),+ Column.of("time_col_1", Types.TimeType.of(1)),+ Column.of("time_col_3", Types.TimeType.of(3)),+ Column.of("time_col_6", Types.TimeType.of(6)),+ // timestamp type+ Column.of("timestamp_col", Types.TimestampType.withTimeZone()),+ Column.of("timestamp_col_0", Types.TimestampType.withTimeZone(0)),+ Column.of("timestamp_col_1", Types.TimestampType.withTimeZone(1)),+ Column.of("timestamp_col_3", Types.TimestampType.withTimeZone(3)),+ Column.of("timestamp_col_6", Types.TimestampType.withTimeZone(6)),+ // datetime type (without time zone)+ Column.of("datetime_col", Types.TimestampType.withoutTimeZone()),+ Column.of("datetime_col_0", Types.TimestampType.withoutTimeZone(0)),+ Column.of("datetime_col_1", Types.TimestampType.withoutTimeZone(1)),+ Column.of("datetime_col_3", Types.TimestampType.withoutTimeZone(3)),+ Column.of("datetime_col_6", Types.TimestampType.withoutTimeZone(6)));++ Map<String, String> properties = createProperties();+ TableCatalog tableCatalog = catalog.asTableCatalog();+ tableCatalog.createTable(+ tableIdentifier,+ columns,+ table_comment,+ properties,+ Transforms.EMPTY_TRANSFORM,+ Distributions.NONE,+ new SortOrder[0]);++ Table loadTable = tableCatalog.loadTable(tableIdentifier);++ // Verify time type precisions+ Column[] timeColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("time_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(5, timeColumns.length);+ for (Column column : timeColumns) {+ switch (column.name()) {+ case "time_col":+ case "time_col_0":+ Assertions.assertEquals(Types.TimeType.of(0), column.dataType());+ break;+ case "time_col_1":+ Assertions.assertEquals(Types.TimeType.of(1), column.dataType());+ break;+ case "time_col_3":+ Assertions.assertEquals(Types.TimeType.of(3), column.dataType());+ break;+ case "time_col_6":+ Assertions.assertEquals(Types.TimeType.of(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected time column: " + column.name());+ }+ }++ // Verify timestamp type precisions+ Column[] timestampColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("timestamp_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(5, timestampColumns.length);+ for (Column column : timestampColumns) {+ switch (column.name()) {+ case "timestamp_col":+ case "timestamp_col_0":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(0), column.dataType());+ break;+ case "timestamp_col_1":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(1), column.dataType());+ break;+ case "timestamp_col_3":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(3), column.dataType());+ break;+ case "timestamp_col_6":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected timestamp column: " + column.name());+ }+ }++ // Verify datetime type precisions+ Column[] datetimeColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("datetime_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(5, datetimeColumns.length);+ for (Column column : datetimeColumns) {+ switch (column.name()) {+ case "datetime_col":+ case "datetime_col_0":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(0), column.dataType());+ break;+ case "datetime_col_1":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(1), column.dataType());+ break;+ case "datetime_col_3":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(3), column.dataType());+ break;+ case "datetime_col_6":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected datetime column: " + column.name());+ }+ }+ }}diff --git a/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/operation/TestOceanBaseTableOperations.java b/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/operation/TestOceanBaseTableOperations.javaindex c8d4fb2382..0427aea095 100644--- a/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/operation/TestOceanBaseTableOperations.java+++ b/catalogs/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/operation/TestOceanBaseTableOperations.java@@ -461,7 +461,7 @@ public class TestOceanBaseTableOperations extends TestOceanBase {columns.add(JdbcColumn.builder().withName("col_3")- .withType(Types.TimestampType.withoutTimeZone())+ .withType(Types.TimestampType.withoutTimeZone(0)).withNullable(false).withComment("timestamp").withDefaultValue(Literals.timestampLiteral(LocalDateTime.parse("2013-01-01T00:00:00")))@@ -545,7 +545,7 @@ public class TestOceanBaseTableOperations extends TestOceanBase {columns.add(JdbcColumn.builder().withName("col_3")- .withType(Types.TimestampType.withoutTimeZone())+ .withType(Types.TimestampType.withoutTimeZone(0)).withNullable(false).withComment("timestamp").withDefaultValue(Literals.timestampLiteral(LocalDateTime.parse("2013-01-01T00:00:00")))@@ -626,13 +626,13 @@ public class TestOceanBaseTableOperations extends TestOceanBase {columns.add(JdbcColumn.builder().withName("col_8")- .withType(Types.TimeType.get())+ .withType(Types.TimeType.of(0)).withNullable(false).build());columns.add(JdbcColumn.builder().withName("col_9")- .withType(Types.TimestampType.withoutTimeZone())+ .withType(Types.TimestampType.withoutTimeZone(0)).withNullable(false).build());columns.add(@@ -1043,4 +1043,94 @@ public class TestOceanBaseTableOperations extends TestOceanBase {sql = OceanBaseTableOperations.deleteIndexDefinition(load, deleteIndex3);Assertions.assertEquals("DROP INDEX `uk_2`", sql);}++ @Test+ public void testCalculateDatetimePrecision() {+ Assertions.assertNull(+ TABLE_OPERATIONS.calculateDatetimePrecision("DATE", 10, 0),+ "DATE type should return 0 precision");++ Assertions.assertEquals(+ 1,+ TABLE_OPERATIONS.calculateDatetimePrecision("TIME", 10, 0),+ "TIME type should return 0 precision");++ Assertions.assertEquals(+ 3,+ TABLE_OPERATIONS.calculateDatetimePrecision("TIMESTAMP", 23, 0),+ "TIMESTAMP type should return 0 precision");++ Assertions.assertEquals(+ 6,+ TABLE_OPERATIONS.calculateDatetimePrecision("DATETIME", 26, 0),+ "TIMESTAMP type should return 0 precision");++ Assertions.assertEquals(+ 9,+ TABLE_OPERATIONS.calculateDatetimePrecision("timestamp", 29, 0),+ "Lower case type name should work");++ Assertions.assertNull(+ TABLE_OPERATIONS.calculateDatetimePrecision("VARCHAR", 50, 0),+ "Non-datetime type should return 0 precision");+ }++ @Test+ public void testCalculateDatetimePrecisionWithUnsupportedDriverVersion() {+ OceanBaseTableOperations operationsWithOldDriver =+ new OceanBaseTableOperations() {+ @Override+ protected String getMySQLDriverVersion() {+ return "mysql-connector-java-8.0.11 (Revision: a0ca826f5cdf51a98356fdfb1bf251eb042f80bf)";+ }++ @Override+ public boolean isMySQLDriverVersionSupported(String driverVersion) {+ return false;+ }+ };++ Assertions.assertNull(+ operationsWithOldDriver.calculateDatetimePrecision("TIMESTAMP", 26, 0),+ "TIMESTAMP type should return null for unsupported driver version");++ Assertions.assertNull(+ operationsWithOldDriver.calculateDatetimePrecision("DATETIME", 26, 0),+ "DATETIME type should return null for unsupported driver version");++ Assertions.assertNull(+ operationsWithOldDriver.calculateDatetimePrecision("TIME", 16, 0),+ "TIME type should return null for unsupported driver version");+ }++ @Test+ public void testCalculateDatetimePrecisionWithOceanBaseDriver() {+ OceanBaseTableOperations operationsWithOceanBaseDriver =+ new OceanBaseTableOperations() {+ @Override+ protected String getMySQLDriverVersion() {+ return "com.oceanbase.jdbc.Driver-1.0.0";+ }++ @Override+ public boolean isMySQLDriverVersionSupported(String driverVersion) {+ return true;+ }+ };++ Assertions.assertEquals(+ 3,+ operationsWithOceanBaseDriver.calculateDatetimePrecision("TIMESTAMP", 23, 0),+ "TIMESTAMP type should return precision for OceanBase driver");++ Assertions.assertEquals(+ 6,+ operationsWithOceanBaseDriver.calculateDatetimePrecision("DATETIME", 26, 0),+ "DATETIME type should return precision for OceanBase driver");++ Assertions.assertEquals(+ 1,+ operationsWithOceanBaseDriver.calculateDatetimePrecision("TIME", 10, 0),+ "TIME type should return precision for OceanBase driver");+ }}diff --git a/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/converter/PostgreSqlTypeConverter.java b/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/converter/PostgreSqlTypeConverter.javaindex 39bc89e629..3d5f788b9e 100644--- a/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/converter/PostgreSqlTypeConverter.java+++ b/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/converter/PostgreSqlTypeConverter.java@@ -20,6 +20,7 @@ package org.apache.gravitino.catalog.postgresql.converter;import com.google.common.annotations.VisibleForTesting;import com.google.common.base.Preconditions;+import java.util.Optional;import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;import org.apache.gravitino.rel.types.Type;import org.apache.gravitino.rel.types.Types;@@ -63,11 +64,17 @@ public class PostgreSqlTypeConverter extends JdbcTypeConverter {case DATE:return Types.DateType.get();case TIME:- return Types.TimeType.get();+ return Optional.ofNullable(typeBean.getDatetimePrecision())+ .map(Types.TimeType::of)+ .orElseGet(Types.TimeType::get);case TIMESTAMP:- return Types.TimestampType.withoutTimeZone();+ return Optional.ofNullable(typeBean.getDatetimePrecision())+ .map(Types.TimestampType::withoutTimeZone)+ .orElseGet(Types.TimestampType::withoutTimeZone);case TIMESTAMP_TZ:- return Types.TimestampType.withTimeZone();+ return Optional.ofNullable(typeBean.getDatetimePrecision())+ .map(Types.TimestampType::withTimeZone)+ .orElseGet(Types.TimestampType::withTimeZone);case NUMERIC:return Types.DecimalType.of(typeBean.getColumnSize(), typeBean.getScale());case VARCHAR:@@ -103,10 +110,12 @@ public class PostgreSqlTypeConverter extends JdbcTypeConverter {return type.simpleString();} else if (type instanceof Types.TimeType) {return type.simpleString();- } else if (type instanceof Types.TimestampType && !((Types.TimestampType) type).hasTimeZone()) {- return TIMESTAMP;- } else if (type instanceof Types.TimestampType && ((Types.TimestampType) type).hasTimeZone()) {- return TIMESTAMP_TZ;+ } else if (type instanceof Types.TimestampType) {+ Types.TimestampType timestampType = (Types.TimestampType) type;+ String baseType = timestampType.hasTimeZone() ? TIMESTAMP_TZ : TIMESTAMP;+ return timestampType.hasPrecisionSet()+ ? String.format("%s(%d)", baseType, timestampType.precision())+ : baseType;} else if (type instanceof Types.DecimalType) {return NUMERIC+ "("diff --git a/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java b/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.javaindex 13a0ff3be0..c2cae935f1 100644--- a/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java+++ b/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java@@ -736,4 +736,18 @@ public class PostgreSqlTableOperations extends JdbcTableOperations {DatabaseMetaData metaData = connection.getMetaData();return metaData.getColumns(database, schema, tableName, null);}++ @Override+ public Integer calculateDatetimePrecision(String typeName, int columnSize, int scale) {+ String upperTypeName = typeName.toUpperCase();+ switch (upperTypeName) {+ case "TIME":+ case "TIMETZ":+ case "TIMESTAMP":+ case "TIMESTAMPTZ":+ return Math.max(scale, 0);+ default:+ return null;+ }+ }}diff --git a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/converter/TestPostgreSqlTypeConverter.java b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/converter/TestPostgreSqlTypeConverter.javaindex 718b61fe3b..d976336fb1 100644--- a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/converter/TestPostgreSqlTypeConverter.java+++ b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/converter/TestPostgreSqlTypeConverter.java@@ -52,22 +52,28 @@ public class TestPostgreSqlTypeConverter {@Testpublic void testToGravitinoType() {- checkJdbcTypeToGravitinoType(Types.BooleanType.get(), BOOL, null, null);- checkJdbcTypeToGravitinoType(Types.ShortType.get(), INT_2, null, null);- checkJdbcTypeToGravitinoType(Types.IntegerType.get(), INT_4, null, null);- checkJdbcTypeToGravitinoType(Types.LongType.get(), INT_8, null, null);- checkJdbcTypeToGravitinoType(Types.FloatType.get(), FLOAT_4, null, null);- checkJdbcTypeToGravitinoType(Types.DoubleType.get(), FLOAT_8, null, null);- checkJdbcTypeToGravitinoType(Types.DateType.get(), DATE, null, null);- checkJdbcTypeToGravitinoType(Types.TimeType.get(), TIME, null, null);- checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(), TIMESTAMP, null, null);- checkJdbcTypeToGravitinoType(Types.DecimalType.of(10, 2), NUMERIC, 10, 2);- checkJdbcTypeToGravitinoType(Types.VarCharType.of(20), VARCHAR, 20, null);- checkJdbcTypeToGravitinoType(Types.FixedCharType.of(20), BPCHAR, 20, null);- checkJdbcTypeToGravitinoType(Types.StringType.get(), TEXT, null, null);- checkJdbcTypeToGravitinoType(Types.BinaryType.get(), BYTEA, null, null);+ checkJdbcTypeToGravitinoType(Types.BooleanType.get(), BOOL, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.ShortType.get(), INT_2, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.IntegerType.get(), INT_4, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.LongType.get(), INT_8, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.FloatType.get(), FLOAT_4, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.DoubleType.get(), FLOAT_8, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.DateType.get(), DATE, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(0), TIME, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(0), TIME, 8, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(3), TIME, 12, null, 3);+ checkJdbcTypeToGravitinoType(Types.TimeType.of(6), TIME, 15, null, 6);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(0), TIMESTAMP, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(0), TIMESTAMP, 19, null, 0);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(3), TIMESTAMP, 23, null, 3);+ checkJdbcTypeToGravitinoType(Types.TimestampType.withoutTimeZone(6), TIMESTAMP, 26, null, 6);+ checkJdbcTypeToGravitinoType(Types.DecimalType.of(10, 2), NUMERIC, 10, 2, 0);+ checkJdbcTypeToGravitinoType(Types.VarCharType.of(20), VARCHAR, 20, null, 0);+ checkJdbcTypeToGravitinoType(Types.FixedCharType.of(20), BPCHAR, 20, null, 0);+ checkJdbcTypeToGravitinoType(Types.StringType.get(), TEXT, null, null, 0);+ checkJdbcTypeToGravitinoType(Types.BinaryType.get(), BYTEA, null, null, 0);checkJdbcTypeToGravitinoType(- Types.ExternalType.of(USER_DEFINED_TYPE), USER_DEFINED_TYPE, null, null);+ Types.ExternalType.of(USER_DEFINED_TYPE), USER_DEFINED_TYPE, null, null, 0);}@Test@@ -76,7 +82,7 @@ public class TestPostgreSqlTypeConverter {Type list1 = Types.ListType.of(elmentType, false);checkGravitinoTypeToJdbcType(INT_4 + ARRAY_TOKEN, list1);- checkJdbcTypeToGravitinoType(list1, JDBC_ARRAY_PREFIX + INT_4, null, null);+ checkJdbcTypeToGravitinoType(list1, JDBC_ARRAY_PREFIX + INT_4, null, null, 0);// not support element nullableAssertions.assertThrowsExactly(@@ -118,17 +124,23 @@ public class TestPostgreSqlTypeConverter {}protected void checkJdbcTypeToGravitinoType(- Type gravitinoType, String jdbcTypeName, Integer columnSize, Integer scale) {- JdbcTypeConverter.JdbcTypeBean typeBean = createTypeBean(jdbcTypeName, columnSize, scale);+ Type gravitinoType,+ String jdbcTypeName,+ Integer columnSize,+ Integer scale,+ Integer datetimePrecision) {+ JdbcTypeConverter.JdbcTypeBean typeBean =+ createTypeBean(jdbcTypeName, columnSize, scale, datetimePrecision);Assertions.assertEquals(gravitinoType, POSTGRE_SQL_TYPE_CONVERTER.toGravitino(typeBean));}protected static JdbcTypeConverter.JdbcTypeBean createTypeBean(- String typeName, Integer columnSize, Integer scale) {+ String typeName, Integer columnSize, Integer scale, Integer datetimePrecision) {return new JdbcTypeConverter.JdbcTypeBean(typeName) {{setColumnSize(columnSize);setScale(scale);+ setDatetimePrecision(datetimePrecision);}};}diff --git a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.javaindex 091c28f15b..a33d0ab0da 100644--- a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java+++ b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java@@ -34,6 +34,7 @@ import java.util.Objects;import java.util.Optional;import java.util.Set;import java.util.stream.Collectors;+import org.apache.commons.lang3.ArrayUtils;import org.apache.commons.lang3.StringUtils;import org.apache.gravitino.Catalog;import org.apache.gravitino.NameIdentifier;@@ -1793,4 +1794,126 @@ public class CatalogPostgreSqlIT extends BaseIT {Exception.class,() -> DriverManager.getDriver("jdbc:postgresql://dummy_address:dummy_port/"));}++ @Test+ void testTimeTypePrecision() {+ String tableName = GravitinoITUtils.genRandomName("test_time_precision");+ NameIdentifier tableIdentifier = NameIdentifier.of(schemaName, tableName);+ Column[] columns = createColumns();+ columns =+ ArrayUtils.addAll(+ columns,+ // timestamp without time zone+ Column.of("timestamp_col", Types.TimestampType.withoutTimeZone()),+ Column.of("timestamp_col_0", Types.TimestampType.withoutTimeZone(0)),+ Column.of("timestamp_col_1", Types.TimestampType.withoutTimeZone(1)),+ Column.of("timestamp_col_3", Types.TimestampType.withoutTimeZone(3)),+ Column.of("timestamp_col_6", Types.TimestampType.withoutTimeZone(6)),+ // timestamp with time zone+ Column.of("timestamptz_col", Types.TimestampType.withTimeZone()),+ Column.of("timestamptz_col_0", Types.TimestampType.withTimeZone(0)),+ Column.of("timestamptz_col_1", Types.TimestampType.withTimeZone(1)),+ Column.of("timestamptz_col_3", Types.TimestampType.withTimeZone(3)),+ Column.of("timestamptz_col_6", Types.TimestampType.withTimeZone(6)),+ // time without time zone+ Column.of("time_col", Types.TimeType.get()),+ Column.of("time_col_0", Types.TimeType.of(0)),+ Column.of("time_col_1", Types.TimeType.of(1)),+ Column.of("time_col_3", Types.TimeType.of(3)),+ Column.of("time_col_6", Types.TimeType.of(6)));++ Map<String, String> properties = createProperties();+ TableCatalog tableCatalog = catalog.asTableCatalog();+ tableCatalog.createTable(+ tableIdentifier,+ columns,+ table_comment,+ properties,+ Transforms.EMPTY_TRANSFORM,+ Distributions.NONE,+ null);++ Table loadTable = tableCatalog.loadTable(tableIdentifier);++ // Verify timestamp type precisions+ Column[] timestampColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("timestamp_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(5, timestampColumns.length);+ for (Column column : timestampColumns) {+ switch (column.name()) {+ case "timestamp_col":+ case "timestamp_col_6":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(6), column.dataType());+ break;+ case "timestamp_col_0":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(0), column.dataType());+ break;+ case "timestamp_col_1":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(1), column.dataType());+ break;+ case "timestamp_col_3":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(3), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected timestamp column: " + column.name());+ }+ }++ // Verify timestamptz type precisions+ Column[] timestamptzColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("timestamptz_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(5, timestamptzColumns.length);+ for (Column column : timestamptzColumns) {+ switch (column.name()) {+ case "timestamptz_col":+ case "timestamptz_col_6":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(6), column.dataType());+ break;+ case "timestamptz_col_0":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(0), column.dataType());+ break;+ case "timestamptz_col_1":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(1), column.dataType());+ break;+ case "timestamptz_col_3":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(3), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected timestamptz column: " + column.name());+ }+ }++ // Verify time type precisions+ Column[] timeColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("time_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(5, timeColumns.length);+ for (Column column : timeColumns) {+ switch (column.name()) {+ case "time_col":+ case "time_col_6":+ Assertions.assertEquals(Types.TimeType.of(6), column.dataType());+ break;+ case "time_col_0":+ Assertions.assertEquals(Types.TimeType.of(0), column.dataType());+ break;+ case "time_col_1":+ Assertions.assertEquals(Types.TimeType.of(1), column.dataType());+ break;+ case "time_col_3":+ Assertions.assertEquals(Types.TimeType.of(3), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected time column: " + column.name());+ }+ }+ }}diff --git a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/operation/TestPostgreSqlTableOperations.java b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/operation/TestPostgreSqlTableOperations.javaindex 3ac8c37756..723c473d86 100644--- a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/operation/TestPostgreSqlTableOperations.java+++ b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/operation/TestPostgreSqlTableOperations.java@@ -312,19 +312,19 @@ public class TestPostgreSqlTableOperations extends TestPostgreSql {columns.add(JdbcColumn.builder().withName("col_8")- .withType(Types.TimeType.get())+ .withType(Types.TimeType.of(6)).withNullable(false).build());columns.add(JdbcColumn.builder().withName("col_9")- .withType(Types.TimestampType.withoutTimeZone())+ .withType(Types.TimestampType.withoutTimeZone(6)).withNullable(false).build());columns.add(JdbcColumn.builder().withName("col_10")- .withType(Types.TimestampType.withTimeZone())+ .withType(Types.TimestampType.withTimeZone(6)).withNullable(false).build());columns.add(@@ -752,4 +752,35 @@ public class TestPostgreSqlTableOperations extends TestPostgreSql {Assertions.assertEquals("ALTER TABLE \"table_test\" ALTER COLUMN \"col_2\" DROP IDENTITY;", sql);}++ @Test+ public void testCalculateDatetimePrecision() {+ Assertions.assertNull(+ TABLE_OPERATIONS.calculateDatetimePrecision("DATE", 10, -1),+ "DATE type should return 0 precision");++ Assertions.assertEquals(+ 0,+ TABLE_OPERATIONS.calculateDatetimePrecision("TIME", 10, 0),+ "TIME type should return 0 precision");++ Assertions.assertEquals(+ 3,+ TABLE_OPERATIONS.calculateDatetimePrecision("TIMETZ", 23, 3),+ "TIMESTAMP type should return 0 precision");++ Assertions.assertEquals(+ 6,+ TABLE_OPERATIONS.calculateDatetimePrecision("TIMESTAMP", 26, 6),+ "TIMESTAMP type should return 0 precision");++ Assertions.assertEquals(+ 1,+ TABLE_OPERATIONS.calculateDatetimePrecision("TIMESTAMPTZ", 19, 1),+ "Lower case type name should work");++ Assertions.assertNull(+ TABLE_OPERATIONS.calculateDatetimePrecision("VARCHAR", 50, 0),+ "Non-datetime type should return 0 precision");+ }}diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/converter/FromIcebergType.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/converter/FromIcebergType.javaindex 56c164970c..e47bf34670 100644--- a/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/converter/FromIcebergType.java+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/converter/FromIcebergType.java@@ -32,6 +32,8 @@ import org.apache.iceberg.types.Types;*/public class FromIcebergType extends TypeUtil.SchemaVisitor<Type> {+ public static final int PRECISION_MICROSECOND = 6;+public FromIcebergType() {}@Override@@ -90,13 +92,15 @@ public class FromIcebergType extends TypeUtil.SchemaVisitor<Type> {case DATE:return org.apache.gravitino.rel.types.Types.DateType.get();case TIME:- return org.apache.gravitino.rel.types.Types.TimeType.get();+ return org.apache.gravitino.rel.types.Types.TimeType.of(PRECISION_MICROSECOND);case TIMESTAMP:Types.TimestampType ts = (Types.TimestampType) primitive;if (ts.shouldAdjustToUTC()) {- return org.apache.gravitino.rel.types.Types.TimestampType.withTimeZone();+ return org.apache.gravitino.rel.types.Types.TimestampType.withTimeZone(+ PRECISION_MICROSECOND);} else {- return org.apache.gravitino.rel.types.Types.TimestampType.withoutTimeZone();+ return org.apache.gravitino.rel.types.Types.TimestampType.withoutTimeZone(+ PRECISION_MICROSECOND);}case STRING:return org.apache.gravitino.rel.types.Types.StringType.get();diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/converter/ToIcebergType.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/converter/ToIcebergType.javaindex f985270b13..58b88c626d 100644--- a/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/converter/ToIcebergType.java+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/converter/ToIcebergType.java@@ -120,12 +120,36 @@ public class ToIcebergType extends ToIcebergTypeVisitor<Type> {} else if (primitive instanceof org.apache.gravitino.rel.types.Types.DateType) {return Types.DateType.get();} else if (primitive instanceof org.apache.gravitino.rel.types.Types.TimeType) {- return Types.TimeType.get();+ org.apache.gravitino.rel.types.Types.TimeType timeType =+ (org.apache.gravitino.rel.types.Types.TimeType) primitive;+ // Iceberg only supports microsecond precision (6) for time type up to version 1.9.x+ // See: https://iceberg.apache.org/docs/1.9.1/schemas/+ if (!timeType.hasPrecisionSet() || timeType.precision() == 6) {+ return Types.TimeType.get();+ } else {+ throw new IllegalArgumentException(+ "Iceberg only supports microsecond precision (6) for time type, but got precision: "+ + timeType.precision());+ }} else if (primitive instanceof org.apache.gravitino.rel.types.Types.TimestampType) {- if (((org.apache.gravitino.rel.types.Types.TimestampType) primitive).hasTimeZone()) {- return Types.TimestampType.withZone();+ org.apache.gravitino.rel.types.Types.TimestampType timestampType =+ (org.apache.gravitino.rel.types.Types.TimestampType) primitive;+ // Iceberg only supports microsecond precision (6) for timestamp/timestamptz types up to+ // version 1.9.x+ // See: https://iceberg.apache.org/docs/1.9.1/schemas/+ if (!timestampType.hasPrecisionSet() || timestampType.precision() == 6) {+ if (timestampType.hasTimeZone()) {+ return Types.TimestampType.withZone();+ } else {+ return Types.TimestampType.withoutZone();+ }} else {- return Types.TimestampType.withoutZone();+ String timestampTypeName = timestampType.hasTimeZone() ? "timestamptz" : "timestamp";+ throw new IllegalArgumentException(+ "Iceberg only supports microsecond precision (6) for "+ + timestampTypeName+ + " type, but got precision: "+ + timestampType.precision());}} else if (primitive instanceof org.apache.gravitino.rel.types.Types.DecimalType) {return Types.DecimalType.of(diff --git a/catalogs/catalog-lakehouse-iceberg/src/test/java/org/apache/gravitino/catalog/lakehouse/iceberg/integration/test/CatalogIcebergBaseIT.java b/catalogs/catalog-lakehouse-iceberg/src/test/java/org/apache/gravitino/catalog/lakehouse/iceberg/integration/test/CatalogIcebergBaseIT.javaindex 560c9272cc..269d2f32ac 100644--- a/catalogs/catalog-lakehouse-iceberg/src/test/java/org/apache/gravitino/catalog/lakehouse/iceberg/integration/test/CatalogIcebergBaseIT.java+++ b/catalogs/catalog-lakehouse-iceberg/src/test/java/org/apache/gravitino/catalog/lakehouse/iceberg/integration/test/CatalogIcebergBaseIT.java@@ -39,6 +39,7 @@ import java.util.Locale;import java.util.Map;import java.util.Set;import java.util.stream.Collectors;+import org.apache.commons.lang3.ArrayUtils;import org.apache.commons.lang3.StringUtils;import org.apache.gravitino.Catalog;import org.apache.gravitino.NameIdentifier;@@ -578,12 +579,12 @@ public abstract class CatalogIcebergBaseIT extends BaseIT {Table loadTable = tableCatalog.loadTable(tableIdentifier);Assertions.assertEquals("iceberg_column_1", loadTable.columns()[0].name());- Assertions.assertEquals(Types.TimestampType.withTimeZone(), loadTable.columns()[0].dataType());+ Assertions.assertEquals(Types.TimestampType.withTimeZone(6), loadTable.columns()[0].dataType());Assertions.assertEquals("col_1_comment", loadTable.columns()[0].comment());Assertions.assertEquals("iceberg_column_2", loadTable.columns()[1].name());Assertions.assertEquals(- Types.TimestampType.withoutTimeZone(), loadTable.columns()[1].dataType());+ Types.TimestampType.withoutTimeZone(6), loadTable.columns()[1].dataType());Assertions.assertEquals("col_2_comment", loadTable.columns()[1].comment());org.apache.iceberg.Table table =@@ -1303,6 +1304,232 @@ public abstract class CatalogIcebergBaseIT extends BaseIT {Assertions.assertDoesNotThrow(() -> tableCatalog.dropTable(tableIdentifier));}+ @Test+ void testTimeTypePrecision() {+ String tableName = GravitinoITUtils.genRandomName("test_time_precision");+ NameIdentifier tableIdentifier = NameIdentifier.of(schemaName, tableName);+ Column[] columns = createColumns();+ columns =+ ArrayUtils.addAll(+ columns,+ // time type - only support precision 6 (microsecond) or no precision+ Column.of("time_col", Types.TimeType.get()),+ Column.of("time_col_6", Types.TimeType.of(6)),+ // timestamptz type (with timezone) - only support precision 6 (microsecond) or no+ // precision+ Column.of("timestamptz_col", Types.TimestampType.withTimeZone()),+ Column.of("timestamptz_col_6", Types.TimestampType.withTimeZone(6)),+ // timestamp type (without timezone) - only support precision 6 (microsecond) or no+ // precision+ Column.of("timestamp_col", Types.TimestampType.withoutTimeZone()),+ Column.of("timestamp_col_6", Types.TimestampType.withoutTimeZone(6)));++ Map<String, String> properties = createProperties();+ TableCatalog tableCatalog = catalog.asTableCatalog();+ tableCatalog.createTable(+ tableIdentifier,+ columns,+ table_comment,+ properties,+ Transforms.EMPTY_TRANSFORM,+ Distributions.NONE,+ new SortOrder[0]);++ Table loadTable = tableCatalog.loadTable(tableIdentifier);++ // Verify time type precisions+ Column[] timeColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("time_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(2, timeColumns.length);+ for (Column column : timeColumns) {+ switch (column.name()) {+ case "time_col":+ case "time_col_6":+ Assertions.assertEquals(Types.TimeType.of(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected time column: " + column.name());+ }+ }++ // Verify timestamptz type precisions (with timezone)+ Column[] timestamptzColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("timestamptz_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(2, timestamptzColumns.length);+ for (Column column : timestamptzColumns) {+ switch (column.name()) {+ case "timestamptz_col":+ case "timestamptz_col_6":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected timestamptz column: " + column.name());+ }+ }++ // Verify timestamp type precisions (without timezone)+ Column[] timestampColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("timestamp_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(2, timestampColumns.length);+ for (Column column : timestampColumns) {+ switch (column.name()) {+ case "timestamp_col":+ case "timestamp_col_6":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected timestamp column: " + column.name());+ }+ }++ // Verify Iceberg schema type conversion+ org.apache.iceberg.Table icebergTable =+ icebergCatalog.loadTable(+ TableIdentifier.of(+ IcebergCatalogWrapperHelper.getIcebergNamespace(schemaName), tableName));+ org.apache.iceberg.Schema schema = icebergTable.schema();++ // Verify field types in Iceberg schema+ for (org.apache.iceberg.types.Types.NestedField field : schema.columns()) {+ String fieldName = field.name();+ org.apache.iceberg.types.Type fieldType = field.type();++ if (fieldName.startsWith("time_col")) {+ Assertions.assertInstanceOf(+ org.apache.iceberg.types.Types.TimeType.class,+ fieldType,+ String.format(+ "Field %s should be TimeType but was %s",+ fieldName, fieldType.getClass().getSimpleName()));+ } else {+ String format =+ String.format(+ "Field %s should be TimestampType but was %s",+ fieldName, fieldType.getClass().getSimpleName());+ if (fieldName.startsWith("timestamptz_col")) {+ Assertions.assertInstanceOf(+ org.apache.iceberg.types.Types.TimestampType.class, fieldType, format);+ org.apache.iceberg.types.Types.TimestampType tsType =+ (org.apache.iceberg.types.Types.TimestampType) fieldType;+ Assertions.assertTrue(tsType.shouldAdjustToUTC(), "Timestamptz should adjust to UTC");+ } else if (fieldName.startsWith("timestamp_col")) {+ Assertions.assertInstanceOf(+ org.apache.iceberg.types.Types.TimestampType.class, fieldType, format);+ org.apache.iceberg.types.Types.TimestampType tsType =+ (org.apache.iceberg.types.Types.TimestampType) fieldType;+ Assertions.assertFalse(tsType.shouldAdjustToUTC(), "Timestamp should not adjust to UTC");+ }+ }+ }++ Assertions.assertDoesNotThrow(() -> tableCatalog.dropTable(tableIdentifier));+ }++ @Test+ void testTimeTypePrecisionValidation() {+ String tableName = GravitinoITUtils.genRandomName("test_time_precision_validation");+ NameIdentifier tableIdentifier = NameIdentifier.of(schemaName, tableName);+ Column[] columns = createColumns();++ // Test unsupported time precision+ Column[] unsupportedTimeColumns = {+ Column.of("time_col_0", Types.TimeType.of(0)),+ Column.of("time_col_1", Types.TimeType.of(1)),+ Column.of("time_col_3", Types.TimeType.of(3)),+ Column.of("time_col_9", Types.TimeType.of(9))+ };++ // Test unsupported timestamptz precision (with timezone)+ Column[] unsupportedTimestamptzColumns = {+ Column.of("timestamptz_col_0", Types.TimestampType.withTimeZone(0)),+ Column.of("timestamptz_col_1", Types.TimestampType.withTimeZone(1)),+ Column.of("timestamptz_col_3", Types.TimestampType.withTimeZone(3)),+ Column.of("timestamptz_col_9", Types.TimestampType.withTimeZone(9))+ };++ // Test unsupported timestamp precision (without timezone)+ Column[] unsupportedTimestampColumns = {+ Column.of("timestamp_col_0", Types.TimestampType.withoutTimeZone(0)),+ Column.of("timestamp_col_1", Types.TimestampType.withoutTimeZone(1)),+ Column.of("timestamp_col_3", Types.TimestampType.withoutTimeZone(3)),+ Column.of("timestamp_col_9", Types.TimestampType.withoutTimeZone(9))+ };++ TableCatalog tableCatalog = catalog.asTableCatalog();++ // Test time precision validation+ for (Column column : unsupportedTimeColumns) {+ Column[] testColumns = ArrayUtils.addAll(columns, column);+ IllegalArgumentException exception =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () ->+ tableCatalog.createTable(+ tableIdentifier,+ testColumns,+ table_comment,+ createProperties(),+ Transforms.EMPTY_TRANSFORM,+ Distributions.NONE,+ new SortOrder[0]));+ Assertions.assertTrue(+ exception+ .getMessage()+ .contains("Iceberg only supports microsecond precision (6) for time type"));+ }++ // Test timestamptz precision validation (with timezone)+ for (Column column : unsupportedTimestamptzColumns) {+ Column[] testColumns = ArrayUtils.addAll(columns, column);+ IllegalArgumentException exception =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () ->+ tableCatalog.createTable(+ tableIdentifier,+ testColumns,+ table_comment,+ createProperties(),+ Transforms.EMPTY_TRANSFORM,+ Distributions.NONE,+ new SortOrder[0]));+ Assertions.assertTrue(+ exception+ .getMessage()+ .contains("Iceberg only supports microsecond precision (6) for timestamptz type"));+ }++ // Test timestamp precision validation (without timezone)+ for (Column column : unsupportedTimestampColumns) {+ Column[] testColumns = ArrayUtils.addAll(columns, column);+ IllegalArgumentException exception =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () ->+ tableCatalog.createTable(+ tableIdentifier,+ testColumns,+ table_comment,+ createProperties(),+ Transforms.EMPTY_TRANSFORM,+ Distributions.NONE,+ new SortOrder[0]));+ Assertions.assertTrue(+ exception+ .getMessage()+ .contains("Iceberg only supports microsecond precision (6) for timestamp type"));+ }+ }+protected static void assertionsTableInfo(String tableName,String tableComment,diff --git a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TypeUtils.java b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TypeUtils.javaindex 0816cb5fdc..a9e7b2365a 100644--- a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TypeUtils.java+++ b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TypeUtils.java@@ -49,6 +49,9 @@ import org.apache.paimon.types.VarCharType;/** Utilities of {@link Type} to support type conversion. */public class TypeUtils {+ public static final int PRECISION_SECOND = 0;+ public static final int PRECISION_MICROSECOND = 6;+private TypeUtils() {}/**@@ -122,17 +125,17 @@ public class TypeUtils {@Overridepublic Type visit(TimeType timeType) {- return Types.TimeType.get();+ return Types.TimeType.of(timeType.getPrecision());}@Overridepublic Type visit(TimestampType timestampType) {- return Types.TimestampType.withoutTimeZone();+ return Types.TimestampType.withoutTimeZone(timestampType.getPrecision());}@Overridepublic Type visit(LocalZonedTimestampType localZonedTimestampType) {- return Types.TimestampType.withTimeZone();+ return Types.TimestampType.withTimeZone(localZonedTimestampType.getPrecision());}@Override@@ -229,11 +232,19 @@ public class TypeUtils {case DATE:return DataTypes.DATE();case TIME:- return DataTypes.TIME();+ Types.TimeType timeType = (Types.TimeType) type;+ int timeTypePrecision =+ timeType.hasPrecisionSet() ? timeType.precision() : PRECISION_SECOND;+ return DataTypes.TIME(timeTypePrecision);case TIMESTAMP:- return ((Types.TimestampType) type).hasTimeZone()- ? DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE()- : DataTypes.TIMESTAMP();+ Types.TimestampType timestampType = (Types.TimestampType) type;+ int timestampTypePrecision =+ timestampType.hasPrecisionSet() ? timestampType.precision() : PRECISION_MICROSECOND;+ if (timestampType.hasTimeZone()) {+ return DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(timestampTypePrecision);+ } else {+ return DataTypes.TIMESTAMP(timestampTypePrecision);+ }case STRING:return DataTypes.STRING();case VARCHAR:diff --git a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.javaindex b2c6d624a2..f83a850ef7 100644--- a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java+++ b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java@@ -35,6 +35,7 @@ import java.util.List;import java.util.Locale;import java.util.Map;import java.util.Set;+import org.apache.commons.lang3.ArrayUtils;import org.apache.gravitino.Catalog;import org.apache.gravitino.NameIdentifier;import org.apache.gravitino.Namespace;@@ -72,7 +73,9 @@ import org.apache.paimon.catalog.Catalog.DatabaseNotExistException;import org.apache.paimon.catalog.Identifier;import org.apache.paimon.schema.TableSchema;import org.apache.paimon.table.FileStoreTable;+import org.apache.paimon.types.DataField;import org.apache.paimon.types.LocalZonedTimestampType;+import org.apache.paimon.types.TimeType;import org.apache.paimon.types.TimestampType;import org.apache.spark.sql.Dataset;import org.apache.spark.sql.Row;@@ -541,13 +544,13 @@ public abstract class CatalogPaimonBaseIT extends BaseIT {Table loadTable = tableCatalog.loadTable(tableIdentifier);Assertions.assertEquals("paimon_column_1", loadTable.columns()[0].name());- Assertions.assertEquals(Types.TimestampType.withTimeZone(), loadTable.columns()[0].dataType());+ Assertions.assertEquals(Types.TimestampType.withTimeZone(6), loadTable.columns()[0].dataType());Assertions.assertEquals("col_1_comment", loadTable.columns()[0].comment());Assertions.assertTrue(loadTable.columns()[0].nullable());Assertions.assertEquals("paimon_column_2", loadTable.columns()[1].name());Assertions.assertEquals(- Types.TimestampType.withoutTimeZone(), loadTable.columns()[1].dataType());+ Types.TimestampType.withoutTimeZone(6), loadTable.columns()[1].dataType());Assertions.assertEquals("col_2_comment", loadTable.columns()[1].comment());Assertions.assertTrue(loadTable.columns()[1].nullable());@@ -854,6 +857,170 @@ public abstract class CatalogPaimonBaseIT extends BaseIT {}}+ @Test+ void testTimeTypePrecision() throws org.apache.paimon.catalog.Catalog.TableNotExistException {+ String tableName = GravitinoITUtils.genRandomName("test_time_precision");+ NameIdentifier tableIdentifier = NameIdentifier.of(schemaName, tableName);+ Column[] columns = createColumns();+ columns =+ ArrayUtils.addAll(+ columns,+ // time type+ Column.of("time_col", Types.TimeType.get()),+ Column.of("time_col_0", Types.TimeType.of(0)),+ Column.of("time_col_1", Types.TimeType.of(1)),+ Column.of("time_col_3", Types.TimeType.of(3)),+ Column.of("time_col_6", Types.TimeType.of(6)),+ // timestamp type+ Column.of("timestamp_col", Types.TimestampType.withTimeZone()),+ Column.of("timestamp_col_0", Types.TimestampType.withTimeZone(0)),+ Column.of("timestamp_col_1", Types.TimestampType.withTimeZone(1)),+ Column.of("timestamp_col_3", Types.TimestampType.withTimeZone(3)),+ Column.of("timestamp_col_6", Types.TimestampType.withTimeZone(6)),+ // datetime type (without time zone)+ Column.of("datetime_col", Types.TimestampType.withoutTimeZone()),+ Column.of("datetime_col_0", Types.TimestampType.withoutTimeZone(0)),+ Column.of("datetime_col_1", Types.TimestampType.withoutTimeZone(1)),+ Column.of("datetime_col_3", Types.TimestampType.withoutTimeZone(3)),+ Column.of("datetime_col_6", Types.TimestampType.withoutTimeZone(6)));++ Map<String, String> properties = createProperties();+ TableCatalog tableCatalog = catalog.asTableCatalog();+ tableCatalog.createTable(+ tableIdentifier,+ columns,+ table_comment,+ properties,+ Transforms.EMPTY_TRANSFORM,+ Distributions.NONE,+ new SortOrder[0]);++ Table loadTable = tableCatalog.loadTable(tableIdentifier);++ // Verify time type precisions+ Column[] timeColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("time_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(5, timeColumns.length);+ for (Column column : timeColumns) {+ switch (column.name()) {+ case "time_col":+ Assertions.assertEquals(Types.TimeType.of(0), column.dataType());+ break;+ case "time_col_0":+ Assertions.assertEquals(Types.TimeType.of(0), column.dataType());+ break;+ case "time_col_1":+ Assertions.assertEquals(Types.TimeType.of(1), column.dataType());+ break;+ case "time_col_3":+ Assertions.assertEquals(Types.TimeType.of(3), column.dataType());+ break;+ case "time_col_6":+ Assertions.assertEquals(Types.TimeType.of(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected time column: " + column.name());+ }+ }++ // Verify timestamp type precisions+ Column[] timestampColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("timestamp_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(5, timestampColumns.length);+ for (Column column : timestampColumns) {+ switch (column.name()) {+ case "timestamp_col":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(6), column.dataType());+ break;+ case "timestamp_col_0":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(0), column.dataType());+ break;+ case "timestamp_col_1":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(1), column.dataType());+ break;+ case "timestamp_col_3":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(3), column.dataType());+ break;+ case "timestamp_col_6":+ Assertions.assertEquals(Types.TimestampType.withTimeZone(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected timestamp column: " + column.name());+ }+ }++ // Verify datetime type precisions+ Column[] datetimeColumns =+ Arrays.stream(loadTable.columns())+ .filter(c -> c.name().startsWith("datetime_col"))+ .toArray(Column[]::new);++ Assertions.assertEquals(5, datetimeColumns.length);+ for (Column column : datetimeColumns) {+ switch (column.name()) {+ case "datetime_col":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(6), column.dataType());+ break;+ case "datetime_col_0":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(0), column.dataType());+ break;+ case "datetime_col_1":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(1), column.dataType());+ break;+ case "datetime_col_3":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(3), column.dataType());+ break;+ case "datetime_col_6":+ Assertions.assertEquals(Types.TimestampType.withoutTimeZone(6), column.dataType());+ break;+ default:+ Assertions.fail("Unexpected datetime column: " + column.name());+ }+ }++ // Verify Paimon catalog type conversion+ org.apache.paimon.table.Table table =+ paimonCatalog.getTable(Identifier.create(schemaName, tableName));+ Assertions.assertInstanceOf(FileStoreTable.class, table);+ FileStoreTable fileStoreTable = (FileStoreTable) table;+ TableSchema schema = fileStoreTable.schema();++ // Verify field types in Paimon schema+ for (DataField field : schema.fields()) {+ String fieldName = field.name();+ org.apache.paimon.types.DataType fieldType = field.type();++ if (fieldName.startsWith("time_col")) {+ Assertions.assertInstanceOf(+ TimeType.class,+ fieldType,+ String.format(+ "Field %s should be TimeType but was %s",+ fieldName, fieldType.getClass().getSimpleName()));+ } else if (fieldName.startsWith("timestamp_col")) {+ Assertions.assertInstanceOf(+ LocalZonedTimestampType.class,+ fieldType,+ String.format(+ "Field %s should be LocalZonedTimestampType but was %s",+ fieldName, fieldType.getClass().getSimpleName()));+ } else if (fieldName.startsWith("datetime_col")) {+ Assertions.assertInstanceOf(+ TimestampType.class,+ fieldType,+ String.format(+ "Field %s should be TimestampType but was %s",+ fieldName, fieldType.getClass().getSimpleName()));+ }+ }+ }+private static @NotNull List<String> getValues() {List<String> values = new ArrayList<>();for (int i = 1; i < 5; i++) {diff --git a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TestTypeUtils.java b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TestTypeUtils.javaindex d5e959d34e..019752b4a3 100644--- a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TestTypeUtils.java+++ b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TestTypeUtils.java@@ -61,8 +61,20 @@ public class TestTypeUtils {DataTypes.DECIMAL(8, 3),DataTypes.DATE(),DataTypes.TIME(),+ DataTypes.TIME(0),+ DataTypes.TIME(3),+ DataTypes.TIME(6),+ DataTypes.TIME(9),DataTypes.TIMESTAMP(),+ DataTypes.TIMESTAMP(0),+ DataTypes.TIMESTAMP(3),+ DataTypes.TIMESTAMP(6),+ DataTypes.TIMESTAMP(9),DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(),+ DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(0),+ DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(3),+ DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(6),+ DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(9),DataTypes.STRING(),DataTypes.VARCHAR(10),DataTypes.CHAR(10),diff --git a/common/src/main/java/org/apache/gravitino/json/JsonUtils.java b/common/src/main/java/org/apache/gravitino/json/JsonUtils.javaindex f0f79bd454..68b66220ad 100644--- a/common/src/main/java/org/apache/gravitino/json/JsonUtils.java+++ b/common/src/main/java/org/apache/gravitino/json/JsonUtils.java@@ -169,6 +169,9 @@ public class JsonUtils {private static final Pattern VARCHAR = Pattern.compile("varchar\\(\\s*(\\d+)\\s*\\)");private static final Pattern DECIMAL =Pattern.compile("decimal\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)");+ private static final Pattern TIME = Pattern.compile("time\\((\\d+)\\)");+ private static final Pattern TIMESTAMP_TZ = Pattern.compile("timestamp_tz\\((\\d+)\\)");+ private static final Pattern TIMESTAMP = Pattern.compile("timestamp\\((\\d+)\\)");/*** Abstract iterator class for iterating over elements of a JSON array.@@ -852,6 +855,21 @@ public class JsonUtils {Integer.parseInt(decimal.group(1)), Integer.parseInt(decimal.group(2)));}+ Matcher time = TIME.matcher(typeString);+ if (time.matches()) {+ return Types.TimeType.of(Integer.parseInt(time.group(1)));+ }++ Matcher timestampTz = TIMESTAMP_TZ.matcher(typeString);+ if (timestampTz.matches()) {+ return Types.TimestampType.withTimeZone(Integer.parseInt(timestampTz.group(1)));+ }++ Matcher timestamp = TIMESTAMP.matcher(typeString);+ if (timestamp.matches()) {+ return Types.TimestampType.withoutTimeZone(Integer.parseInt(timestamp.group(1)));+ }+return Types.UnparsedType.of(typeString);}diff --git a/docs/jdbc-doris-catalog.md b/docs/jdbc-doris-catalog.mdindex 82fa4e1655..6cf55de4bb 100644--- a/docs/jdbc-doris-catalog.md+++ b/docs/jdbc-doris-catalog.md@@ -55,6 +55,31 @@ Besides the [common catalog properties](./gravitino-server-config.md#apache-gravBefore using the Doris Catalog, you must download the corresponding JDBC driver to the `catalogs/jdbc-doris/libs` directory.Gravitino doesn't package the JDBC driver for Doris due to licensing issues.+### Driver Version Compatibility++The Doris catalog includes driver version compatibility checks for datetime precision calculation:++- **MySQL Connector/J versions >= 8.0.16**: Full support for datetime precision calculation+- **MySQL Connector/J versions < 8.0.16**: Limited support - datetime precision calculation returns `null` with a warning log++This limitation affects the following datetime types:+- `DATETIME(p)` - datetime precision++When using an unsupported driver version, the system will:+1. Continue to work normally with default precision (0)+2. Log a warning message indicating the driver version limitation+3. Return `null` for precision calculations to avoid incorrect results++**Example warning log:**+```+WARN: MySQL driver version mysql-connector-java-8.0.11 is below 8.0.16,+columnSize may not be accurate for precision calculation.+Returning null for DATETIME type precision. Driver version: mysql-connector-java-8.0.11+```++**Recommended driver versions:**+- `mysql-connector-java-8.0.16` or higher+### Catalog operationsRefer to [Manage Relational Metadata Using Gravitino](./manage-relational-metadata-using-gravitino.md#catalog-operations) for more details.@@ -86,21 +111,21 @@ Please refer to#### Table column types-| Gravitino Type | Doris Type |-|----------------|------------|-| `Boolean` | `Boolean` |-| `Byte` | `TinyInt` |-| `Short` | `SmallInt` |-| `Integer` | `Int` |-| `Long` | `BigInt` |-| `Float` | `Float` |-| `Double` | `Double` |-| `Decimal` | `Decimal` |-| `Date` | `Date` |-| `Timestamp` | `Datetime` |-| `VarChar` | `VarChar` |-| `FixedChar` | `Char` |-| `String` | `String` |+| Gravitino Type | Doris Type |+|------------------|-----------------|+| `Boolean` | `Boolean` |+| `Byte` | `TinyInt` |+| `Short` | `SmallInt` |+| `Integer` | `Int` |+| `Long` | `BigInt` |+| `Float` | `Float` |+| `Double` | `Double` |+| `Decimal` | `Decimal` |+| `Date` | `Date` |+| `Timestamp[(p)]` | `Datetime[(p)]` |+| `VarChar` | `VarChar` |+| `FixedChar` | `Char` |+| `String` | `String` |Doris doesn't support Gravitino `Fixed` `Timestamp_tz` `IntervalDay` `IntervalYear` `Union` `UUID` type.diff --git a/docs/jdbc-mysql-catalog.md b/docs/jdbc-mysql-catalog.mdindex 76d56eabc3..5406daea55 100644--- a/docs/jdbc-mysql-catalog.md+++ b/docs/jdbc-mysql-catalog.md@@ -54,6 +54,33 @@ Besides the [common catalog properties](./gravitino-server-config.md#apache-gravYou must download the corresponding JDBC driver to the `catalogs/jdbc-mysql/libs` directory.:::+### Driver Version Compatibility++The MySQL catalog includes driver version compatibility checks for datetime precision calculation:++- **MySQL Connector/J versions >= 8.0.16**: Full support for datetime precision calculation+- **MySQL Connector/J versions < 8.0.16**: Limited support - datetime precision calculation returns `null` with a warning log++This limitation affects the following datetime types:+- `TIME(p)` - time precision+- `TIMESTAMP(p)` - timestamp precision+- `DATETIME(p)` - datetime precision++When using an unsupported driver version, the system will:+1. Continue to work normally with default precision (0)+2. Log a warning message indicating the driver version limitation+3. Return `null` for precision calculations to avoid incorrect results++**Example warning log:**+```+WARN: MySQL driver version mysql-connector-java-8.0.11 is below 8.0.16,+columnSize may not be accurate for precision calculation.+Returning null for TIMESTAMP type precision. Driver version: mysql-connector-java-8.0.11+```++**Recommended driver versions:**+- `mysql-connector-java-8.0.16` or higher+### Catalog operationsRefer to [Manage Relational Metadata Using Gravitino](./manage-relational-metadata-using-gravitino.md#catalog-operations) for more details.@@ -87,30 +114,31 @@ Refer to [Manage Relational Metadata Using Gravitino](./manage-relational-metada### Table column types-| Gravitino Type | MySQL Type |-|--------------------|---------------------|-| `Byte` | `Tinyint` |-| `Unsigned Byte` | `Tinyint Unsigned` |-| `Short` | `Smallint` |-| `Unsigned Short` | `Smallint Unsigned` |-| `Integer` | `Int` |-| `Unsigned Integer` | `Int Unsigned` |-| `Long` | `Bigint` |-| `Unsigned Long` | `Bigint Unsigned` |-| `Float` | `Float` |-| `Double` | `Double` |-| `String` | `Text` |-| `Date` | `Date` |-| `Time` | `Time` |-| `Timestamp` | `Timestamp` |-| `Decimal` | `Decimal` |-| `VarChar` | `VarChar` |-| `FixedChar` | `FixedChar` |-| `Binary` | `Binary` |-| `BOOLEAN` | `BIT` |+| Gravitino Type | MySQL Type |+|----------------------|---------------------|+| `Byte` | `Tinyint` |+| `Unsigned Byte` | `Tinyint Unsigned` |+| `Short` | `Smallint` |+| `Unsigned Short` | `Smallint Unsigned` |+| `Integer` | `Int` |+| `Unsigned Integer` | `Int Unsigned` |+| `Long` | `Bigint` |+| `Unsigned Long` | `Bigint Unsigned` |+| `Float` | `Float` |+| `Double` | `Double` |+| `String` | `Text` |+| `Date` | `Date` |+| `Time[(p)]` | `Time[(p)]` |+| `Timestamp_tz[(p)]` | `Timestamp(p)` |+| `Timestamp[(p)]` | `Datetime[(p)]` |+| `Decimal` | `Decimal` |+| `VarChar` | `VarChar` |+| `FixedChar` | `FixedChar` |+| `Binary` | `Binary` |+| `BOOLEAN` | `BIT` |:::info-MySQL doesn't support Gravitino `Fixed` `Struct` `List` `Map` `Timestamp_tz` `IntervalDay` `IntervalYear` `Union` `UUID` type.+MySQL doesn't support Gravitino `Fixed` `Struct` `List` `Map` `IntervalDay` `IntervalYear` `Union` `UUID` type.Meanwhile, the data types other than listed above are mapped to Gravitino **[External Type](./manage-relational-metadata-using-gravitino.md#external-type)** that represents an unresolvable data type since 0.6.0-incubating.:::diff --git a/docs/jdbc-oceanbase-catalog.md b/docs/jdbc-oceanbase-catalog.mdindex 58a9f8548a..6acada8da9 100644--- a/docs/jdbc-oceanbase-catalog.md+++ b/docs/jdbc-oceanbase-catalog.md@@ -52,6 +52,34 @@ Before using the OceanBase Catalog, you must download the corresponding JDBC driGravitino doesn't package the JDBC driver for OceanBase due to licensing issues.:::+### Driver Version Compatibility++The OceanBase catalog includes driver version compatibility checks for datetime precision calculation:++- **MySQL Connector/J versions >= 8.0.16**: Full support for datetime precision calculation+- **MySQL Connector/J versions < 8.0.16**: Limited support - datetime precision calculation returns `null` with a warning log++This limitation affects the following datetime types:+- `TIME(p)` - time precision+- `TIMESTAMP(p)` - timestamp precision+- `DATETIME(p)` - datetime precision++When using an unsupported driver version, the system will:+1. Continue to work normally with default precision (0)+2. Log a warning message indicating the driver version limitation+3. Return `null` for precision calculations to avoid incorrect results++**Example warning log:**+```+WARN: MySQL driver version mysql-connector-java-8.0.11 is below 8.0.16,+columnSize may not be accurate for precision calculation.+Returning null for TIMESTAMP type precision. Driver version: mysql-connector-java-8.0.11+```++**Recommended driver versions:**+- `mysql-connector-java-8.0.16` or higher+- `com.oceanbase.jdbc.Driver` (OceanBase official driver)+### Catalog operationsRefer to [Manage Relational Metadata Using Gravitino](./manage-relational-metadata-using-gravitino.md#catalog-operations) for more details.@@ -88,29 +116,30 @@ Refer to [Manage Relational Metadata Using Gravitino](./manage-relational-metada### Table column types-| Gravitino Type | OceanBase Type |-|-------------------|---------------------|-| `Byte` | `Tinyint` |-| `Byte(false)` | `Tinyint Unsigned` |-| `Short` | `Smallint` |-| `Short(false)` | `Smallint Unsigned` |-| `Integer` | `Int` |-| `Integer(false)` | `Int Unsigned` |-| `Long` | `Bigint` |-| `Long(false)` | `Bigint Unsigned` |-| `Float` | `Float` |-| `Double` | `Double` |-| `String` | `Text` |-| `Date` | `Date` |-| `Time` | `Time` |-| `Timestamp` | `Timestamp` |-| `Decimal` | `Decimal` |-| `VarChar` | `VarChar` |-| `FixedChar` | `FixedChar` |-| `Binary` | `Binary` |+| Gravitino Type | OceanBase Type |+|---------------------|---------------------|+| `Byte` | `Tinyint` |+| `Byte(false)` | `Tinyint Unsigned` |+| `Short` | `Smallint` |+| `Short(false)` | `Smallint Unsigned` |+| `Integer` | `Int` |+| `Integer(false)` | `Int Unsigned` |+| `Long` | `Bigint` |+| `Long(false)` | `Bigint Unsigned` |+| `Float` | `Float` |+| `Double` | `Double` |+| `String` | `Text` |+| `Date` | `Date` |+| `Time[(p)]` | `Time[(p)]` |+| `Timestamp_tz[(p)]` | `Timestamp[(p)]` |+| `Timestamp[(p)]` | `Datetime[(p)]` |+| `Decimal` | `Decimal` |+| `VarChar` | `VarChar` |+| `FixedChar` | `FixedChar` |+| `Binary` | `Binary` |:::info-OceanBase doesn't support Gravitino `Boolean` `Fixed` `Struct` `List` `Map` `Timestamp_tz` `IntervalDay` `IntervalYear` `Union` `UUID` type.+OceanBase doesn't support Gravitino `Boolean` `Fixed` `Struct` `List` `Map` `IntervalDay` `IntervalYear` `Union` `UUID` type.Meanwhile, the data types other than listed above are mapped to Gravitino **[External Type](./manage-relational-metadata-using-gravitino.md#external-type)** that represents an unresolvable data type since 0.6.0-incubating.:::diff --git a/docs/jdbc-postgresql-catalog.md b/docs/jdbc-postgresql-catalog.mdindex 3adb13ce22..c3285ab5c2 100644--- a/docs/jdbc-postgresql-catalog.md+++ b/docs/jdbc-postgresql-catalog.md@@ -90,24 +90,24 @@ Please refer to [Manage Relational Metadata Using Gravitino](./manage-relational### Table column types-| Gravitino Type | PostgreSQL Type |-|----------------|-----------------|-| `Boolean` | `Bool` |-| `Short` | `Int2` |-| `Integer` | `Int4` |-| `Long` | `Int8` |-| `Float` | `Float4` |-| `Double` | `Float8` |-| `String` | `Text` |-| `Date` | `Date` |-| `Time` | `Time` |-| `Timestamp` | `Timestamp` |-| `Timestamp_tz` | `Timestamptz` |-| `Decimal` | `Numeric` |-| `VarChar` | `Varchar` |-| `FixedChar` | `Bpchar` |-| `Binary` | `Bytea` |-| `List` | `Array` |+| Gravitino Type | PostgreSQL Type |+|-------------------|------------------|+| `Boolean` | `Bool` |+| `Short` | `Int2` |+| `Integer` | `Int4` |+| `Long` | `Int8` |+| `Float` | `Float4` |+| `Double` | `Float8` |+| `String` | `Text` |+| `Date` | `Date` |+| `Time(p)` | `Time(p)` |+| `Timestamp(p)` | `Timestamp(p)` |+| `Timestamp_tz(p)` | `Timestamptz(p)` |+| `Decimal` | `Numeric` |+| `VarChar` | `Varchar` |+| `FixedChar` | `Bpchar` |+| `Binary` | `Bytea` |+| `List` | `Array` |:::infoPostgreSQL doesn't support Gravitino `Fixed` `Struct` `Map` `IntervalDay` `IntervalYear` `Union` `UUID` type.diff --git a/docs/lakehouse-iceberg-catalog.md b/docs/lakehouse-iceberg-catalog.mdindex 8a7d712926..ace2f501c6 100644--- a/docs/lakehouse-iceberg-catalog.md+++ b/docs/lakehouse-iceberg-catalog.md@@ -232,25 +232,25 @@ If you doesn't specify distribution expressions, the table distribution will be### Table column types-| Gravitino Type | Apache Iceberg Type |-|-----------------------------|-----------------------------|-| `Struct` | `Struct` |-| `Map` | `Map` |-| `List` | `Array` |-| `Boolean` | `Boolean` |-| `Integer` | `Integer` |-| `Long` | `Long` |-| `Float` | `Float` |-| `Double` | `Double` |-| `String` | `String` |-| `Date` | `Date` |-| `Time` | `Time` |-| `TimestampType withZone` | `TimestampType withZone` |-| `TimestampType withoutZone` | `TimestampType withoutZone` |-| `Decimal` | `Decimal` |-| `Fixed` | `Fixed` |-| `Binary` | `Binary` |-| `UUID` | `UUID` |+| Gravitino Type | Apache Iceberg Type |+|-------------------|-----------------------------|+| `Struct` | `Struct` |+| `Map` | `Map` |+| `List` | `Array` |+| `Boolean` | `Boolean` |+| `Integer` | `Integer` |+| `Long` | `Long` |+| `Float` | `Float` |+| `Double` | `Double` |+| `String` | `String` |+| `Date` | `Date` |+| `Time(6)` | `Time` |+| `Timestamp(6)` | `TimestampType withZone` |+| `Timestamp_tz(6)` | `TimestampType withoutZone` |+| `Decimal` | `Decimal` |+| `Fixed` | `Fixed` |+| `Binary` | `Binary` |+| `UUID` | `UUID` |:::infoApache Iceberg doesn't support Gravitino `Varchar` `Fixedchar` `Byte` `Short` `Union` type.diff --git a/docs/lakehouse-paimon-catalog.md b/docs/lakehouse-paimon-catalog.mdindex aa4c1759df..88f2f35796 100644--- a/docs/lakehouse-paimon-catalog.md+++ b/docs/lakehouse-paimon-catalog.md@@ -155,28 +155,28 @@ Paimon Table primary key constraint should not be same with partition fields, th### Table column types-| Gravitino Type | Apache Paimon Type |-|-----------------------------|------------------------------|-| `Struct` | `Row` |-| `Map` | `Map` |-| `List` | `Array` |-| `Boolean` | `Boolean` |-| `Byte` | `TinyInt` |-| `Short` | `SmallInt` |-| `Integer` | `Int` |-| `Long` | `BigInt` |-| `Float` | `Float` |-| `Double` | `Double` |-| `Decimal` | `Decimal` |-| `String` | `VarChar(Integer.MAX_VALUE)` |-| `VarChar` | `VarChar` |-| `FixedChar` | `Char` |-| `Date` | `Date` |-| `Time` | `Time` |-| `TimestampType withZone` | `LocalZonedTimestamp` |-| `TimestampType withoutZone` | `Timestamp` |-| `Fixed` | `Binary` |-| `Binary` | `VarBinary` |+| Gravitino Type | Apache Paimon Type |+|-------------------|------------------------------|+| `Struct` | `Row` |+| `Map` | `Map` |+| `List` | `Array` |+| `Boolean` | `Boolean` |+| `Byte` | `TinyInt` |+| `Short` | `SmallInt` |+| `Integer` | `Int` |+| `Long` | `BigInt` |+| `Float` | `Float` |+| `Double` | `Double` |+| `Decimal` | `Decimal` |+| `String` | `VarChar(Integer.MAX_VALUE)` |+| `VarChar` | `VarChar` |+| `FixedChar` | `Char` |+| `Date` | `Date` |+| `Time(p)` | `Time(p)` |+| `Timestamp(p)` | `LocalZonedTimestamp(p)` |+| `Timestamp_tz(p)` | `Timestamp(p)` |+| `Fixed` | `Binary` |+| `Binary` | `VarBinary` |:::infoGravitino doesn't support Paimon `MultisetType` type.diff --git a/docs/manage-relational-metadata-using-gravitino.md b/docs/manage-relational-metadata-using-gravitino.mdindex 0a298afc35..6b3a90ff14 100644--- a/docs/manage-relational-metadata-using-gravitino.md+++ b/docs/manage-relational-metadata-using-gravitino.md@@ -895,8 +895,8 @@ The following types that Gravitino supports:| String | `Types.StringType.get()` | `string` | String type || FixedChar(length) | `Types.FixedCharType.of(length)` | `char(l)` | Char type, indicates a fixed-length string || VarChar(length) | `Types.VarCharType.of(length)` | `varchar(l)` | Varchar type, indicates a variable-length string, the length is the maximum length of the string |-| Timestamp | `Types.TimestampType.withoutTimeZone()` | `timestamp` | Timestamp type, indicates a timestamp without timezone |-| TimestampWithTimezone | `Types.TimestampType.withTimeZone()` | `timestamp_tz` | Timestamp with timezone type, indicates a timestamp with timezone |+| Timestamp(p) | `Types.TimestampType.withoutTimeZone(p)` | `timestamp(p)` | Timestamp type, indicates a timestamp without timezone, where p is the precision of fractional seconds (0-12) |+| TimestampWithTimezone(p) | `Types.TimestampType.withTimeZone(p)` | `timestamp_tz(p)` | Timestamp with timezone type, indicates a timestamp with timezone, where p is the precision of fractional seconds (0-12) || Date | `Types.DateType.get()` | `date` | Date type || Time | `Types.TimeType.withoutTimeZone()` | `time` | Time type || IntervalToYearMonth | `Types.IntervalYearType.get()` | `interval_year` | Interval type, indicates an interval of year and month |diff --git a/docs/open-api/datatype.yaml b/docs/open-api/datatype.yamlindex f937f45681..d5ad0cc2b5 100644--- a/docs/open-api/datatype.yaml+++ b/docs/open-api/datatype.yaml@@ -44,9 +44,9 @@ components:- "double"- "decimal(10,2)"- "date"- - "time"- - "timestamp"- - "timestamp_tz"+ - "time(3)"+ - "timestamp(3)"+ - "timestamp_tz(3)"- "string"- "char(10)"- "varchar(10)"diff --git a/flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/iceberg/FlinkIcebergCatalogIT.java b/flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/iceberg/FlinkIcebergCatalogIT.javaindex 792a5ba659..25b1ec2f37 100644--- a/flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/iceberg/FlinkIcebergCatalogIT.java+++ b/flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/iceberg/FlinkIcebergCatalogIT.java@@ -349,7 +349,7 @@ public abstract class FlinkIcebergCatalogIT extends FlinkCommonIT {Column.of("float_type", Types.FloatType.get(), "float_type"),Column.of("date_type", Types.DateType.get(), "date_type"),Column.of(- "timestamp_type", Types.TimestampType.withoutTimeZone(), "timestamp_type"),+ "timestamp_type", Types.TimestampType.withoutTimeZone(6), "timestamp_type"),Column.of("array_type", Types.ListType.of(Types.IntegerType.get(), true), "array_type"),Column.of(@@ -384,7 +384,7 @@ public abstract class FlinkIcebergCatalogIT extends FlinkCommonIT {Column.of("bigint_type", Types.LongType.get(), "bigint_type"),Column.of("float_type", Types.FloatType.get(), "float_type"),Column.of("date_type", Types.DateType.get(), "date_type"),- Column.of("timestamp_type", Types.TimestampType.withoutTimeZone(), "timestamp_type"),+ Column.of("timestamp_type", Types.TimestampType.withoutTimeZone(6), "timestamp_type"),Column.of("array_type", Types.ListType.of(Types.IntegerType.get(), true), "array_type"),Column.of("map_type",diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.tomlindex 4745cf87b2..4d6fa790ae 100644--- a/gradle/libs.versions.toml+++ b/gradle/libs.versions.toml@@ -146,7 +146,7 @@ kerby-simplekdc = { group = "org.apache.kerby", name = "kerb-simplekdc", versionlombok = { group = "org.projectlombok", name = "lombok", version.ref = "lombok" }junit-jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version.ref = "junit" }-junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine"}+junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" }slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }slf4j-jdk14 = { group = "org.slf4j", name = "slf4j-jdk14", version = "1.7.30" }diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.propertiesindex 8afdd29416..3f788ef6b5 100644--- a/gradle/wrapper/gradle-wrapper.properties+++ b/gradle/wrapper/gradle-wrapper.properties@@ -1,3 +1,21 @@+#+# Licensed to the Apache Software Foundation (ASF) under one+# or more contributor license agreements. See the NOTICE file+# distributed with this work for additional information+# regarding copyright ownership. The ASF licenses this file+# to you under the Apache License, Version 2.0 (the+# "License"); you may not use this file except in compliance+# with the License. You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing,+# software distributed under the License is distributed on an+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+# KIND, either express or implied. See the License for the+# specific language governing permissions and limitations+# under the License.+#distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/dists# checksum was taken from https://gradle.org/release-checksums