From 13233f52efa9234b0b9f53003f3fddeea0b86e9f Mon Sep 17 00:00:00 2001 From: chenl Date: Wed, 7 Jul 2021 17:34:30 +0800 Subject: [PATCH] fix: format sql with different data type with different utility functions. avoid throwing exceptions --- server/src/main/java/edp/core/utils/SqlUtils.java | 13 +++++++++++-- .../java/edp/davinci/service/excel/SheetWorker.java | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/edp/core/utils/SqlUtils.java b/server/src/main/java/edp/core/utils/SqlUtils.java index 294cbf3ee..f6867c934 100644 --- a/server/src/main/java/edp/core/utils/SqlUtils.java +++ b/server/src/main/java/edp/core/utils/SqlUtils.java @@ -1079,9 +1079,18 @@ public String getJdbcUrl() { return this.jdbcSourceInfo.getJdbcUrl(); } - public static String formatSql(String sql) { + public String formatSql(String sql) { try { - return SQLUtils.formatMySql(sql); + switch (dataTypeEnum) { + case ORACLE: + return SQLUtils.formatOracle(sql); + case MYSQL: + return SQLUtils.formatMySql(sql); + case HIVE2: + return SQLUtils.formatHive(sql); + default: + return sql; + } } catch (Exception e) { // ignore } diff --git a/server/src/main/java/edp/davinci/service/excel/SheetWorker.java b/server/src/main/java/edp/davinci/service/excel/SheetWorker.java index d57ad4f5d..a3ac03c56 100644 --- a/server/src/main/java/edp/davinci/service/excel/SheetWorker.java +++ b/server/src/main/java/edp/davinci/service/excel/SheetWorker.java @@ -89,7 +89,7 @@ public T call() { Set queryFromsAndJoins = SqlUtils.getQueryFromsAndJoins(sql); if (log) { logger.info("Task({}) sheet worker(name:{}, sheetNo:{}, sheetName:{}) query start sql:{}, md5:{}", - context.getTaskKey(), context.getName(), context.getSheetNo(), context.getSheet().getSheetName(), SqlUtils.formatSql(sql), md5); + context.getTaskKey(), context.getName(), context.getSheetNo(), context.getSheet().getSheetName(), utils.formatSql(sql), md5); } final AtomicInteger count = new AtomicInteger(0);