[fix](jdbc catalog )fix jdbc catalog current_timestamp default (#25016)

This problem is caused when you read table data from Mariadb where the datatime type default value is set to current_timestamp().
This commit is contained in:
Petrichor
2023-10-07 01:43:03 -05:00
committed by GitHub
parent 0f6ea41220
commit 47694c5b36

View File

@ -176,12 +176,17 @@ public class JdbcMySQLClient extends JdbcClient {
List<Column> dorisTableSchema = Lists.newArrayListWithCapacity(jdbcTableSchema.size());
for (JdbcFieldSchema field : jdbcTableSchema) {
DefaultValueExprDef defaultValueExprDef = null;
if (field.getDefaultValue() != null
&& field.getDefaultValue().toLowerCase().startsWith("current_timestamp")) {
long precision = field.getDefaultValue().toLowerCase().contains("(")
? Long.parseLong(field.getDefaultValue().toLowerCase()
.split("\\(")[1].split("\\)")[0]) : 0;
defaultValueExprDef = new DefaultValueExprDef("now", precision);
if (field.getDefaultValue() != null) {
String colDefaultValue = field.getDefaultValue().toLowerCase();
// current_timestamp()
if (colDefaultValue.startsWith("current_timestamp")) {
long precision = 0;
if (colDefaultValue.contains("(")) {
String substring = colDefaultValue.substring(18, colDefaultValue.length() - 1).trim();
precision = substring.isEmpty() ? 0 : Long.parseLong(substring);
}
defaultValueExprDef = new DefaultValueExprDef("now", precision);
}
}
dorisTableSchema.add(new Column(field.getColumnName(),
jdbcTypeToDoris(field), field.isKey(), null,