问题
I'm using presto-parser to figure out which database tables are being queried in any given Presto query. I implemented a class that extends DefaultTraversalVisitor like this
public class ProcessTables extends DefaultTraversalVisitor<Void, Void> {
private Set<String> tables;
ProcessTables() {
this.tables = new LinkedHashSet<>();
}
Set<String> getTables() {
return tables;
}
@Override
protected Void visitTable(Table node, Void context) {
this.tables.add(node.getName().toString());
return visitQueryBody(node, context);
}
}
However, I find that conceptual tables (I'm not sure of the correct term here) are also treated as Tables without a way to distinguish them from actual database tables. For example
with RANDOMNAME as (
select column_a, column_b
from db.tablename
where condition
)
would visitTable
for both RANDOMNAME
and db.tablename
. Is there a better way to do this? Am I missing something, like another method that I should override as well to distinguish between the two?
来源:https://stackoverflow.com/questions/61361107/how-to-get-all-database-tables-referenced-in-a-presto-query-using-presto-parser