sanjosh / php-sql-parser

Automatically exported from code.google.com/p/php-sql-parser
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Parser does not correctly parse a count(*) expression #65

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. try to parse the following:
select i1, count(*) cnt from test.s1 group by i1

2. You'll get the following, which has an incorrect 'base_expr' and the alias 
is missing.  It treats the alias as a colref.
Array
(
    [SELECT] => Array
        (
            [0] => Array
                (
                    [expr_type] => colref
                    [alias] => 
                    [base_expr] => i1
                    [sub_tree] => 
                )

            [1] => Array
                (
                    [expr_type] => expression
                    [alias] => 
                    [base_expr] => count(*) cnt
                    [sub_tree] => Array
                        (
                            [0] => Array
                                (
                                    [expr_type] => aggregate_function
                                    [base_expr] => count
                                    [sub_tree] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [expr_type] => colref
                                                    [base_expr] => *
                                                    [sub_tree] => 
                                                )

                                        )

                                )

                            [1] => Array
                                (
                                    [expr_type] => colref
                                    [base_expr] => cnt
                                    [sub_tree] => 
                                )

                        )

                )

        )

    [FROM] => Array
        (
            [0] => Array
                (
                    [expr_type] => table
                    [table] => test.s1
                    [alias] => 
                    [join_type] => JOIN
                    [ref_type] => 
                    [ref_clause] => 
                    [base_expr] => test.s1
                    [sub_tree] => 
                )

        )

    [GROUP] => Array
        (
            [0] => Array
                (
                    [expr_type] => colref
                    [base_expr] => i1
                    [sub_tree] => 
                )

        )

)

What is the expected output? 
I expect one expression in the sub_tree for count(*) and alias to be properly 
populated

Phosco:
You've modified the parser extensively and I'm not sure that I fully understand 
it completely now.  If you can fix this quickly, I'd appreciate it, otherwise I 
can look into it.  I've assigned it to you.  Assign it back to me if you don't 
have time.

Original issue reported on code.google.com by greenlion@gmail.com on 2 Jul 2012 at 12:46

GoogleCodeExporter commented 8 years ago
See /trunk, there was a problem with the type "aggregate_function". I have 
added a test case.

Original comment by pho...@gmx.de on 2 Jul 2012 at 7:13