Hacker News new | ask | show | jobs
by noisy_boy 1421 days ago
I wonder if this is a topical thread to check if anyone is aware of a Java based solution to parse a CREATE VIEW statement to get a mapping between the view columns and the corresponding source table columns. I checked out jsqlparser[0] and it does produce an AST which can be parsed using the visitor-pattern[1] but was wondering if there is a more "out-of-the-box" solution involving less work. Due to various reasons, querying the database information schema is not an option I can pursue.

[0]: https://github.com/JSQLParser/JSqlParser

[1]: https://en.wikipedia.org/wiki/Visitor_pattern

2 comments

What do you mean by a mapping with a source table columns? The data columns in the view could come from 0 to n source tables. Entirely synthetic, transformed, combined data from multiple tables etc.
True - I mean the view columns that _are_ from actual tables. Could be straight up table columns as is or may be part of function like max(a.abcd) where a is an alias to table xyz
Apache Calcite can do this, though it's not a beginner-friendly task:

https://calcite.apache.org/