Skip to content

Instantly share code, notes, and snippets.

@nathanlws
Created November 19, 2014 15:09
Show Gist options
  • Save nathanlws/f71000943777297c7cfb to your computer and use it in GitHub Desktop.
Save nathanlws/f71000943777297c7cfb to your computer and use it in GitHub Desktop.
TableFinder
import com.foundationdb.sql.parser.*;
import com.foundationdb.sql.StandardException;
public class TableFinder {
public static void main(String[] args) throws Exception {
SQLParser parser = new SQLParser();
for(String sql : args) {
StatementNode node = parser.parseStatement(sql);
node.accept(new FromTablePrinter());
}
}
public static class FromTablePrinter implements Visitor {
public Visitable visit(Visitable node) throws StandardException {
if(node instanceof FromTable) {
FromTable ft = (FromTable)node;
TableName name = ft.getOrigTableName();
String alias = ft.getCorrelationName();
if(name != null) {
System.out.print(name);
if(alias != null) {
System.out.print(" AS " + alias);
}
System.out.println();
} else if (alias != null) {
String type = node.getClass().getSimpleName();
System.out.println(type + " AS " + alias);
}
}
return node;
};
public boolean visitChildrenFirst(Visitable node) {
return false;
}
public boolean stopTraversal() {
return false;
}
public boolean skipChildren(Visitable node) {
return false;
}
}
}
@Bhanoday55
Copy link

can you provide me with jar file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment