-
I have seen questions about getting a list of columns and I have looked at the TableNamesFinder class. What I am not able to get my head wrapped around is how would I go about creating a map of aliases to table columns or expressions. I want to create list of table columns used in a select, but have also the alias included. I am attempting to do column to schema validation in the visit column method, but by the time it gets to the column visit the alias seems not available. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Maybe you look into: https://github.com/JSQLParser/JSqlParser/wiki/Examples-of-SQL-parsing#apply-aliases-to-all-expressions. This AddAliasesVisitor extracts all expressions and columns and adds aliases. So you could learn from this to read it and create a list. |
Beta Was this translation helpful? Give feedback.
-
I was able to do it by adding two maps. One would map object to SelectExcpressionItem and would be updated as the visitor descended through the structure so I am always able to tell which SelectExpressionItem is the root of the current branch and then a map to keep track of SelectExpressionItems to a list of columns it has encountered on the way. As noted elsewhere I had to implement retrieval of column names from schema for cases like AllColumns and AllTableColumns. |
Beta Was this translation helpful? Give feedback.
I was able to do it by adding two maps. One would map object to SelectExcpressionItem and would be updated as the visitor descended through the structure so I am always able to tell which SelectExpressionItem is the root of the current branch and then a map to keep track of SelectExpressionItems to a list of columns it has encountered on the way. As noted elsewhere I had to implement retrieval of column names from schema for cases like AllColumns and AllTableColumns.