Skip to content

Commit d3e8ef5

Browse files
committed
fix: update
Signed-off-by: zacsun <[email protected]>
1 parent c493269 commit d3e8ef5

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

api/src/main/java/org/apache/gravitino/rel/types/Types.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public Name name() {
364364

365365
@Override
366366
public String simpleString() {
367-
return precision.map(integer -> String.format("time(%d)", integer)).orElse("time");
367+
return precision.filter(p -> p > 0).map(p -> String.format("time(%d)", p)).orElse("time");
368368
}
369369

370370
@Override
@@ -441,11 +441,12 @@ public Name name() {
441441
@Override
442442
public String simpleString() {
443443
return precision
444+
.filter(p -> p > 0)
444445
.map(
445-
integer ->
446+
p ->
446447
withTimeZone
447-
? String.format("timestamp_tz(%d)", integer)
448-
: String.format("timestamp(%d)", integer))
448+
? String.format("timestamp_tz(%d)", p)
449+
: String.format("timestamp(%d)", p))
449450
.orElse(withTimeZone ? "timestamp_tz" : "timestamp");
450451
}
451452

catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/converter/MysqlTypeConverter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ public String fromGravitino(Type type) {
138138
// such as DATETIME.) see more details: https://dev.mysql.com/doc/refman/8.0/en/datetime.html
139139
Types.TimestampType timestampType = (Types.TimestampType) type;
140140
String baseType = timestampType.hasTimeZone() ? TIMESTAMP : DATETIME;
141-
return timestampType.precision().isPresent()
142-
? String.format("%s(%d)", baseType, timestampType.precision().get())
143-
: baseType;
141+
return timestampType
142+
.precision()
143+
.filter(p -> p > 0)
144+
.map(p -> String.format("%s(%d)", baseType, p))
145+
.orElse(baseType);
144146
} else if (type instanceof Types.DecimalType) {
145147
return type.simpleString();
146148
} else if (type instanceof Types.VarCharType) {

catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/operation/MysqlTableOperations.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,9 @@ private static void validateIndexes(Index[] indexes, JdbcColumn[] columns) {
679679
* TIME: Format is 'HH:MM:SS' (8 chars) + precision - TIMESTAMP/DATETIME: Format is 'YYYY-MM-DD
680680
* HH:MM:SS' (19 chars) + precision
681681
*
682-
* <p>The precision is calculated by subtracting the base format length from the total column
683-
* size. For example: - TIME(6) has columnSize = 14 (8 + 6) - TIMESTAMP(6) has columnSize = 25 (19
684-
* + 6)
682+
* <p>The precision is calculated by subtracting the base format length plus one (for decimal
683+
* point) from the total column size. For example: - TIME(6) has columnSize = 15 (8 + 1 + 6) -
684+
* TIMESTAMP(6) has columnSize = 26 (19 + 1 + 6)
685685
*
686686
* @param typeName The data type name (TIME, TIMESTAMP, or DATETIME)
687687
* @param columnSize The total column size from MySQL JDBC driver
@@ -692,12 +692,12 @@ public int calculateDatetimePrecision(String typeName, int columnSize) {
692692
String upperTypeName = typeName.toUpperCase();
693693
switch (upperTypeName) {
694694
case "TIME":
695-
// TIME format: 'HH:MM:SS' (8 chars) + precision
696-
return columnSize > 8 ? columnSize - 9 : 0;
695+
// TIME format: 'HH:MM:SS' (8 chars) + decimal point + precision
696+
return columnSize >= 9 ? columnSize - 9 : 0;
697697
case "TIMESTAMP":
698698
case "DATETIME":
699-
// TIMESTAMP/DATETIME format: 'YYYY-MM-DD HH:MM:SS' (19 chars) + precision
700-
return columnSize > 19 ? columnSize - 20 : 0;
699+
// TIMESTAMP/DATETIME format: 'YYYY-MM-DD HH:MM:SS' (19 chars) + decimal point + precision
700+
return columnSize >= 20 ? columnSize - 20 : 0;
701701
}
702702
return 0;
703703
}

0 commit comments

Comments
 (0)