From: Matt S Trout Date: Sun, 29 Jul 2012 17:19:00 +0000 (+0000) Subject: functionalise order mapping X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e82795badd473bce46651b622ed622d3d218a78f;p=dbsrgits%2FData-Query.git functionalise order mapping --- diff --git a/lib/Data/Query/Renderer/SQL/Slice/FetchFirst.pm b/lib/Data/Query/Renderer/SQL/Slice/FetchFirst.pm index f7be0b2..d885fb4 100644 --- a/lib/Data/Query/Renderer/SQL/Slice/FetchFirst.pm +++ b/lib/Data/Query/Renderer/SQL/Slice/FetchFirst.pm @@ -75,13 +75,12 @@ sub _render_slice { }; my $order_gensym_count; - my %order_map; - foreach my $order (@order_nodes) { - my $by = $order->{by}; + my @mapped_order = map { + my $by = $_->{by}; if (is_Identifier $by) { $default_inside_alias ||= $by->{elements}[0] if @{$by->{elements}} == 2; - $order_map{$by} + my $mapped_by = $alias_map{join('.', @{$by->{elements}})} ||= do { if ( @@ -95,10 +94,11 @@ sub _render_slice { Identifier($name); } }; + Order($mapped_by, $_->{reverse}); } else { die "XXX not implemented yet"; } - } + } @order_nodes; $default_inside_alias ||= 'me'; @@ -112,9 +112,9 @@ sub _render_slice { ? Select( \@outside_select_list, compose { - Order($order_map{$b->{by}}, $b->{reverse}, $a) + Order($b->{by}, $b->{reverse}, $a) } ( - @order_nodes, + @mapped_order, Alias($default_inside_alias, $_) ) ) @@ -127,13 +127,13 @@ sub _render_slice { @outside_select_list, $dq->{preserve_order} ? (grep @{$_->{elements}} == 1, - @order_map{map $_->{by}, @order_nodes}) + map $_->{by}, @mapped_order) : (), ], compose { - Order($order_map{$b->{by}}, !$b->{reverse}, $a) + Order($b->{by}, !$b->{reverse}, $a) } ( - @order_nodes, + @mapped_order, Alias( $default_inside_alias, Slice(