-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
I'm developing an application that needs to identify columns used in equality predicates. This is working fine for predicates that are not inside parens. For example consider this query and AST:
SELECT w_tax
FROM warehouse
WHERE w_id
= 4;
SQL Text
└─Statements: statement.select.PlainSelect
├─selectItems: statement.select.SelectItem
│ └─Column: w_tax
├─Table: warehouse
└─where: expression.operators.relational.EqualsTo
├─Column: w_id
└─LongValue: 4
However, if the where clause is in parens, the AST is very different, and the column name and value are not visible explicitly in the AST. How to identify them if they exist?
Here is the same query with the predicates in parens:
SELECT w_tax
FROM warehouse
WHERE ( w_id
= 4 );
Here is the AST:
SQL Text
└─Statements: statement.select.PlainSelect
├─selectItems: statement.select.SelectItem
│ └─Column: w_tax
├─Table: warehouse
└─ParenthesedExpressionList: (w_id
= 4)
Thanks for your help.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 1 reply
-
Greetings, please have a look at JSQLTranspiler which can retrieve full column lineage.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks. From your answer, does this mean that JSQLParser can't handle this directly?
Beta Was this translation helpful? Give feedback.
All reactions
-
As always I depends :-D
- Colum Resolution is actually difficult and can not be over estimated
- without schema information JSQLParser can not know if an identifier is an actual physical column or not (and that is what JSQLTranspiler is doing)
- however, often you just need a "good guess" without resolving against Schema and then JSQLTranspiler can help a lot already (especially with the new improved Visitor patterns in version 5)
Conclusion:
a) if you have Schema information, then better use JSQLTranspiler for the column resolution
b) if you don't have schema information, then JSQLParser can give you the maximum information based on the query only
Or in other words:
JSQLTranspiler = JSQLParser plus Schema Information
Beta Was this translation helpful? Give feedback.