Skip to content

join missing the 'on' filter #1229

Closed

Description

@zhang245606

original SQL : select t1.column1,t1.column2,t2.field1,t2.field2 from T_DT_ytb_01 t1 , T_DT_ytb_02 t2 on t1.column1 = t2.field1
after parse SQL: SELECT t1.column1, t1.column2, t2.field1, t2.field2 FROM T_DT_ytb_01 t1, T_DT_ytb_02 t2

What is simple join?

Activity

  1. manticore-projects commented on Jun 16, 2021

    @manticore-projects
    Contributor

    Greetings.

    1. I can not confirm your observation. Statement is parsed and deparsed correctly:
    SELECT  t1.column1
            , t1.column2
            , t2.field1
            , t2.field2
    FROM t_dt_ytb_01 t1
        , t_dt_ytb_02 t2
            ON t1.column1 = t2.field1
    ;

    You can also test it online here

    1. Your statement should be invalid though because you should be able to use ON only in conjunction with JOIN, otherwise you would need to use WHERE (at least this is my understanding).

    Please double check and close this issue, when confirmed.

  2. wumpz commented on Jun 16, 2021

    @wumpz
    Member

    It could be, like using parseExpression, that JSqlParser parses as far as it is able to interpret your sql and stops then. How to you parse this statement actually?

    If you do not use CCJSqlParserUtil.parse but directly use the parses SingleStatement method, this one could happen.

    However this seems like a bug to me, as @manticore-projects already mentioned, this on should only be valid with a corresponding join.

  3. zhang245606 commented on Jun 16, 2021

    @zhang245606
    Author

    Thank you for your reply!

    I try to parse it as follows :
    String sql = "select t1.column1,t1.column2,t2.field1,t2.field2 from T_DT_ytb_01 t1 , T_DT_ytb_02 t2 on t1.column1 = t2.field1";
    Statement parse = CCJSqlParserUtil.parse(sql);
    return parse.toString();

    This sql is equivalent to “select t1.column1,t1.column2,t2.field1,t2.field2 from T_DT_ytb_01 t1 inner join T_DT_ytb_02 t2 on t1.column1 = t2.field1”

    I don't understand what simple join means .
    The debug screenshot is as follows:
    image

  4. wumpz commented on Jun 16, 2021

    @wumpz
    Member

    The problem is in production JoinerExpression. Simple means a comma list of table names like

    select * from tab1, tab2
    

    but in the grammar is no check when this on part is parsed, if there was a non simple join

    ( <K_ON> onExpression=Expression()  { join.setOnExpression(onExpression); })
    

    So the solution should be a semantic Lookahead here with the check !join.isSimple().

  5. self-assigned this
    on Jun 16, 2021
  6. added a commit that references this issue on Aug 14, 2021
    d2c3712
  7. added a commit that references this issue on Sep 6, 2021
    d18c59b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions