Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 1492 #1600

Merged
merged 2 commits into from
Jan 10, 2020
Merged

fix issue 1492 #1600

merged 2 commits into from
Jan 10, 2020

Conversation

Yang2096
Copy link
Contributor

@Yang2096 Yang2096 commented Jan 2, 2020

fix #1492 with the solution given by @small-cat .

SELECT o.item.line_item_id, o.item.quantity FROM short_orders o

Before

(sql_script 
    (unit_statement 
        (data_manipulation_language_statements 
            (select_statement 
                (subquery 
                    (subquery_basic_elements 
                        (query_block SELECT 
                            (selected_element 
                                (select_list_elements 
                                    (regular_id O)
                                    . (expressions     //  all selected_elements were parsed to a single seleced_element
                                        (expression 
                                        (logical_expression 
                                        (unary_logical_expression 
                                        (multiset_expression 
                                        (relational_expression 
                                        (compound_expression 
                                        (concatenation 
                                        (model_expression 
                                        (unary_expression 
                                        (atom 
                                        (general_element 
                                        (general_element_part 
                                            (id_expression (regular_id ITEM)) 
                                            . (id_expression (regular_id LINE_ITEM_ID))
                                        )))))))))))) , 
// the second select_list_element was parsed as a expression
                                        (expression 
                                        (logical_expression 
                                        (unary_logical_expression 
                                        (multiset_expression 
                                        (relational_expression 
                                        (compound_expression 
                                        (concatenation 
                                        (model_expression 
                                        (unary_expression 
                                        (atom 
                                        (general_element 
                                        (general_element_part 
                                            (id_expression (regular_id O)) . 
                                            (id_expression (regular_id ITEM)) . 
                                            (id_expression (regular_id QUANTITY))))))))))))))
                                    )
                                )) 
                            (from_clause FROM 
                                (table_ref_list 
                                (table_ref 
                                (table_ref_aux 
                                (table_ref_aux_internal 
                                (dml_table_expression_clause 
                                (tableview_name 
                                (identifier 
                                (id_expression 
                                    (regular_id SHORT_ORDERS)))))) 
                                (table_alias 
                                (identifier 
                                (id_expression 
                                    (regular_id O)))))))
                            )
                        )
                    )
                )
            )
        )
    ) 
<EOF>
)

After

(sql_script 
    (unit_statement 
        (data_manipulation_language_statements 
            (select_statement 
                (subquery 
                    (subquery_basic_elements 
                        (query_block SELECT 
                            (selected_list 
                                (select_list_elements 
                                    (expression 
                                    (logical_expression 
                                    (unary_logical_expression 
                                    (multiset_expression 
                                    (relational_expression 
                                    (compound_expression 
                                    (concatenation 
                                    (model_expression 
                                    (unary_expression 
                                    (atom 
                                    (general_element 
                                    (general_element_part 
                                        (id_expression (regular_id O)) . 
                                        (id_expression (regular_id ITEM)) . 
                                        (id_expression (regular_id LINE_ITEM_ID))
                                    ))))))))))))) , 

                                (selected_list_element 
                                    (expression 
                                    (logical_expression 
                                    (unary_logical_expression 
                                    (multiset_expression 
                                    (relational_expression 
                                    (compound_expression 
                                    (concatenation 
                                    (model_expression 
                                    (unary_expression 
                                    (atom 
                                    (general_element 
                                    (general_element_part 
                                        (id_expression (regular_id O)) . 
                                        (id_expression (regular_id ITEM)) . 
                                        (id_expression (regular_id QUANTITY))
                                    )))))))))))))) 
                            (from_clause FROM 
                                (table_ref_list 
                                    (table_ref 
                                    (table_ref_aux 
                                    (table_ref_aux_internal 
                                    (dml_table_expression_clause 
                                    (tableview_name 
                                    (identifier 
                                    (id_expression 
                                        (regular_id SHORT_ORDERS)))))) 
                                    (table_alias 
                                        (identifier (id_expression (regular_id O)))
                                    ))))
                            )
                        )
                    )
                )
            )
        )
    ) 
<EOF>
)

@Yang2096
Copy link
Contributor Author

Yang2096 commented Jan 2, 2020

The old grammar has another mistake, you can write SQL like select table.* as ALL from table;, which is impossible in reality.

@KvanTTT KvanTTT added the plsql label Jan 10, 2020
@KvanTTT KvanTTT merged commit 64016e0 into antlr:master Jan 10, 2020
@Yang2096 Yang2096 deleted the fix_1492 branch January 10, 2020 12:33
@KvanTTT KvanTTT mentioned this pull request Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Grammar PlSqlParser.g4 parsed uncorrect result
2 participants