-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
For instance, I want something like this:
PlainSelect select = (PlainSelect) CCJSqlParserUtil.parse(query);
List<SelectItem<?>> selectItems = select.getSelectItems();
. . .
String tableName = TableNamesFinder.findTable(selectItem, colName -> findTables(colName));I want a findTable(SelectItem<?> selectItem, Function<String, Set<String>> tableMatcher) method where tableMatcher provides the parser with a lookup for tables having a specified column name. For my case I can supply this via JDBC. Note, selectItem must be a column defined in a table or the all-columns expression, otherwise the method returns null.
I know this type of utility is more on the semantics side of the equation, but I feel like this parser could begin to provide these kinds of services. Even better, build a resolver/backend based on JDBC where not only table names, but also data types etc. could be attached to the AST. Just a thought, considering most of the time a specific DBMS is in context when using this parser.
Btw, I need this utility as a backup for JDBC drivers that don't support ResultSetMetaData#getTableName(int columnIndex) properly; Server and Oracle don't provide table names corresponding with columns.
I'll probably begin writing this utility myself, but would appreciate feedback if you have any. Would be awesome to hear something similar is available!