hqbhoho commented on code in PR #7852:
URL: https://github.com/apache/gravitino/pull/7852#discussion_r2261826341


##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/jdbc/mysql/MysqlColumnDefaultValueConverter.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.trino.connector.catalog.jdbc.mysql;
+
+import static org.apache.gravitino.rel.Column.DEFAULT_VALUE_NOT_SET;
+import static 
org.apache.gravitino.rel.Column.DEFAULT_VALUE_OF_CURRENT_TIMESTAMP;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.format.DateTimeParseException;
+import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.gravitino.rel.expressions.literals.Literals;
+import org.apache.gravitino.rel.types.Decimal;
+import org.apache.gravitino.rel.types.Type;
+import org.apache.gravitino.rel.types.Types;
+import 
org.apache.gravitino.trino.connector.catalog.jdbc.JdbcColumnDefaultValueConverter;
+
+/**
+ * Column default value converter for MySQL
+ *
+ * <p>Referred from
+ * 
org/apache/gravitino/catalog/mysql/converter/MysqlColumnDefaultValueConverter.java
+ */
+public class MysqlColumnDefaultValueConverter extends 
JdbcColumnDefaultValueConverter {
+
+  @Override
+  public Expression toGravitino(Type type, String columnDefaultValue, boolean 
nullable) {
+    if (columnDefaultValue == null) {
+      return nullable ? Literals.NULL : DEFAULT_VALUE_NOT_SET;
+    }
+
+    if (columnDefaultValue.equalsIgnoreCase(NULL)) {
+      return Literals.NULL;
+    }
+
+    try {
+      switch (type.name()) {
+        case BYTE:
+          return Literals.byteLiteral(Byte.valueOf(columnDefaultValue));
+        case SHORT:
+          return Literals.shortLiteral(Short.valueOf(columnDefaultValue));
+        case INTEGER:
+          return Literals.integerLiteral(Integer.valueOf(columnDefaultValue));
+        case LONG:
+          return Literals.longLiteral(Long.valueOf(columnDefaultValue));
+        case FLOAT:
+          return Literals.floatLiteral(Float.valueOf(columnDefaultValue));
+        case DOUBLE:
+          return Literals.doubleLiteral(Double.valueOf(columnDefaultValue));
+        case DECIMAL:
+          Types.DecimalType decimalType = (Types.DecimalType) type;
+          return Literals.decimalLiteral(
+              Decimal.of(columnDefaultValue, decimalType.precision(), 
decimalType.scale()));
+        case DATE:
+          return Literals.dateLiteral(LocalDate.parse(columnDefaultValue, 
DATE_FORMATTER));
+        case TIME:
+          return Literals.timeLiteral(LocalTime.parse(columnDefaultValue, 
TIME_FORMATTER));
+        case TIMESTAMP:
+          if (columnDefaultValue.toUpperCase().startsWith(CURRENT_TIMESTAMP)) {

Review Comment:
   In MySQL
   ```
   
+-------+--------------+------+-----+----------------------+-------------------+
   | Field | Type         | Null | Key | Default              | Extra           
  |
   
+-------+--------------+------+-----+----------------------+-------------------+
   | f1    | timestamp    | NO   |     | CURRENT_TIMESTAMP    | 
DEFAULT_GENERATED |
   | f2    | timestamp(6) | NO   |     | CURRENT_TIMESTAMP(6) | 
DEFAULT_GENERATED |
   
+-------+--------------+------+-----+----------------------+-------------------+
   ```
   In Gravitino Server support TimestampType with default value 
'CURRENT_TIMESTAMP'
   
   Here should use `equal`. Currently, TimestampType is without precision. 



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to