Skip to content

Commit

Permalink
fix ob catalog default value parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
mchades committed Oct 30, 2024
1 parent 5c41758 commit 3c4b88f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ void testColumnDefaultValueConverter() {
+ " date_col_5 date DEFAULT '2024-04-01',\n"
+ " timestamp_col_1 timestamp default '2012-12-31 11:30:45',\n"
+ " timestamp_col_2 timestamp default 19830905,\n"
+ " timestamp_col_3 timestamp(6) default CURRENT_TIMESTAMP(6),\n"
+ " decimal_6_2_col_1 decimal(6, 2) default 1.2,\n"
+ " bit_col_1 bit default b'1'\n"
+ ");\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Objects;
import java.util.regex.Pattern;

import org.apache.gravitino.catalog.jdbc.converter.JdbcColumnDefaultValueConverter;
import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;
import org.apache.gravitino.rel.expressions.Expression;
Expand All @@ -35,6 +37,8 @@

public class OceanBaseColumnDefaultValueConverter extends JdbcColumnDefaultValueConverter {

private static final Pattern CURRENT_TIMESTAMP = Pattern.compile("^CURRENT_TIMESTAMP(\\(\\d+\\))?$");

@Override
public Expression toGravitino(
JdbcTypeConverter.JdbcTypeBean type,
Expand All @@ -50,7 +54,7 @@ public Expression toGravitino(
}

if (isExpression) {
if (columnDefaultValue.equals(CURRENT_TIMESTAMP)) {
if (CURRENT_TIMESTAMP.matcher(columnDefaultValue).matches()) {
return DEFAULT_VALUE_OF_CURRENT_TIMESTAMP;
}
// The parsing of OceanBase expressions is complex, so we are not currently undertaking the
Expand Down Expand Up @@ -93,7 +97,7 @@ public Expression toGravitino(
return Literals.timeLiteral(LocalTime.parse(columnDefaultValue, DATE_TIME_FORMATTER));
case JdbcTypeConverter.TIMESTAMP:
case OceanBaseTypeConverter.DATETIME:
return CURRENT_TIMESTAMP.equals(columnDefaultValue)
return CURRENT_TIMESTAMP.matcher(columnDefaultValue).matches()
? DEFAULT_VALUE_OF_CURRENT_TIMESTAMP
: Literals.timestampLiteral(
LocalDateTime.parse(columnDefaultValue, DATE_TIME_FORMATTER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ void testColumnDefaultValueConverter() {
+ " date_col_5 date DEFAULT '2024-04-01',\n"
+ " timestamp_col_1 timestamp default '2012-12-31 11:30:45',\n"
+ " timestamp_col_2 timestamp default 19830905,\n"
+ " timestamp_col_3 timestamp(6) default CURRENT_TIMESTAMP(6),\n"
+ " decimal_6_2_col_1 decimal(6, 2) default 1.2,\n"
+ " bit_col_1 bit default b'1'\n"
+ ");\n";
Expand Down Expand Up @@ -511,6 +512,7 @@ void testColumnDefaultValueConverter() {
break;
case "datetime_col_1":
case "datetime_col_2":
case "timestamp_col_3":
Assertions.assertEquals(DEFAULT_VALUE_OF_CURRENT_TIMESTAMP, column.defaultValue());
break;
case "datetime_col_3":
Expand Down

0 comments on commit 3c4b88f

Please sign in to comment.