You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static class TableVisitor extends OdpsASTVisitorAdapter {
public List<String> tableList = new ArrayList<>();
@Override
public boolean visit(SQLExprTableSource tableSource) {
tableList.add(tableSource.getTableName());
return true;
}
}
遍历代码如下:
String sql1 = "with \n" +
" a as (select * from src where key is not null),\n" +
" b as (select * from src2 where value>0),\n" +
" c as (select * from src3 where value>0),\n" +
" d as (select a.key,b.value from a join b on a.key=b.key ),\n" +
" e as (select a.key,c.value from a left outer join c on a.key=c.key and c.key is not null )\n" +
" insert overwrite table x select * from y;";
SQLStatement statement = SQLUtils.parseSingleStatement(sql1, DbType.odps, false);
TableVisitor visitor = new TableVisitor();
statement.accept(visitor);
System.out.println(visitor.tableList.toString());
打印结果:
[x, y]
The text was updated successfully, but these errors were encountered:
debughx
changed the title
解析with......insertoverwrite......类sql问题
解析with......insert overwrite......类sql问题
Sep 15, 2022
使用visitor遍历sql的SQLExprTableSource,发现vistitor在遍历类似 wtih......insert overwrite......这种类型的sql时,不会遍历with里的表,而with......select 则不会出现这种情况。
visitor定义如下:
遍历代码如下:
打印结果:
[x, y]
The text was updated successfully, but these errors were encountered: