Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解析with......insert overwrite......类sql问题 #4933

Closed
debughx opened this issue Sep 15, 2022 · 1 comment
Closed

解析with......insert overwrite......类sql问题 #4933

debughx opened this issue Sep 15, 2022 · 1 comment
Milestone

Comments

@debughx
Copy link

debughx commented Sep 15, 2022

使用visitor遍历sql的SQLExprTableSource,发现vistitor在遍历类似 wtih......insert overwrite......这种类型的sql时,不会遍历with里的表,而with......select 则不会出现这种情况。

visitor定义如下:

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]

@debughx debughx changed the title 解析with......insertoverwrite......类sql问题 解析with......insert overwrite......类sql问题 Sep 15, 2022
@wenshao wenshao added the Bug label Sep 15, 2022
@wenshao wenshao added this to the 1.2.13 milestone Oct 6, 2022
@wenshao wenshao added the Fixed label Oct 6, 2022
@wenshao
Copy link
Member

wenshao commented Oct 6, 2022

https://github.com/alibaba/druid/releases/tag/1.2.13
问题已修复,请用新版本

@wenshao wenshao closed this as completed Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants