Skip to content

Commit

Permalink
[fix](jdbc catalog )fix jdbc catalog current_timestamp default (#25016)
Browse files Browse the repository at this point in the history
This problem is caused when you read table data from Mariadb where the datatime type default value is set to current_timestamp().
  • Loading branch information
vinlee19 authored and xiaokang committed Oct 7, 2023
1 parent 7985a03 commit 9642923
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,17 @@ public List<Column> getColumnsFromJdbc(String dbName, String tableName) {
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,
Expand Down

0 comments on commit 9642923

Please sign in to comment.