Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Equality predicates inside parens #2053

sampsonsl started this conversation in General
Discussion options

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.

You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

Greetings, please have a look at JSQLTranspiler which can retrieve full column lineage.

You must be logged in to vote
1 reply
Comment options

Thanks. From your answer, does this mean that JSQLParser can't handle this directly?

Comment options

As always I depends :-D

  1. Colum Resolution is actually difficult and can not be over estimated
  2. without schema information JSQLParser can not know if an identifier is an actual physical column or not (and that is what JSQLTranspiler is doing)
  3. 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

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /