use of com.dtstack.taier.develop.sql.TableLineage in project Taier by DTStack.
the class AstNodeParser method parseTableLineage.
@Override
public ParseResult parseTableLineage(String originSql, String currentDb) throws Exception {
ParseResult parseResult = new ParseResult();
parseResult.setCurrentDb(currentDb);
parseResult.setOriginSql(originSql);
parseResult.setMainTable(new Table());
ASTNode root;
originSql = SqlFormatUtil.formatSql(originSql);
String standardSql = SqlFormatUtil.getStandardSql(originSql);
SqlFormatUtil.checkSql(standardSql);
parseResult.setStandardSql(standardSql);
// 解析和去掉sql中的生命周期和类目信息
parseLifecycleAndCatalogue(parseResult);
String formattedSql = this.uglySqlHandler.parseUglySql(originSql);
if (StringUtils.isEmpty(formattedSql)) {
return parseResult;
}
parseResult.setStandardSql(formattedSql);
try {
root = parseDriver.parse(parseResult.getStandardSql());
} catch (ParseException e) {
LOG.error("sql解析异常========>>>>:{}", e.getMessage());
// 用正则匹配一下
ParseResult p = SqlTypeRegexUtil.getParseResultByRegexSql(parseResult);
return p;
}
NodeParser nodeParser = ASTNodeLineageParser.ParserProxy.getParser((ASTNode) root.getChild(0), originSql);
com.dtstack.taier.develop.sql.node.Node node = nodeParser.parseSql((ASTNode) root.getChild(0), currentDb, new HashMap<>(), new HashMap<>());
LineageParser lineageParser = LineageParser.HiveParserProxy.getParser(node, currentDb, new HashMap<>());
if (lineageParser != null) {
List<TableLineage> tableLineages = getTableLineages(node, lineageParser);
parseResult.setTableLineages(tableLineages);
}
getMainTable(node, parseResult, root);
return parseResult;
}
use of com.dtstack.taier.develop.sql.TableLineage in project Taier by DTStack.
the class AstNodeParser method getTableLineages.
/**
* 对表级血缘进行组装
*
* @param sqlNode
* @param lineageParser
* @return
*/
private List<TableLineage> getTableLineages(com.dtstack.taier.develop.sql.node.Node sqlNode, LineageParser lineageParser) {
List<TableLineage> resList = Lists.newArrayList();
List<Pair<Identifier, Identifier>> pairs = lineageParser.parseTableLineage(sqlNode);
if (CollectionUtils.isNotEmpty(pairs)) {
for (Pair<Identifier, Identifier> pair : pairs) {
Identifier key = pair.getKey();
Identifier value = pair.getValue();
TableLineage tableLineage = new TableLineage();
tableLineage.setFromDb(value.getDb());
tableLineage.setFromTable(value.getTable());
tableLineage.setToDb(key.getDb());
tableLineage.setToTable(key.getTable());
resList.add(tableLineage);
}
}
return resList;
}
Aggregations