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);
}
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 必须为字符串数组格式");
}
}
}
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");
}
}
}
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;
}
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;
}
Aggregations