Search in sources :

Example 6 with DtCenterDefException

use of com.dtstack.taier.common.exception.DtCenterDefException in project Taier by DTStack.

the class BatchSelectSqlService method beforeGetResult.

/**
 * sql查询前置处理
 *
 * @param jobId
 * @param taskId
 * @param tenantId
 * @param type
 * @param sqlId
 * @return
 */
private ExecuteSelectSqlData beforeGetResult(String jobId, Long taskId, Long tenantId, Integer type, String sqlId) {
    BatchSelectSql batchHiveSelectSql = developHiveSelectSqlDao.getByJobId(StringUtils.isNotEmpty(sqlId) ? sqlId : jobId, tenantId, null);
    Preconditions.checkNotNull(batchHiveSelectSql, "不存在该临时查询");
    if (StringUtils.isNotEmpty(sqlId)) {
        batchHiveSelectSql.setFatherJobId(jobId);
        batchHiveSelectSql.setJobId(sqlId);
    }
    IBatchSelectSqlService selectSqlService = multiEngineServiceFactory.getBatchSelectSqlService(batchHiveSelectSql.getTaskType());
    Preconditions.checkNotNull(selectSqlService, String.format("不支持此任务类型 %d", batchHiveSelectSql.getTaskType()));
    BatchTask batchTask = batchTaskService.getOneWithError(taskId);
    ;
    Integer taskType = null;
    if (Objects.nonNull(batchTask)) {
        taskType = batchTask.getTaskType();
    }
    if (Objects.isNull(taskType)) {
        throw new DtCenterDefException("任务类型为空");
    }
    return new ExecuteSelectSqlData(batchHiveSelectSql, batchTask, taskType, selectSqlService);
}
Also used : IBatchSelectSqlService(com.dtstack.taier.develop.service.develop.IBatchSelectSqlService) ExecuteSelectSqlData(com.dtstack.taier.develop.dto.devlop.ExecuteSelectSqlData) BatchTask(com.dtstack.taier.dao.domain.BatchTask) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) BatchSelectSql(com.dtstack.taier.dao.domain.BatchSelectSql)

Example 7 with DtCenterDefException

use of com.dtstack.taier.common.exception.DtCenterDefException in project Taier by DTStack.

the class RDBWriter method checkFormat.

@Override
public void checkFormat(JSONObject data) {
    String name = data.getString("name");
    data = data.getJSONObject("parameter");
    if (name.equals(PluginName.Clichhouse_W)) {
        // 1、clickhouse不支持修改删除,写入模式只能为insert into
        String writeMode = data.getString("writeMode");
        if (!"insert".equalsIgnoreCase(writeMode)) {
            throw new DtCenterDefException("clickhouse 写入模式只能为insert into");
        }
    }
    if (data.get("column") == null) {
        throw new RdosDefineException("column 不能为空");
    }
    if (data.get("column") == null) {
        throw new RdosDefineException("需要匹配映射");
    }
    if (!(data.get("column") instanceof JSONArray)) {
        throw new RdosDefineException("column 必须为数组格式");
    }
    JSONArray column = data.getJSONArray("column");
    if (column.isEmpty()) {
        throw new RdosDefineException("需要匹配映射");
    }
    if (data.get("connection") == null) {
        throw new RdosDefineException("connection 不能为空");
    }
    if (!(data.get("connection") instanceof JSONArray)) {
        throw new RdosDefineException("connection 必须为数组格式");
    }
    JSONArray connections = data.getJSONArray("connection");
    if (connections.isEmpty()) {
        throw new RdosDefineException("connection 不能为空");
    }
    if (connections.size() > 1) {
        throw new RdosDefineException("暂不支持多个数据源写入");
    }
    if (StringUtils.isEmpty(connections.getJSONObject(0).getString("jdbcUrl"))) {
        throw new RdosDefineException("jdbcUrl 不能为空");
    }
    if (connections.getJSONObject(0).get("table") == null) {
        throw new RdosDefineException("table 不能为空");
    }
    if (!(connections.getJSONObject(0).get("table") instanceof JSONArray)) {
        throw new RdosDefineException("table 必须为数组格式");
    }
    JSONArray tables = connections.getJSONObject(0).getJSONArray("table");
    if (tables.isEmpty()) {
        throw new RdosDefineException("table 不能为空");
    }
    if (tables.size() > 1) {
        throw new RdosDefineException("暂不支持多张表写入");
    }
    for (Object table : tables) {
        if (!(table instanceof String)) {
            throw new RdosDefineException("table 必须为字符串数组格式");
        }
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) JSONArray(com.alibaba.fastjson.JSONArray) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) JSONObject(com.alibaba.fastjson.JSONObject)

Example 8 with DtCenterDefException

use of com.dtstack.taier.common.exception.DtCenterDefException in project Taier by DTStack.

the class SyncJobCheck method checkJobData.

/**
 * 检测 job 参数的合理性
 * @param job
 */
