Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5359] fix(ob-catalog): fix ob catalog default value parse error #5393

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Expand Up @@ -569,6 +570,10 @@ void testColumnDefaultValueConverter() {
Assertions.assertEquals(
Literals.timestampLiteral("1983-09-05T00:00:00"), column.defaultValue());
break;
case "timestamp_col_3":
Assertions.assertEquals(
UnparsedExpression.of("CURRENT_TIMESTAMP(6)"), column.defaultValue());
break;
case "decimal_6_2_col_1":
Assertions.assertEquals(
Literals.decimalLiteral(Decimal.of("1.2", 6, 2)), column.defaultValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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 +36,10 @@

public class OceanBaseColumnDefaultValueConverter extends JdbcColumnDefaultValueConverter {

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

@Override
public Expression toGravitino(
JdbcTypeConverter.JdbcTypeBean type,
Expand All @@ -50,7 +55,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 +98,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
Loading