use of com.alibaba.druid.sql.parser.ParserException in project DataX by alibaba.
the class WriterUtil method preCheckPrePareSQL.
public static void preCheckPrePareSQL(Configuration originalConfig, DataBaseType type) {
List<Object> conns = originalConfig.getList(Constant.CONN_MARK, Object.class);
Configuration connConf = Configuration.from(conns.get(0).toString());
String table = connConf.getList(Key.TABLE, String.class).get(0);
List<String> preSqls = originalConfig.getList(Key.PRE_SQL, String.class);
List<String> renderedPreSqls = WriterUtil.renderPreOrPostSqls(preSqls, table);
if (null != renderedPreSqls && !renderedPreSqls.isEmpty()) {
LOG.info("Begin to preCheck preSqls:[{}].", StringUtils.join(renderedPreSqls, ";"));
for (String sql : renderedPreSqls) {
try {
DBUtil.sqlValid(sql, type);
} catch (ParserException e) {
throw RdbmsException.asPreSQLParserException(type, e, sql);
}
}
}
}
use of com.alibaba.druid.sql.parser.ParserException in project DataX by alibaba.
the class WriterUtil method preCheckPostSQL.
public static void preCheckPostSQL(Configuration originalConfig, DataBaseType type) {
List<Object> conns = originalConfig.getList(Constant.CONN_MARK, Object.class);
Configuration connConf = Configuration.from(conns.get(0).toString());
String table = connConf.getList(Key.TABLE, String.class).get(0);
List<String> postSqls = originalConfig.getList(Key.POST_SQL, String.class);
List<String> renderedPostSqls = WriterUtil.renderPreOrPostSqls(postSqls, table);
if (null != renderedPostSqls && !renderedPostSqls.isEmpty()) {
LOG.info("Begin to preCheck postSqls:[{}].", StringUtils.join(renderedPostSqls, ";"));
for (String sql : renderedPostSqls) {
try {
DBUtil.sqlValid(sql, type);
} catch (ParserException e) {
throw RdbmsException.asPostSQLParserException(type, e, sql);
}
}
}
}
use of com.alibaba.druid.sql.parser.ParserException in project DataX by alibaba.
the class PreCheckTask method call.
@Override
public Boolean call() throws DataXException {
String jdbcUrl = this.connection.getString(Key.JDBC_URL);
List<Object> querySqls = this.connection.getList(Key.QUERY_SQL, Object.class);
List<Object> splitPkSqls = this.connection.getList(Key.SPLIT_PK_SQL, Object.class);
List<Object> tables = this.connection.getList(Key.TABLE, Object.class);
Connection conn = DBUtil.getConnectionWithoutRetry(this.dataBaseType, jdbcUrl, this.userName, password);
int fetchSize = 1;
if (DataBaseType.MySql.equals(dataBaseType) || DataBaseType.DRDS.equals(dataBaseType)) {
fetchSize = Integer.MIN_VALUE;
}
try {
for (int i = 0; i < querySqls.size(); i++) {
String splitPkSql = null;
String querySql = querySqls.get(i).toString();
String table = null;
if (tables != null && !tables.isEmpty()) {
table = tables.get(i).toString();
}
/*verify query*/
ResultSet rs = null;
try {
DBUtil.sqlValid(querySql, dataBaseType);
if (i == 0) {
rs = DBUtil.query(conn, querySql, fetchSize);
}
} catch (ParserException e) {
throw RdbmsException.asSqlParserException(this.dataBaseType, e, querySql);
} catch (Exception e) {
throw RdbmsException.asQueryException(this.dataBaseType, e, querySql, table, userName);
} finally {
DBUtil.closeDBResources(rs, null, null);
}
/*verify splitPK*/
try {
if (splitPkSqls != null && !splitPkSqls.isEmpty()) {
splitPkSql = splitPkSqls.get(i).toString();
DBUtil.sqlValid(splitPkSql, dataBaseType);
if (i == 0) {
SingleTableSplitUtil.precheckSplitPk(conn, splitPkSql, fetchSize, table, userName);
}
}
} catch (ParserException e) {
throw RdbmsException.asSqlParserException(this.dataBaseType, e, splitPkSql);
} catch (DataXException e) {
throw e;
} catch (Exception e) {
throw RdbmsException.asSplitPKException(this.dataBaseType, e, splitPkSql, this.splitPkId.trim());
}
}
} finally {
DBUtil.closeDBResources(null, conn);
}
return true;
}
Aggregations