Merge pull request #248 from dataease/pr@dev@errorlog

feat: 适配oracle 11g
This commit is contained in:
taojinlong 2021-07-15 18:33:51 +08:00 committed by GitHub
commit da17d8f19c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 35 deletions

View File

@ -83,16 +83,32 @@ public class OracleQueryProvider extends QueryProvider {
@Override @Override
public String createQueryCountSQLAsTmp(String sql) { public String createQueryCountSQLAsTmp(String sql) {
return createQueryCountSQL(" (" + sqlFix(sql) + ") AS tmp "); return createQueryCountSQL(" (" + sqlFix(sql) + ") DE_TMP ");
} }
@Override @Override
public String createSQLPreview(String sql, String orderBy) { 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 @Override
public String createQuerySQL(String table, List<DatasetTableField> fields) { 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() SQLObj tableObj = SQLObj.builder()
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(OracleConstants.KEYWORD_TABLE, table)) .tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(OracleConstants.KEYWORD_TABLE, table))
.tableAlias(String.format(OracleConstants.ALIAS_FIX, String.format(TABLE_ALIAS_PREFIX, 0))) .tableAlias(String.format(OracleConstants.ALIAS_FIX, String.format(TABLE_ALIAS_PREFIX, 0)))
@ -137,17 +153,11 @@ public class OracleQueryProvider extends QueryProvider {
.build()); .build());
} }
} }
return xFields;
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 String sqlColumn(List<SQLObj> xFields) {
private String sqlColumn(List<DatasetTableField> fields) { String[] array = xFields.stream().map(f -> {
String[] array = fields.stream().map(f -> { return f.getFieldAlias();
return f.getDataeaseName();
}).toArray(String[]::new); }).toArray(String[]::new);
return StringUtils.join(array, ","); return StringUtils.join(array, ",");
} }
@ -159,24 +169,27 @@ public class OracleQueryProvider extends QueryProvider {
@Override @Override
public String createQuerySQLWithPage(String table, List<DatasetTableField> fields, Integer page, Integer pageSize, Integer realSize) { 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} ", List<SQLObj> xFields = xFields(table, fields);
sqlColumn(fields), createQuerySQL(table, fields), Integer.valueOf(page * realSize).toString(), Integer.valueOf((page - 1) * pageSize).toString());
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 @Override
public String createQueryTableWithLimit(String table, List<DatasetTableField> fields, Integer limit) { 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 @Override
public String createQuerySqlWithLimit(String sql, List<DatasetTableField> fields, Integer limit) { 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 @Override
public String createQuerySQLAsTmpWithPage(String sql, List<DatasetTableField> fields, Integer page, Integer pageSize, Integer realSize) { 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} ", List<SQLObj> xFields = xFields("(" + sqlFix(sql) + ")", fields);
sqlColumn(fields), createQuerySQLAsTmp(sql, fields), Integer.valueOf(page * realSize).toString(), Integer.valueOf((page - 1) * pageSize).toString()); 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 @Override
@ -353,7 +366,7 @@ public class OracleQueryProvider extends QueryProvider {
if (sql.lastIndexOf(";") == (sql.length() - 1)) { if (sql.lastIndexOf(";") == (sql.length() - 1)) {
sql = sql.substring(0, 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; return tmpSql;
} }
@ -361,7 +374,7 @@ public class OracleQueryProvider extends QueryProvider {
public String createRawQuerySQL(String table, List<DatasetTableField> fields) { public String createRawQuerySQL(String table, List<DatasetTableField> fields) {
String[] array = fields.stream().map(f -> { String[] array = fields.stream().map(f -> {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(" ").append(f.getOriginName()).append(" AS ").append(f.getDataeaseName()); stringBuilder.append(" ").append(f.getOriginName());
return stringBuilder.toString(); return stringBuilder.toString();
}).toArray(String[]::new); }).toArray(String[]::new);
return MessageFormat.format("SELECT {0} FROM {1} ORDER BY null", StringUtils.join(array, ","), table); return MessageFormat.format("SELECT {0} FROM {1} ORDER BY null", StringUtils.join(array, ","), table);
@ -369,7 +382,7 @@ public class OracleQueryProvider extends QueryProvider {
@Override @Override
public String createRawQuerySQLAsTmp(String sql, List<DatasetTableField> fields) { 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) { public String transMysqlFilterTerm(String term) {

View File

@ -720,7 +720,7 @@ public class ExtractDataService {
transMeta.addDatabase(dataMeta); transMeta.addDatabase(dataMeta);
selectSQL = getSelectSQL(extractType, datasetTable, datasource, datasetTableFields, selectSQL); selectSQL = getSelectSQL(extractType, datasetTable, datasource, datasetTableFields, selectSQL);
inputStep = inputStep(transMeta, selectSQL); inputStep = inputStep(transMeta, selectSQL);
udjcStep = udjc(datasetTableFields, false); udjcStep = udjc(datasetTableFields, DatasourceTypes.mysql);
break; break;
case sqlServer: case sqlServer:
SqlServerConfigration sqlServerConfigration = new Gson().fromJson(datasource.getConfiguration(), SqlServerConfigration.class); SqlServerConfigration sqlServerConfigration = new Gson().fromJson(datasource.getConfiguration(), SqlServerConfigration.class);
@ -728,7 +728,7 @@ public class ExtractDataService {
transMeta.addDatabase(dataMeta); transMeta.addDatabase(dataMeta);
selectSQL = getSelectSQL(extractType, datasetTable, datasource, datasetTableFields, selectSQL); selectSQL = getSelectSQL(extractType, datasetTable, datasource, datasetTableFields, selectSQL);
inputStep = inputStep(transMeta, selectSQL); inputStep = inputStep(transMeta, selectSQL);
udjcStep = udjc(datasetTableFields, false); udjcStep = udjc(datasetTableFields, DatasourceTypes.sqlServer);
break; break;
case oracle: case oracle:
OracleConfigration oracleConfigration = new Gson().fromJson(datasource.getConfiguration(), OracleConfigration.class); OracleConfigration oracleConfigration = new Gson().fromJson(datasource.getConfiguration(), OracleConfigration.class);
@ -742,12 +742,12 @@ public class ExtractDataService {
selectSQL = getSelectSQL(extractType, datasetTable, datasource, datasetTableFields, selectSQL); selectSQL = getSelectSQL(extractType, datasetTable, datasource, datasetTableFields, selectSQL);
inputStep = inputStep(transMeta, selectSQL); inputStep = inputStep(transMeta, selectSQL);
udjcStep = udjc(datasetTableFields, false); udjcStep = udjc(datasetTableFields, DatasourceTypes.oracle);
break; break;
case excel: case excel:
String filePath = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getData(); String filePath = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getData();
inputStep = excelInputStep(filePath, datasetTableFields); inputStep = excelInputStep(filePath, datasetTableFields);
udjcStep = udjc(datasetTableFields, true); udjcStep = udjc(datasetTableFields, DatasourceTypes.excel);
default: default:
break; break;
} }
@ -878,13 +878,9 @@ public class ExtractDataService {
return outputStep; return outputStep;
} }
private StepMeta udjc(List<DatasetTableField> datasetTableFields, boolean isExcel) { private StepMeta udjc(List<DatasetTableField> datasetTableFields, DatasourceTypes datasourceType) {
String needToChangeColumnType = ""; String needToChangeColumnType = "";
// for (DatasetTableField datasetTableField : datasetTableFields) {
// if (datasetTableField.getDeExtractType() != null && datasetTableField.getDeExtractType() == 4) {
// needToChangeColumnType = needToChangeColumnType + alterColumnTypeCode.replace("FILED", datasetTableField.getDataeaseName());
// }
// }
UserDefinedJavaClassMeta userDefinedJavaClassMeta = new UserDefinedJavaClassMeta(); UserDefinedJavaClassMeta userDefinedJavaClassMeta = new UserDefinedJavaClassMeta();
List<UserDefinedJavaClassMeta.FieldInfo> fields = new ArrayList<>(); List<UserDefinedJavaClassMeta.FieldInfo> fields = new ArrayList<>();
@ -895,10 +891,16 @@ public class ExtractDataService {
String tmp_code = code.replace("alterColumnTypeCode", needToChangeColumnType); String tmp_code = code.replace("alterColumnTypeCode", needToChangeColumnType);
tmp_code = tmp_code.replace("handleWraps", handleWraps); tmp_code = tmp_code.replace("handleWraps", handleWraps);
if(isExcel){ String Column_Fields = "";
tmp_code = tmp_code.replace("handleExcelIntColumn", handleExcelIntColumn).replace("Column_Fields", String.join(",", datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList())));; if(datasourceType.equals(DatasourceTypes.excel) || datasourceType.equals(DatasourceTypes.oracle)){
Column_Fields = String.join(",", datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList()));
}else { }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); UserDefinedJavaClassDef userDefinedJavaClassDef = new UserDefinedJavaClassDef(UserDefinedJavaClassDef.ClassType.TRANSFORM_CLASS, "Processor", tmp_code);

View File

@ -12,7 +12,7 @@ SELECT
<aggregators:{agg|<if(agg)><agg.fieldName> AS <agg.fieldAlias><endif>}; separator=",\n"> <aggregators:{agg|<if(agg)><agg.fieldName> AS <agg.fieldAlias><endif>}; separator=",\n">
<endif> <endif>
FROM FROM
<table.tableName> AS <table.tableAlias> <table.tableName> <table.tableAlias>
<if(filters)> <if(filters)>
WHERE WHERE
<filters:{filter|<if(filter)><filter.whereField> <filter.whereTermAndValue><endif>}; separator="\nAND "> <filters:{filter|<if(filter)><filter.whereField> <filter.whereTermAndValue><endif>}; separator="\nAND ">