From 7c412c6136cac1ad971fa1b3e3c6326c96ba14e3 Mon Sep 17 00:00:00 2001 From: vran Date: Fri, 29 Apr 2022 18:51:42 +0800 Subject: [PATCH] fix: hive sync error (#135) --- .../impl/jdbc/JdbcColumnMetaRepository.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java b/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java index 7ca7661..5754035 100644 --- a/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java +++ b/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java @@ -52,10 +52,7 @@ public class JdbcColumnMetaRepository implements ColumnMetaRepository { if (isNullable.trim().equals("")) { isNullable = "UNKNOWN"; } - String isAutoIncrement = columnsResult.getString("IS_AUTOINCREMENT"); - if (isAutoIncrement.trim().equals("")) { - isAutoIncrement = "UNKNOWN"; - } + if (defaultValue != null && defaultValue.trim().equals("")) { defaultValue = "'" + defaultValue + "'"; } @@ -76,7 +73,7 @@ public class JdbcColumnMetaRepository implements ColumnMetaRepository { .size(columnSize) .decimalDigits(decimalDigits) .nullable(isNullable) - .autoIncrement(isAutoIncrement) + .autoIncrement(retrieveAutoIncrement(columnsResult)) .comment(columnComment) .defaultValue(defaultValue) .isPrimaryKey(primaryKeyColumns.contains(columnName)) @@ -90,6 +87,20 @@ public class JdbcColumnMetaRepository implements ColumnMetaRepository { return columnDocs; } + private String retrieveAutoIncrement(ResultSet columnsResult) { + String isAutoIncrement = null; + try { + isAutoIncrement = columnsResult.getString("IS_AUTOINCREMENT"); + if (isAutoIncrement.trim().equals("")) { + isAutoIncrement = "UNKNOWN"; + } + return isAutoIncrement; + } catch (SQLException e) { + log.warn("warn: ignore auto increment, error: " + e.getMessage()); + return "UNKNOWN"; + } + } + private List selectPrimaryKeyColumns(DatabaseMetaData meta, TableCondition tableCondition) throws SQLException { ResultSet result = meta.getPrimaryKeys(tableCondition.getDatabaseName(),