diff --git a/backend/src/main/java/io/dataease/provider/QueryProvider.java b/backend/src/main/java/io/dataease/provider/QueryProvider.java index 055679307e..0e057c1285 100644 --- a/backend/src/main/java/io/dataease/provider/QueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/QueryProvider.java @@ -41,4 +41,6 @@ public abstract class QueryProvider { public abstract String getSQLSummary(String table, List yAxis, List customFilter, List extFilterRequestList); public abstract String getSQLSummaryAsTmp(String sql, List yAxis, List customFilter, List extFilterRequestList); + + public abstract String wrapSql(String sql); } diff --git a/backend/src/main/java/io/dataease/provider/doris/DorisQueryProvider.java b/backend/src/main/java/io/dataease/provider/doris/DorisQueryProvider.java index a32742045b..d9faed7c4d 100644 --- a/backend/src/main/java/io/dataease/provider/doris/DorisQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/doris/DorisQueryProvider.java @@ -338,6 +338,16 @@ public class DorisQueryProvider extends QueryProvider { return getSQLSummary(" (" + sql + ") AS tmp ", yAxis, customFilter, extFilterRequestList); } + @Override + public String wrapSql(String sql) { + sql = sql.trim(); + if (sql.lastIndexOf(";") == (sql.length() - 1)) { + sql = sql.substring(0, sql.length() - 1); + } + String tmpSql = "SELECT * FROM (" + sql + ") AS tmp " + " LIMIT 0"; + return tmpSql; + } + public String transMysqlFilterTerm(String term) { switch (term) { case "eq": diff --git a/backend/src/main/java/io/dataease/provider/mysql/MysqlQueryProvider.java b/backend/src/main/java/io/dataease/provider/mysql/MysqlQueryProvider.java index d66fd877a7..00133dade4 100644 --- a/backend/src/main/java/io/dataease/provider/mysql/MysqlQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/mysql/MysqlQueryProvider.java @@ -346,6 +346,16 @@ public class MysqlQueryProvider extends QueryProvider { return getSQLSummary(" (" + sqlFix(sql) + ") AS tmp ", yAxis, customFilter, extFilterRequestList); } + @Override + public String wrapSql(String sql) { + sql = sql.trim(); + if (sql.lastIndexOf(";") == (sql.length() - 1)) { + sql = sql.substring(0, sql.length() - 1); + } + String tmpSql = "SELECT * FROM (" + sql + ") AS tmp " + " LIMIT 0"; + return tmpSql; + } + public String transMysqlFilterTerm(String term) { switch (term) { case "eq": diff --git a/backend/src/main/java/io/dataease/provider/oracle/OracleQueryProvider.java b/backend/src/main/java/io/dataease/provider/oracle/OracleQueryProvider.java index 05c436197a..88c1454cc8 100644 --- a/backend/src/main/java/io/dataease/provider/oracle/OracleQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/oracle/OracleQueryProvider.java @@ -490,6 +490,16 @@ public class OracleQueryProvider extends QueryProvider { return sql; } + @Override + public String wrapSql(String sql) { + sql = sql.trim(); + if (sql.lastIndexOf(";") == (sql.length() - 1)) { + sql = sql.substring(0, sql.length() - 1); + } + String tmpSql = "SELECT * FROM (" + sql + ") tmp " + " where rownum <= 0"; + return tmpSql; + } + private String transDateFormat(String dateStyle, String datePattern) { String split = "-"; if (StringUtils.equalsIgnoreCase(datePattern, "date_sub")) { diff --git a/backend/src/main/java/io/dataease/provider/sqlserver/SqlserverQueryProvider.java b/backend/src/main/java/io/dataease/provider/sqlserver/SqlserverQueryProvider.java index 7ca66ecd0d..0e3d09bd96 100644 --- a/backend/src/main/java/io/dataease/provider/sqlserver/SqlserverQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/sqlserver/SqlserverQueryProvider.java @@ -260,6 +260,16 @@ public class SqlserverQueryProvider extends QueryProvider { return null; } + @Override + public String wrapSql(String sql) { + sql = sql.trim(); + if (sql.lastIndexOf(";") == (sql.length() - 1)) { + sql = sql.substring(0, sql.length() - 1); + } + String tmpSql = "SELECT * FROM (" + sql + ") AS tmp " + " LIMIT 0"; + return tmpSql; + } + public String transMysqlFilterTerm(String term) { switch (term) { case "eq": diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index eb5101dbd0..6ce5e7bb4e 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -721,13 +721,14 @@ public class DataSetTableService { }); List originNameFileds = datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList()); Datasource ds = datasourceMapper.selectByPrimaryKey(datasetTable.getDataSourceId()); + QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType()); DatasourceRequest datasourceRequest = new DatasourceRequest(); datasourceRequest.setDatasource(ds); if (StringUtils.isNotEmpty(datasetTableIncrementalConfig.getIncrementalAdd()) && StringUtils.isNotEmpty(datasetTableIncrementalConfig.getIncrementalAdd().replace(" ", ""))) {// 增量添加 String sql = datasetTableIncrementalConfig.getIncrementalAdd().replace(lastUpdateTime, Long.valueOf(System.currentTimeMillis()).toString()) .replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString()); - datasourceRequest.setQuery(extractDataService.sqlFix(sql)); + datasourceRequest.setQuery(qp.wrapSql(sql)); List sqlFileds = new ArrayList<>(); datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> { sqlFileds.add(filed); @@ -740,7 +741,7 @@ public class DataSetTableService { if (StringUtils.isNotEmpty(datasetTableIncrementalConfig.getIncrementalDelete()) && StringUtils.isNotEmpty(datasetTableIncrementalConfig.getIncrementalDelete().replace(" ", ""))) {// 增量删除 String sql = datasetTableIncrementalConfig.getIncrementalDelete().replace(lastUpdateTime, Long.valueOf(System.currentTimeMillis()).toString()) .replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString()); - datasourceRequest.setQuery(extractDataService.sqlFix(sql)); + datasourceRequest.setQuery(qp.wrapSql(sql)); List sqlFileds = new ArrayList<>(); datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> { sqlFileds.add(filed); diff --git a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java index 711ae34079..0bc19fbdea 100644 --- a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java +++ b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java @@ -580,10 +580,11 @@ public class ExtractDataService { } private String fetchSqlField(String sql, Datasource ds) throws Exception { + QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType()); DatasourceRequest datasourceRequest = new DatasourceRequest(); datasourceRequest.setDatasource(ds); - datasourceRequest.setQuery(sqlFix(sql)); + datasourceRequest.setQuery(qp.wrapSql(sql)); List dorisFileds = new ArrayList<>(); datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed ->{ dorisFileds.add(DorisTableUtils.columnName(filed)); @@ -591,16 +592,6 @@ public class ExtractDataService { return String.join(",", dorisFileds); } - public String sqlFix(String sql) { - sql = sql.trim(); - if (sql.lastIndexOf(";") == (sql.length() - 1)) { - sql = sql.substring(0, sql.length() - 1); - } - String tmpSql = "SELECT * FROM (" + sql + ") AS tmp " + " LIMIT 0"; - return tmpSql; - } - - private void generateTransFile(String extractType, DatasetTable datasetTable, Datasource datasource, List datasetTableFields, String selectSQL) throws Exception { TransMeta transMeta = new TransMeta(); String outFile = null;