forked from github/dataease
Merge pull request #248 from dataease/pr@dev@errorlog
feat: 适配oracle 11g
This commit is contained in:
commit
da17d8f19c
@ -83,16 +83,32 @@ public class OracleQueryProvider extends QueryProvider {
|
||||
|
||||
@Override
|
||||
public String createQueryCountSQLAsTmp(String sql) {
|
||||
return createQueryCountSQL(" (" + sqlFix(sql) + ") AS tmp ");
|
||||
return createQueryCountSQL(" (" + sqlFix(sql) + ") DE_TMP ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createSQLPreview(String sql, String orderBy) {
|
||||
return "SELECT * FROM (" + sqlFix(sql) + ") tmp " + " WHERE rownum <= 1000";
|
||||
return "SELECT * FROM (" + sqlFix(sql) + ") DE_TMP " + " WHERE rownum <= 1000";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createQuerySQL(String table, List<DatasetTableField> fields) {
|
||||
SQLObj tableObj = SQLObj.builder()
|
||||
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(OracleConstants.KEYWORD_TABLE, table))
|
||||
.tableAlias(String.format(OracleConstants.ALIAS_FIX, String.format(TABLE_ALIAS_PREFIX, 0)))
|
||||
.build();
|
||||
List<SQLObj> xFields = xFields(table, fields);
|
||||
|
||||
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
|
||||
ST st_sql = stg.getInstanceOf("querySql");
|
||||
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
|
||||
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);
|
||||
return st_sql.render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<SQLObj> xFields(String table, List<DatasetTableField> fields){
|
||||
SQLObj tableObj = SQLObj.builder()
|
||||
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(OracleConstants.KEYWORD_TABLE, table))
|
||||
.tableAlias(String.format(OracleConstants.ALIAS_FIX, String.format(TABLE_ALIAS_PREFIX, 0)))
|
||||
@ -137,17 +153,11 @@ public class OracleQueryProvider extends QueryProvider {
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
|
||||
ST st_sql = stg.getInstanceOf("querySql");
|
||||
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
|
||||
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);
|
||||
return st_sql.render();
|
||||
return xFields;
|
||||
}
|
||||
|
||||
private String sqlColumn(List<DatasetTableField> fields) {
|
||||
String[] array = fields.stream().map(f -> {
|
||||
return f.getDataeaseName();
|
||||
private String sqlColumn(List<SQLObj> xFields) {
|
||||
String[] array = xFields.stream().map(f -> {
|
||||
return f.getFieldAlias();
|
||||
}).toArray(String[]::new);
|
||||
return StringUtils.join(array, ",");
|
||||
}
|
||||
@ -159,24 +169,27 @@ public class OracleQueryProvider extends QueryProvider {
|
||||
|
||||
@Override
|
||||
public String createQuerySQLWithPage(String table, List<DatasetTableField> fields, Integer page, Integer pageSize, Integer realSize) {
|
||||
return MessageFormat.format("SELECT {0} FROM ( SELECT tmp.*, rownum r FROM ( {1} ) tmp WHERE rownum <= {2} ) tmp2 WHERE r > {3} ",
|
||||
sqlColumn(fields), createQuerySQL(table, fields), Integer.valueOf(page * realSize).toString(), Integer.valueOf((page - 1) * pageSize).toString());
|
||||
List<SQLObj> xFields = xFields(table, fields);
|
||||
|
||||
return MessageFormat.format("SELECT {0} FROM ( SELECT DE_TMP.*, rownum r FROM ( {1} ) DE_TMP WHERE rownum <= {2} ) WHERE r > {3} ",
|
||||
sqlColumn(xFields), createQuerySQL(table, fields), Integer.valueOf(page * realSize).toString(), Integer.valueOf((page - 1) * pageSize).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createQueryTableWithLimit(String table, List<DatasetTableField> fields, Integer limit) {
|
||||
return createQuerySQL(table, fields) + " WHERE rownum <= " + limit;
|
||||
return String.format("SELECT %s.* from %s WHERE rownum <= %s ", table, table, limit.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createQuerySqlWithLimit(String sql, List<DatasetTableField> fields, Integer limit) {
|
||||
return createQuerySQLAsTmp(sql, fields) + " WHERE rownum <= " + limit;
|
||||
return String.format("SELECT * from %s WHERE rownum <= %s ", "(" + sqlFix(sql) + ")", limit.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createQuerySQLAsTmpWithPage(String sql, List<DatasetTableField> fields, Integer page, Integer pageSize, Integer realSize) {
|
||||
return MessageFormat.format("SELECT {0} FROM ( SELECT tmp.*, rownum r FROM ( {1} ) tmp WHERE rownum <= {2} ) tmp2 WHERE r > {3} ",
|
||||
sqlColumn(fields), createQuerySQLAsTmp(sql, fields), Integer.valueOf(page * realSize).toString(), Integer.valueOf((page - 1) * pageSize).toString());
|
||||
List<SQLObj> xFields = xFields("(" + sqlFix(sql) + ")", fields);
|
||||
return MessageFormat.format("SELECT {0} FROM ( SELECT DE_TMP.*, rownum r FROM ( {1} ) DE_TMP WHERE rownum <= {2} ) WHERE r > {3} ",
|
||||
sqlColumn(xFields), createQuerySQLAsTmp(sql, fields), Integer.valueOf(page * realSize).toString(), Integer.valueOf((page - 1) * pageSize).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -353,7 +366,7 @@ public class OracleQueryProvider extends QueryProvider {
|
||||
if (sql.lastIndexOf(";") == (sql.length() - 1)) {
|
||||
sql = sql.substring(0, sql.length() - 1);
|
||||
}
|
||||
String tmpSql = "SELECT * FROM (" + sql + ") tmp " + " where rownum <= 0";
|
||||
String tmpSql = "SELECT * FROM (" + sql + ") DE_TMP " + " where rownum <= 0";
|
||||
return tmpSql;
|
||||
}
|
||||
|
||||
@ -361,7 +374,7 @@ public class OracleQueryProvider extends QueryProvider {
|
||||
public String createRawQuerySQL(String table, List<DatasetTableField> fields) {
|
||||
String[] array = fields.stream().map(f -> {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(" ").append(f.getOriginName()).append(" AS ").append(f.getDataeaseName());
|
||||
stringBuilder.append(" ").append(f.getOriginName());
|
||||
return stringBuilder.toString();
|
||||
}).toArray(String[]::new);
|
||||
return MessageFormat.format("SELECT {0} FROM {1} ORDER BY null", StringUtils.join(array, ","), table);
|
||||
@ -369,7 +382,7 @@ public class OracleQueryProvider extends QueryProvider {
|
||||
|
||||
@Override
|
||||
public String createRawQuerySQLAsTmp(String sql, List<DatasetTableField> fields) {
|
||||
return createRawQuerySQL(" (" + sqlFix(sql) + ") tmp ", fields);
|
||||
return createRawQuerySQL(" (" + sqlFix(sql) + ") DE_TMP ", fields);
|
||||
}
|
||||
|
||||
public String transMysqlFilterTerm(String term) {
|
||||
|
@ -720,7 +720,7 @@ public class ExtractDataService {
|
||||
transMeta.addDatabase(dataMeta);
|
||||
selectSQL = getSelectSQL(extractType, datasetTable, datasource, datasetTableFields, selectSQL);
|
||||
inputStep = inputStep(transMeta, selectSQL);
|
||||
udjcStep = udjc(datasetTableFields, false);
|
||||
udjcStep = udjc(datasetTableFields, DatasourceTypes.mysql);
|
||||
break;
|
||||
case sqlServer:
|
||||
SqlServerConfigration sqlServerConfigration = new Gson().fromJson(datasource.getConfiguration(), SqlServerConfigration.class);
|
||||
@ -728,7 +728,7 @@ public class ExtractDataService {
|
||||
transMeta.addDatabase(dataMeta);
|
||||
selectSQL = getSelectSQL(extractType, datasetTable, datasource, datasetTableFields, selectSQL);
|
||||
inputStep = inputStep(transMeta, selectSQL);
|
||||
udjcStep = udjc(datasetTableFields, false);
|
||||
udjcStep = udjc(datasetTableFields, DatasourceTypes.sqlServer);
|
||||
break;
|
||||
case oracle:
|
||||
OracleConfigration oracleConfigration = new Gson().fromJson(datasource.getConfiguration(), OracleConfigration.class);
|
||||
@ -742,12 +742,12 @@ public class ExtractDataService {
|
||||
|
||||
selectSQL = getSelectSQL(extractType, datasetTable, datasource, datasetTableFields, selectSQL);
|
||||
inputStep = inputStep(transMeta, selectSQL);
|
||||
udjcStep = udjc(datasetTableFields, false);
|
||||
udjcStep = udjc(datasetTableFields, DatasourceTypes.oracle);
|
||||
break;
|
||||
case excel:
|
||||
String filePath = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getData();
|
||||
inputStep = excelInputStep(filePath, datasetTableFields);
|
||||
udjcStep = udjc(datasetTableFields, true);
|
||||
udjcStep = udjc(datasetTableFields, DatasourceTypes.excel);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -878,13 +878,9 @@ public class ExtractDataService {
|
||||
return outputStep;
|
||||
}
|
||||
|
||||
private StepMeta udjc(List<DatasetTableField> datasetTableFields, boolean isExcel) {
|
||||
private StepMeta udjc(List<DatasetTableField> datasetTableFields, DatasourceTypes datasourceType) {
|
||||
String needToChangeColumnType = "";
|
||||
// for (DatasetTableField datasetTableField : datasetTableFields) {
|
||||
// if (datasetTableField.getDeExtractType() != null && datasetTableField.getDeExtractType() == 4) {
|
||||
// needToChangeColumnType = needToChangeColumnType + alterColumnTypeCode.replace("FILED", datasetTableField.getDataeaseName());
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
UserDefinedJavaClassMeta userDefinedJavaClassMeta = new UserDefinedJavaClassMeta();
|
||||
List<UserDefinedJavaClassMeta.FieldInfo> fields = new ArrayList<>();
|
||||
@ -895,10 +891,16 @@ public class ExtractDataService {
|
||||
String tmp_code = code.replace("alterColumnTypeCode", needToChangeColumnType);
|
||||
|
||||
tmp_code = tmp_code.replace("handleWraps", handleWraps);
|
||||
if(isExcel){
|
||||
tmp_code = tmp_code.replace("handleExcelIntColumn", handleExcelIntColumn).replace("Column_Fields", String.join(",", datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList())));;
|
||||
String Column_Fields = "";
|
||||
if(datasourceType.equals(DatasourceTypes.excel) || datasourceType.equals(DatasourceTypes.oracle)){
|
||||
Column_Fields = String.join(",", datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList()));
|
||||
}else {
|
||||
tmp_code = tmp_code.replace("handleExcelIntColumn", "").replace("Column_Fields", String.join(",", datasetTableFields.stream().map(DatasetTableField::getDataeaseName).collect(Collectors.toList())));;
|
||||
Column_Fields = String.join(",", datasetTableFields.stream().map(DatasetTableField::getDataeaseName).collect(Collectors.toList()));
|
||||
}
|
||||
if(datasourceType.equals(DatasourceTypes.excel)){
|
||||
tmp_code = tmp_code.replace("handleExcelIntColumn", handleExcelIntColumn).replace("Column_Fields", Column_Fields);
|
||||
}else {
|
||||
tmp_code = tmp_code.replace("handleExcelIntColumn", "").replace("Column_Fields", Column_Fields);
|
||||
}
|
||||
UserDefinedJavaClassDef userDefinedJavaClassDef = new UserDefinedJavaClassDef(UserDefinedJavaClassDef.ClassType.TRANSFORM_CLASS, "Processor", tmp_code);
|
||||
|
||||
|
@ -12,7 +12,7 @@ SELECT
|
||||
<aggregators:{agg|<if(agg)><agg.fieldName> AS <agg.fieldAlias><endif>}; separator=",\n">
|
||||
<endif>
|
||||
FROM
|
||||
<table.tableName> AS <table.tableAlias>
|
||||
<table.tableName> <table.tableAlias>
|
||||
<if(filters)>
|
||||
WHERE
|
||||
<filters:{filter|<if(filter)><filter.whereField> <filter.whereTermAndValue><endif>}; separator="\nAND ">
|
||||
|
Loading…
Reference in New Issue
Block a user