From: Arthur Axel 'fREW' Schmidt Date: Fri, 14 Mar 2014 16:12:05 +0000 (-0500) Subject: Fix the reassembler to treat RNO as the precious special snowflake it is X-Git-Tag: v1.78~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0ec2e26564ab5809a4b1c76ca7b3084c7a06fccd;p=dbsrgits%2FSQL-Abstract.git Fix the reassembler to treat RNO as the precious special snowflake it is Yes, the parser is accumulating a lot of cruft this way with special casing and whatnot, and yes it is necessary for the future when we write a real parser which will *HAVE* to deal with the corner cases. The accumulated set of tests is the goal here (with the side effect of better UX) -- ribasushi --- diff --git a/Changes b/Changes index 4461299..5d98116 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Revision history for SQL::Abstract - Fix parsing of binary ops to correctly take up only a single LHS element, instead of gobbling up the entire parse-to-date + - Explicitly handle ROW_NUMBER() OVER as the snowflake-operator it is revision 1.77 2014-01-17 ---------------------------- diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index ae93c95..97b90a6 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -669,8 +669,9 @@ sub _parenthesis_unroll { $changes++; } - # if the parent operator explicitly allows it nuke the parenthesis - if ( $ast->[0] =~ $unrollable_ops_re ) { + # if the parent operator explicitly allows it AND the child isn't a subselect + # nuke the parenthesis + if ($ast->[0] =~ $unrollable_ops_re and $child->[1][0][0] ne 'SELECT') { push @children, @{$child->[1]}; $changes++; } @@ -758,7 +759,10 @@ sub _parenthesis_unroll { # a construct of ... ( somefunc ( ... ) ) ... can safely lose the outer parens # except for the case of ( NOT ( ... ) ) which has already been handled earlier + # and except for the case of RNO, where the double are explicit syntax elsif ( + $ast->[0] ne 'ROW_NUMBER() OVER' + and @{$child->[1]} == 1 and @{$child->[1][0][1]} == 1 diff --git a/t/14roundtrippin.t b/t/14roundtrippin.t index 3b631d3..bfb713f 100644 --- a/t/14roundtrippin.t +++ b/t/14roundtrippin.t @@ -27,6 +27,7 @@ my @sql = ( "SELECT * FROM foo WHERE foo.a @@ to_tsquery('word')", "SELECT * FROM foo ORDER BY name + ?, [me].[id]", "SELECT foo AS bar FROM baz ORDER BY x + ? DESC, baz.g", + "SELECT [me].[id], ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS [rno__row__index] FROM ( SELECT [me].[id] FROM [LogParents] [me]) [me]", # deliberate batshit insanity "SELECT foo FROM bar WHERE > 12", );