private static void checkJobData(JSONObject job) {
    if (JSONPath.eval(job, JobElementPath.SPEED) != null) {
        long speed = Long.parseLong(String.valueOf(JSONPath.eval(job, JobElementPath.SPEED)));
        // -1是不限制速度
        if (speed < -1) {
            throw new RdosDefineException("速率 bytes 必须大于 0");
        }
    }
    if (JSONPath.eval(job, JobElementPath.CHANNEL) != null) {
        long channel = Long.parseLong(String.valueOf(JSONPath.eval(job, JobElementPath.CHANNEL)));
        if (channel <= 0) {
            throw new RdosDefineException("并发度 channel 必须大于 0");
        }
        String name = (String) JSONPath.eval(job, "$.job.content[0].writer.name");
        if (PluginName.Clichhouse_W.equals(name)) {
            // 2、clickhouse不支持并发写入,当写入clickhouse时,作业并发数只能设置为1
            if (1 != channel) {
                throw new DtCenterDefException("clickhouse 作业并发数只能设置为1");
            }
        }
    }
    if (JSONPath.eval(job, JobElementPath.RECORD) != null) {
        long record = Long.parseLong(String.valueOf(JSONPath.eval(job, JobElementPath.RECORD)));
        if (record < 0) {
            throw new RdosDefineException("错误记录数 record 必须大于等于 0");
        }
    }
    Object percentageObj = JSONPath.eval(job, JobElementPath.PERCENTAGE);
    if (percentageObj != null) {
        Double percentage = NumberUtils.toDouble(percentageObj.toString(), -1);
        if (percentage < 0 || percentage > 100) {
            throw new RdosDefineException("错误比率 percentage 必须介于 0-100");
        }
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) JSONObject(com.alibaba.fastjson.JSONObject)

Example 9 with DtCenterDefException

use of com.dtstack.taier.common.exception.DtCenterDefException in project Taier by DTStack.

the class CreateTableSqlParseUtil method parseTableName.

public static String parseTableName(String originSql) {
    String sql = originSql.replace("\n", "").replace("\r", "");
    if (sql.contains("(")) {
        sql = sql.substring(0, sql.indexOf("("));
    }
    if (!sql.matches(CREATE_REGEX)) {
        throw new DtCenterDefException("Only accept sql like 'create table ....'");
    }
    String tableName = null;
    Matcher matcher = CREATE_PATTERN.matcher(sql);
    if (matcher.find()) {
        tableName = matcher.group("tableName");
    }
    if (tableName == null) {
        throw new DtCenterDefException("Can not parse tableName from sql:" + sql);
    }
    if (tableName.contains(".")) {
        tableName = tableName.split("\\.")[1];
    }
    if (tableName.contains("`") || tableName.contains("'") || tableName.contains("\"")) {
        tableName = tableName.substring(1, tableName.length() - 1);
    }
    return tableName;
}
Also used : Matcher(java.util.regex.Matcher) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException)

Example 10 with DtCenterDefException

use of com.dtstack.taier.common.exception.DtCenterDefException in project Taier by DTStack.

the class HiveSqlBuildService method buildColumnsSql.

private List<String> buildColumnsSql(List<ColumnDTO> columns, boolean isAddCol) {
    List<String> columnsStr = Lists.newArrayList();
    String colName;
    String colType;
    String colDesc;
    String addColumnFormat = "%s %s comment '%s'";
    String alterColumnFormat = "%s %s %s comment '%s'";
    for (ColumnDTO col : columns) {
        if (StringUtils.isEmpty(col.getColumnName()) || StringUtils.isEmpty(col.getColumnType())) {
            throw new DtCenterDefException("column name or type can not be null");
        }
        colName = col.getColumnName();
        colType = col.getColumnType();
        colDesc = col.getComment() == null ? "" : col.getComment();
        if ("DECIMAL".equals(colType)) {
            int precision = col.getPrecision() == null ? 10 : col.getPrecision();
            int scale = col.getScale() == null ? 0 : col.getScale();
            colType += String.format("(%s,%s)", precision, scale);
        }
        if (isAddCol) {
            columnsStr.add(String.format(addColumnFormat, quote(colName), colType, colDesc));
        } else {
            columnsStr.add(String.format(alterColumnFormat, quote(colName), colName, colType, colDesc));
        }
    }
    return columnsStr;
}
Also used : DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException) ColumnDTO(com.dtstack.taier.develop.utils.develop.common.dto.ColumnDTO)

Aggregations

DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)26 IOException (java.io.IOException)11 JSONObject (com.alibaba.fastjson.JSONObject)7 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)7 SftpException (com.jcraft.jsch.SftpException)6 IHdfsFile (com.dtstack.dtcenter.loader.client.IHdfsFile)5 HdfsSourceDTO (com.dtstack.dtcenter.loader.dto.source.HdfsSourceDTO)5 UnknownHostException (java.net.UnknownHostException)5 Matcher (java.util.regex.Matcher)4 ArrayList (java.util.ArrayList)3 IClient (com.dtstack.dtcenter.loader.client.IClient)2 IKerberos (com.dtstack.dtcenter.loader.client.IKerberos)2 ColumnMetaDTO (com.dtstack.dtcenter.loader.dto.ColumnMetaDTO)2 SqlQueryDTO (com.dtstack.dtcenter.loader.dto.SqlQueryDTO)2 ISourceDTO (com.dtstack.dtcenter.loader.dto.source.ISourceDTO)2 DataSourceTypeEnum (com.dtstack.taier.common.enums.DataSourceTypeEnum)2 PubSvcDefineException (com.dtstack.taier.common.exception.PubSvcDefineException)2 DsInfo (com.dtstack.taier.dao.domain.DsInfo)2 File (java.io.File)2 HttpEntity (org.apache.http.HttpEntity)2