How to extract join conditions from the JSQLParser result of an non-ansi join statement?

51 views Asked by At

I'm using JSQLParser to parse a SQL statement which is unknown util when it is passed to JSQLParser. If the query contains non-ANSI join, the join condition is in the WhereExpression instead of the onExpressions in Join.

For example, the parse result of non-ANSI join statement SELECT * FROM a, b WHERE a.id = b.id is

SQL Text
 └─Statements: net.sf.jsqlparser.statement.select.Select
    └─selectBody: net.sf.jsqlparser.statement.select.PlainSelect
       ├─ArrayList: [*]
       │  └─AllColumns: *
       ├─Table: a
       ├─ArrayList: [b]
       │  └─joins: net.sf.jsqlparser.statement.select.Join
       │     └─Table: b
       └─where: net.sf.jsqlparser.expression.operators.relational.EqualsTo
          ├─Column: a.id
          └─Column: b.id

While the parse result of SELECT * FROM a JOIN b ON a.id = b.id is

SQL Text
 └─Statements: net.sf.jsqlparser.statement.select.Select
    └─selectBody: net.sf.jsqlparser.statement.select.PlainSelect
       ├─ArrayList: [*]
       │  └─AllColumns: *
       ├─Table: a
       └─ArrayList: [JOIN b ON a.id = b.id]
          └─joins: net.sf.jsqlparser.statement.select.Join
             ├─Table: b
             └─LinkedList: [a.id = b.id]
                └─onExpressions: net.sf.jsqlparser.expression.operators.relational.EqualsTo
                   ├─Column: a.id
                   └─Column: b.id

Since further work is required in my program to process the join conditions, I need to extract them from the whereExpression and add them back to the onExpression if there are non-ANSI joins in the statement.

Are there any methods or rules that I can applied to implement the extraction?

0

There are 0 answers