line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Query::Algebra::Sort |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Algebra::Sort - Algebra class for sorting |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Algebra::Sort version 2.915_01. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Algebra::Sort; |
15
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
186
|
use strict; |
|
36
|
|
|
|
|
62
|
|
|
36
|
|
|
|
|
885
|
|
17
|
36
|
|
|
36
|
|
180
|
use warnings; |
|
36
|
|
|
|
|
65
|
|
|
36
|
|
|
|
|
936
|
|
18
|
36
|
|
|
36
|
|
180
|
no warnings 'redefine'; |
|
36
|
|
|
|
|
66
|
|
|
36
|
|
|
|
|
1267
|
|
19
|
36
|
|
|
36
|
|
188
|
use base qw(RDF::Query::Algebra); |
|
36
|
|
|
|
|
126
|
|
|
36
|
|
|
|
|
2574
|
|
20
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
195
|
use Data::Dumper; |
|
36
|
|
|
|
|
73
|
|
|
36
|
|
|
|
|
1698
|
|
22
|
36
|
|
|
36
|
|
185
|
use Set::Scalar; |
|
36
|
|
|
|
|
66
|
|
|
36
|
|
|
|
|
1250
|
|
23
|
36
|
|
|
36
|
|
178
|
use Log::Log4perl; |
|
36
|
|
|
|
|
64
|
|
|
36
|
|
|
|
|
277
|
|
24
|
36
|
|
|
36
|
|
1728
|
use Scalar::Util qw(blessed); |
|
36
|
|
|
|
|
77
|
|
|
36
|
|
|
|
|
1676
|
|
25
|
36
|
|
|
36
|
|
184
|
use Carp qw(carp croak confess); |
|
36
|
|
|
|
|
73
|
|
|
36
|
|
|
|
|
2005
|
|
26
|
36
|
|
|
36
|
|
190
|
use Time::HiRes qw(gettimeofday tv_interval); |
|
36
|
|
|
|
|
79
|
|
|
36
|
|
|
|
|
321
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
###################################################################### |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our ($VERSION); |
31
|
|
|
|
|
|
|
BEGIN { |
32
|
36
|
|
|
36
|
|
35682
|
$VERSION = '2.915_01'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
###################################################################### |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
40
|
|
|
|
|
|
|
L<RDF::Query::Algebra> class. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=over 4 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item C<new ( $pattern, [ $dir => $expr ] )> |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Returns a new Sort structure. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub new { |
53
|
15
|
|
|
15
|
1
|
34
|
my $class = shift; |
54
|
15
|
|
|
|
|
26
|
my $pattern = shift; |
55
|
15
|
|
|
|
|
33
|
my @orderby = @_; |
56
|
15
|
|
|
|
|
66
|
return bless( [ $pattern, @orderby ], $class ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item C<< construct_args >> |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Returns a list of arguments that, passed to this class' constructor, |
62
|
|
|
|
|
|
|
will produce a clone of this algebra pattern. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub construct_args { |
67
|
28
|
|
|
28
|
1
|
44
|
my $self = shift; |
68
|
28
|
|
|
|
|
72
|
my $pattern = $self->pattern; |
69
|
28
|
|
|
|
|
77
|
my @orderby = $self->orderby; |
70
|
28
|
|
|
|
|
85
|
return ($pattern, @orderby); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item C<< pattern >> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Returns the pattern to be sorted. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub pattern { |
80
|
86
|
|
|
86
|
1
|
124
|
my $self = shift; |
81
|
86
|
50
|
|
|
|
199
|
if (@_) { |
82
|
0
|
|
|
|
|
0
|
$self->[0] = shift; |
83
|
|
|
|
|
|
|
} |
84
|
86
|
|
|
|
|
377
|
return $self->[0]; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item C<< orderby >> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns the array of ordering definitions. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub orderby { |
94
|
79
|
|
|
79
|
1
|
132
|
my $self = shift; |
95
|
79
|
|
|
|
|
109
|
my @orderby = @{ $self }[ 1 .. $#{ $self } ]; |
|
79
|
|
|
|
|
167
|
|
|
79
|
|
|
|
|
169
|
|
96
|
79
|
|
|
|
|
190
|
return @orderby; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item C<< sse >> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Returns the SSE string for this algebra expression. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub sse { |
106
|
36
|
|
|
36
|
1
|
56
|
my $self = shift; |
107
|
36
|
|
|
|
|
52
|
my $context = shift; |
108
|
36
|
|
100
|
|
|
127
|
my $prefix = shift || ''; |
109
|
36
|
|
50
|
|
|
99
|
my $indent = $context->{indent} || ' '; |
110
|
|
|
|
|
|
|
|
111
|
36
|
|
|
|
|
49
|
my @order_sse; |
112
|
36
|
|
|
|
|
85
|
my @orderby = $self->orderby; |
113
|
36
|
|
|
|
|
73
|
foreach my $o (@orderby) { |
114
|
36
|
|
|
|
|
84
|
my ($dir, $val) = @$o; |
115
|
36
|
|
|
|
|
188
|
push(@order_sse, sprintf("($dir %s)", $val->sse( $context, "${prefix}${indent}" ))); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
36
|
|
|
|
|
699
|
return sprintf( |
119
|
|
|
|
|
|
|
"(sort\n${prefix}${indent}%s\n${prefix}${indent}%s)", |
120
|
|
|
|
|
|
|
$self->pattern->sse( $context, "${prefix}${indent}" ), |
121
|
|
|
|
|
|
|
join(' ', @order_sse), |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item C<< as_sparql >> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Returns the SPARQL string for this algebra expression. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub as_sparql { |
132
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
133
|
3
|
|
50
|
|
|
10
|
my $context = shift || {}; |
134
|
3
|
|
|
|
|
5
|
my $indent = shift; |
135
|
|
|
|
|
|
|
|
136
|
3
|
100
|
|
|
|
10
|
if ($context->{ skip_sort }) { |
137
|
1
|
|
|
|
|
2
|
$context->{ skip_sort }--; |
138
|
1
|
|
|
|
|
4
|
return $self->pattern->as_sparql( $context, $indent ); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
2
|
|
|
|
|
10
|
my $order_exprs = $self->_as_sparql_order_exprs($context, $indent); |
142
|
|
|
|
|
|
|
|
143
|
2
|
|
|
|
|
8
|
my $string = sprintf( |
144
|
|
|
|
|
|
|
"%s\nORDER BY %s", |
145
|
|
|
|
|
|
|
$self->pattern->as_sparql( $context, $indent ), |
146
|
|
|
|
|
|
|
$order_exprs, |
147
|
|
|
|
|
|
|
); |
148
|
2
|
|
|
|
|
9
|
return $string; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _as_sparql_order_exprs { |
152
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
153
|
3
|
|
|
|
|
6
|
my $context = shift; |
154
|
3
|
|
|
|
|
4
|
my $intent = shift; |
155
|
|
|
|
|
|
|
|
156
|
3
|
|
|
|
|
6
|
my @order_sparql; |
157
|
3
|
|
|
|
|
7
|
my @orderby = $self->orderby; |
158
|
3
|
|
|
|
|
6
|
foreach my $o (@orderby) { |
159
|
3
|
|
|
|
|
8
|
my ($dir, $val) = @$o; |
160
|
3
|
|
|
|
|
9
|
$dir = uc($dir); |
161
|
3
|
50
|
|
|
|
17
|
my $str = ($dir eq 'ASC') |
162
|
|
|
|
|
|
|
? $val->as_sparql( $context ) |
163
|
|
|
|
|
|
|
: sprintf("%s(%s)", $dir, $val->as_sparql( $context )); |
164
|
3
|
|
|
|
|
27
|
push(@order_sparql, $str); |
165
|
|
|
|
|
|
|
} |
166
|
3
|
|
|
|
|
12
|
return join(' ', @order_sparql); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item C<< as_hash >> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Returns the query as a nested set of plain data structures (no objects). |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub as_hash { |
176
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
177
|
0
|
|
|
|
|
0
|
my $context = shift; |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
0
|
my @order = $self->orderby; |
180
|
0
|
|
|
|
|
0
|
my @expressions; |
181
|
0
|
|
|
|
|
0
|
foreach my $o (@order) { |
182
|
0
|
|
|
|
|
0
|
push(@expressions, { type => 'comparator', direction => $o->[0], expression => $o->[1]->as_hash }); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
return { |
186
|
0
|
|
|
|
|
0
|
type => lc($self->type), |
187
|
|
|
|
|
|
|
pattern => $self->pattern->as_hash, |
188
|
|
|
|
|
|
|
order => \@expressions, |
189
|
|
|
|
|
|
|
}; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item C<< type >> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Returns the type of this algebra expression. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub type { |
199
|
0
|
|
|
0
|
1
|
0
|
return 'SORT'; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item C<< referenced_variables >> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub referenced_variables { |
209
|
6
|
|
|
6
|
1
|
8
|
my $self = shift; |
210
|
6
|
|
|
|
|
16
|
return RDF::Query::_uniq($self->pattern->referenced_variables); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item C<< potentially_bound >> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression that will |
216
|
|
|
|
|
|
|
bind values during execution. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub potentially_bound { |
221
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
222
|
0
|
|
|
|
|
|
return RDF::Query::_uniq($self->pattern->potentially_bound); |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item C<< definite_variables >> |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Returns a list of the variable names that will be bound after evaluating this algebra expression. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=cut |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub definite_variables { |
232
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
233
|
0
|
|
|
|
|
|
return $self->pattern->definite_variables; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item C<< is_solution_modifier >> |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Returns true if this node is a solution modifier. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub is_solution_modifier { |
243
|
0
|
|
|
0
|
1
|
|
return 1; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
__END__ |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=back |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head1 AUTHOR |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=cut |