use of com.dtstack.taier.common.enums.TempJobType in project Taier by DTStack.
the class BatchHadoopSelectSqlService method buildSql.
/**
* 解析sql
* @param parseResult
* @param tenantId
* @param userId
* @param database
* @param isCreateAs
* @param taskId
* @return
*/
public BuildSqlVO buildSql(ParseResult parseResult, Long tenantId, Long userId, String database, Boolean isCreateAs, Long taskId) {
BatchTask batchTask = batchTaskService.getBatchTaskById(taskId);
String originSql = parseResult.getStandardSql();
// 生成临时表名
String tempTable = TEMP_TABLE_PREFIX + System.nanoTime();
if (StringUtils.isEmpty(originSql)) {
return null;
}
String parsedColumns = "";
int isSelectSql;
Matcher witchMatcher = WITH_SQL_PATTERN.matcher(originSql);
String sql = null;
if (SqlType.CREATE.equals(parseResult.getSqlType())) {
isSelectSql = TempJobType.CREATE.getType();
sql = buildCustomFunctionAndDbSql(originSql, tenantId, database, true, batchTask.getTaskType());
} else if (isCreateAs) {
isSelectSql = TempJobType.CREATE_AS.getType();
sql = buildCustomFunctionAndDbSql(originSql, tenantId, database, true, batchTask.getTaskType());
} else if (SqlType.INSERT.equals(parseResult.getSqlType()) || SqlType.INSERT_OVERWRITE.equals(parseResult.getSqlType())) {
isSelectSql = TempJobType.INSERT.getType();
sql = buildCustomFunctionAndDbSql(originSql, tenantId, database, true, batchTask.getTaskType());
} else if (witchMatcher.find()) {
TempJobType jobType = getTempJobType(witchMatcher.group("option"));
isSelectSql = jobType.getType();
sql = formatSql(jobType, database, tempTable, originSql);
} else {
isSelectSql = TempJobType.SELECT.getType();
sql = buildSelectSqlCustomFunction(originSql, tenantId, database, tempTable, batchTask.getTaskType());
}
// 设置需要环境参数
String taskParam = batchTask.getTaskParams();
BuildSqlVO buildSqlVO = new BuildSqlVO();
buildSqlVO.setSql(sql);
buildSqlVO.setTaskParam(taskParam);
buildSqlVO.setIsSelectSql(isSelectSql);
buildSqlVO.setOriginSql(originSql);
buildSqlVO.setParsedColumns(parsedColumns);
buildSqlVO.setTenantId(tenantId);
buildSqlVO.setTempTable(tempTable);
buildSqlVO.setUserId(userId);
return buildSqlVO;
}
Aggregations