Search in sources :

Example 1 with DataSourceType

use of com.dtstack.taier.common.enums.DataSourceType in project Taier by DTStack.

the class BatchSparkHiveSqlExeService method executeSql.

/**
 * 执行sql
 *
 * @param executeContent
 * @param scheduleJobType
 * @return
 */
protected ExecuteResultVO executeSql(ExecuteContent executeContent, EScheduleJobType scheduleJobType) {
    // 判断血缘解析结果,防止空指针
    if (null == executeContent.getParseResult()) {
        throw new RdosDefineException("SQL解析异常,结果为空");
    }
    Long tenantId = executeContent.getTenantId();
    Long userId = executeContent.getUserId();
    Long taskId = executeContent.getTaskId();
    String preJobId = executeContent.getPreJobId();
    String currDb = executeContent.getParseResult().getCurrentDb();
    ParseResult parseResult = executeContent.getParseResult();
    boolean useSelfFunction = batchFunctionService.validContainSelfFunction(executeContent.getSql(), tenantId, null, scheduleJobType.getType());
    ExecuteResultVO<List<Object>> result = new ExecuteResultVO<>();
    if (Objects.nonNull(parseResult) && Objects.nonNull(parseResult.getStandardSql()) && isSimpleQuery(parseResult.getStandardSql()) && !useSelfFunction) {
        result = simpleQuery(tenantId, parseResult, currDb, userId, scheduleJobType);
        if (!result.getContinue()) {
            return result;
        }
    }
    DataSourceType dataSourceType = scheduleJobType == EScheduleJobType.SPARK_SQL ? DataSourceType.SPARKTHRIFT2_1 : null;
    if (SqlType.CREATE_AS.equals(parseResult.getSqlType())) {
        String jobId = batchHadoopSelectSqlService.runSqlByTask(tenantId, parseResult, userId, currDb.toLowerCase(), true, taskId, scheduleJobType.getType(), preJobId);
        result.setJobId(jobId);
        result.setContinue(false);
        return result;
    } else if (SqlType.INSERT.equals(parseResult.getSqlType()) || SqlType.INSERT_OVERWRITE.equals(parseResult.getSqlType()) || SqlType.QUERY.equals(parseResult.getSqlType()) || useSelfFunction) {
        String jobId = batchHadoopSelectSqlService.runSqlByTask(tenantId, parseResult, userId, currDb.toLowerCase(), taskId, scheduleJobType.getType(), preJobId);
        result.setJobId(jobId);
    } else {
        if (!executeContent.isExecuteSqlLater()) {
            TenantComponent tenantEngine = developTenantComponentService.getByTenantAndEngineType(executeContent.getTenantId(), executeContent.getTaskType());
            Preconditions.checkNotNull(tenantEngine, "引擎不能为空");
            if (SqlType.CREATE.equals(parseResult.getSqlType()) || SqlType.CREATE_LIKE.equals(parseResult.getSqlType())) {
                executeCreateTableSql(parseResult, tenantId, tenantEngine.getComponentIdentity().toLowerCase(), scheduleJobType);
            } else {
                this.exeSqlDirect(executeContent, tenantId, parseResult, result, tenantEngine, dataSourceType);
            }
        }
    }
    result.setContinue(true);
    return result;
}
Also used : ParseResult(com.dtstack.taier.develop.sql.ParseResult) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) DataSourceType(com.dtstack.taier.common.enums.DataSourceType) ExecuteResultVO(com.dtstack.taier.develop.dto.devlop.ExecuteResultVO) List(java.util.List) TenantComponent(com.dtstack.taier.dao.domain.TenantComponent)

Aggregations

DataSourceType (com.dtstack.taier.common.enums.DataSourceType)1 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)1 TenantComponent (com.dtstack.taier.dao.domain.TenantComponent)1 ExecuteResultVO (com.dtstack.taier.develop.dto.devlop.ExecuteResultVO)1 ParseResult (com.dtstack.taier.develop.sql.ParseResult)1 List (java.util.List)1