写过一个类似的可以参考一下
private static List<String> lookupSelectTable(SqlNode sqlNode) {
List<String> list = new ArrayList<>();
if (sqlNode instanceof SqlSelect) {
SqlNode from = ((SqlSelect) sqlNode).getFrom();
list.addAll(lookupSelectTable(from));
} else if (sqlNode instanceof SqlJoin) {
SqlJoin sqlJoin = (SqlJoin) sqlNode;
list.addAll(lookupSelectTable(sqlJoin.getLeft()));
list.addAll(lookupSelectTable(sqlJoin.getRight()));
} else if (sqlNode instanceof SqlBasicCall) {
SqlBasicCall sqlBasicCall = (SqlBasicCall) sqlNode;
SqlOperator operator = sqlBasicCall.getOperator();
if (SqlKind.AS.equals(operator.getKind())) {
list.addAll(lookupSelectTable(sqlBasicCall.getOperands()[0]));
} else if (SqlKind.UNION.equals(operator.getKind())) {
for (SqlNode operandSqlNode : sqlBasicCall.getOperands()) {
list.addAll(lookupSelectTable(operandSqlNode));
}
} else {
throw new RuntimeException("operator " + operator.getKind()
+ " not support");
}
} else if (sqlNode instanceof SqlIdentifier) {
list.add(((SqlIdentifier) sqlNode).getSimple());
} else {
throw new RuntimeException("operator " + sqlNode.getClass() + "
not support");
}
return list;
}
--
Sent from: http://apache-flink.147419.n8.nabble.com/