use of com.qlangtech.tis.sql.parser.exception.TisSqlFormatException in project tis by qlangtech.
the class SqlTaskNodeMeta method getRewriteSql.
// private static class EntryPair implements Map.Entry<IDumpTable, ITabPartition> {
// private final IDumpTable key;
// private final ITabPartition val;
//
// public EntryPair(IDumpTable key, ITabPartition val) {
// this.key = key;
// this.val = val;
// }
//
// @Override
// public IDumpTable getKey() {
// return key;
// }
//
// @Override
// public ITabPartition getValue() {
// return val;
// }
//
// @Override
// public ITabPartition setValue(ITabPartition value) {
// return null;
// }
// }
@Override
public RewriteSql getRewriteSql(String taskName, TabPartitions dumpPartition, IPrimaryTabFinder erRules, ITemplateContext templateContext, boolean isFinalNode) {
if (dumpPartition.size() < 1) {
throw new IllegalStateException("dumpPartition set size can not small than 1");
}
Optional<List<Expression>> parameters = Optional.empty();
IJoinTaskContext joinContext = templateContext.getExecContext();
SqlStringBuilder builder = new SqlStringBuilder();
SqlRewriter rewriter = new SqlRewriter(builder, dumpPartition, erRules, parameters, isFinalNode, joinContext);
// 执行rewrite
try {
Statement state = getSqlStatement();
rewriter.process(state, 0);
} catch (TisSqlFormatException e) {
throw e;
} catch (Exception e) {
// dumpPartition.entrySet().stream().map((ee) -> "[" + ee.getKey() + "->" + ee.getValue().getPt() + "]").collect(Collectors.joining(","));
String dp = dumpPartition.toString();
throw new IllegalStateException("task:" + taskName + ",isfinalNode:" + isFinalNode + ",dump tabs pt:" + dp + "\n" + e.getMessage(), e);
}
SqlRewriter.AliasTable primaryTable = rewriter.getPrimayTable();
if (primaryTable == null) {
throw new IllegalStateException("task:" + taskName + " has not find primary table");
}
// return ;
return new RewriteSql(builder.toString(), rewriter.getPrimayTable());
}
use of com.qlangtech.tis.sql.parser.exception.TisSqlFormatException in project tis by qlangtech.
the class SqlTaskNodeMeta method validateSql.
/**
* 对sql进行粗略的校验
*
* @param sql
* @param dependencyNodes
* @return
*/
public static Optional<TisSqlFormatException> validateSql(String sql, List<String> dependencyNodes) {
// Optional<TisSqlFormatException> result = Optional.empty();
SqlTaskNodeMeta taskNodeMeta = new SqlTaskNodeMeta();
// 这个sql语句有错误,需要校验成错误,抛异常
taskNodeMeta.setSql(sql);
final IJoinTaskContext tskContext = new DftJoinTaskContext(ExecutePhaseRange.fullRange());
final ITemplateContext tplContext = new ITemplateContext() {
@Override
public <T> T getContextValue(String key) {
return null;
}
@Override
public void putContextValue(String key, Object v) {
}
@Override
public IJoinTaskContext getExecContext() {
return tskContext;
}
};
try {
String pt = "20200703113848";
ITabPartition p = () -> pt;
Map<IDumpTable, ITabPartition> tabPartition = dependencyNodes.stream().collect(Collectors.toMap((r) -> EntityName.parse(r), (r) -> p));
taskNodeMeta.getRewriteSql("testTaskName", new MockDumpPartition(tabPartition), new IPrimaryTabFinder() {
@Override
public Optional<TableMeta> getPrimaryTab(IDumpTable entityName) {
return Optional.empty();
}
@Override
public Map<EntityName, TabFieldProcessor> getTabFieldProcessorMap() {
return Collections.emptyMap();
}
}, tplContext, false);
return Optional.empty();
} catch (Throwable e) {
int indexOf;
if ((indexOf = ExceptionUtils.indexOfType(e, TisSqlFormatException.class)) > -1) {
TisSqlFormatException ex = (TisSqlFormatException) ExceptionUtils.getThrowables(e)[indexOf];
// System.out.println(ex.summary());
return Optional.of(ex);
// assertEquals("base ref:gg can not find relevant table entity in map,mapSize:1,exist:[g:tis.commodity_goods],位置,行:1,列:44", ex.summary());
} else {
throw e;
}
}
}
Aggregations