line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Query::Plan::Filter |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Plan::Filter - Executable query plan for Filters. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Plan::Filter version 2.915_01. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 METHODS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
15
|
|
|
|
|
|
|
L<RDF::Query::Plan> class. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=over 4 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package RDF::Query::Plan::Filter; |
22
|
|
|
|
|
|
|
|
23
|
35
|
|
|
35
|
|
189
|
use strict; |
|
35
|
|
|
|
|
81
|
|
|
35
|
|
|
|
|
959
|
|
24
|
35
|
|
|
35
|
|
184
|
use warnings; |
|
35
|
|
|
|
|
73
|
|
|
35
|
|
|
|
|
1022
|
|
25
|
35
|
|
|
35
|
|
179
|
use base qw(RDF::Query::Plan); |
|
35
|
|
|
|
|
73
|
|
|
35
|
|
|
|
|
2506
|
|
26
|
35
|
|
|
35
|
|
198
|
use RDF::Query::Error qw(:try); |
|
35
|
|
|
|
|
103
|
|
|
35
|
|
|
|
|
311
|
|
27
|
35
|
|
|
35
|
|
5128
|
use Scalar::Util qw(blessed); |
|
35
|
|
|
|
|
73
|
|
|
35
|
|
|
|
|
2332
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
###################################################################### |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our ($VERSION); |
32
|
|
|
|
|
|
|
BEGIN { |
33
|
35
|
|
|
35
|
|
14002
|
$VERSION = '2.915_01'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
###################################################################### |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item C<< new ( $plan, $expr, $active_graph ) >> |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
43
|
37
|
|
|
37
|
1
|
63
|
my $class = shift; |
44
|
37
|
|
|
|
|
62
|
my $expr = shift; |
45
|
37
|
|
|
|
|
63
|
my $plan = shift; |
46
|
37
|
|
|
|
|
54
|
my $graph = shift; |
47
|
37
|
|
|
|
|
175
|
my $self = $class->SUPER::new( $expr, $plan, $graph ); |
48
|
37
|
|
|
|
|
195
|
$self->[0]{referenced_variables} = [ $plan->referenced_variables ]; |
49
|
37
|
|
|
|
|
162
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item C<< execute ( $execution_context ) >> |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub execute ($) { |
57
|
37
|
|
|
37
|
1
|
69
|
my $self = shift; |
58
|
37
|
|
|
|
|
64
|
my $context = shift; |
59
|
37
|
|
|
|
|
128
|
$self->[0]{delegate} = $context->delegate; |
60
|
37
|
50
|
|
|
|
157
|
if ($self->state == $self->OPEN) { |
61
|
0
|
|
|
|
|
0
|
throw RDF::Query::Error::ExecutionError -text => "FILTER plan can't be executed while already open"; |
62
|
|
|
|
|
|
|
} |
63
|
37
|
|
|
|
|
85
|
my $plan = $self->[2]; |
64
|
37
|
|
|
|
|
182
|
$plan->execute( $context ); |
65
|
37
|
|
|
|
|
170
|
my $l = Log::Log4perl->get_logger("rdf.query.plan.filter"); |
66
|
|
|
|
|
|
|
|
67
|
37
|
50
|
|
|
|
4439
|
if ($plan->state == $self->OPEN) { |
68
|
37
|
|
|
|
|
162
|
$self->state( $self->OPEN ); |
69
|
37
|
|
|
|
|
76
|
my $expr = $self->[1]; |
70
|
37
|
|
|
|
|
191
|
my $bool = RDF::Query::Node::Resource->new( "sparql:ebv" ); |
71
|
37
|
|
|
|
|
678
|
my $filter = RDF::Query::Expression::Function->new( $bool, $expr ); |
72
|
37
|
50
|
|
|
|
130
|
if ($l->is_trace) { |
73
|
0
|
|
|
|
|
0
|
$l->trace("filter constructed for " . $expr->sse({}, '')); |
74
|
|
|
|
|
|
|
} |
75
|
37
|
|
|
|
|
388
|
my $query = $context->query; |
76
|
37
|
|
|
|
|
136
|
my $bridge = $context->model; |
77
|
|
|
|
|
|
|
$self->[0]{filter} = sub { |
78
|
82
|
|
|
82
|
|
125
|
my $row = shift; |
79
|
82
|
|
|
|
|
114
|
my $bool = 0; |
80
|
|
|
|
|
|
|
try { |
81
|
82
|
|
|
|
|
2626
|
my $qok = ref($query); |
82
|
82
|
|
|
|
|
260
|
local($query->{_query_row_cache}) = {}; |
83
|
82
|
50
|
|
|
|
198
|
unless ($qok) { |
84
|
|
|
|
|
|
|
# $query may not be defined, but the local() call will autovivify it into a HASH. |
85
|
|
|
|
|
|
|
# later on, if it's a ref, somebody's going to try to call a method on it, so |
86
|
|
|
|
|
|
|
# undef it if it wasn't defined before the local() call. |
87
|
0
|
|
|
|
|
0
|
$query = undef; |
88
|
|
|
|
|
|
|
} |
89
|
82
|
|
|
|
|
226
|
my $value = $filter->evaluate( $query, $row, $context, $self->active_graph ); |
90
|
82
|
100
|
|
|
|
263
|
$bool = ($value->literal_value eq 'true') ? 1 : 0; |
91
|
|
|
|
|
|
|
} catch RDF::Query::Error with { |
92
|
0
|
|
|
|
|
0
|
my $e = shift; |
93
|
35
|
|
|
35
|
|
216
|
no warnings 'uninitialized'; |
|
35
|
|
|
|
|
77
|
|
|
35
|
|
|
|
|
22157
|
|
94
|
0
|
|
|
|
|
0
|
$l->debug( 'exception thrown during filter evaluation: ' . $e->text ); |
95
|
|
|
|
|
|
|
} otherwise { |
96
|
0
|
|
|
|
|
0
|
$l->debug( 'error during filter evaluation: ' . $@); |
97
|
82
|
|
|
|
|
781
|
}; |
98
|
82
|
|
|
|
|
1649
|
return $bool; |
99
|
37
|
|
|
|
|
288
|
}; |
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
|
|
|
|
0
|
warn "could not execute plan in filter"; |
102
|
|
|
|
|
|
|
} |
103
|
37
|
|
|
|
|
124
|
$self; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item C<< next >> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub next { |
111
|
80
|
|
|
80
|
1
|
127
|
my $self = shift; |
112
|
80
|
50
|
|
|
|
240
|
unless ($self->state == $self->OPEN) { |
113
|
0
|
|
|
|
|
0
|
throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open FILTER"; |
114
|
|
|
|
|
|
|
} |
115
|
80
|
|
|
|
|
147
|
my $plan = $self->[2]; |
116
|
80
|
|
|
|
|
137
|
my $filter = $self->[0]{filter}; |
117
|
80
|
|
|
|
|
305
|
my $l = Log::Log4perl->get_logger("rdf.query.plan.filter"); |
118
|
80
|
|
|
|
|
1413
|
while (1) { |
119
|
109
|
|
|
|
|
598
|
my $row = $plan->next; |
120
|
109
|
100
|
|
|
|
308
|
unless (defined($row)) { |
121
|
27
|
|
|
|
|
105
|
$l->debug("no remaining rows in filter"); |
122
|
27
|
|
|
|
|
216
|
return; |
123
|
|
|
|
|
|
|
} |
124
|
82
|
50
|
|
|
|
273
|
if ($l->is_trace) { |
125
|
0
|
|
|
|
|
0
|
$l->trace("filter processing bindings $row"); |
126
|
|
|
|
|
|
|
} |
127
|
82
|
100
|
|
|
|
573
|
if ($filter->( $row )) { |
128
|
53
|
|
|
|
|
181
|
$l->trace( "- filter returned true on row" ); |
129
|
53
|
50
|
|
|
|
508
|
if (my $d = $self->delegate) { |
130
|
0
|
|
|
|
|
0
|
$d->log_result( $self, $row ); |
131
|
|
|
|
|
|
|
} |
132
|
53
|
|
|
|
|
199
|
return $row; |
133
|
|
|
|
|
|
|
} else { |
134
|
29
|
|
|
|
|
102
|
$l->trace( "- filter returned false on row" ); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item C<< close >> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub close { |
144
|
33
|
|
|
33
|
1
|
58
|
my $self = shift; |
145
|
33
|
50
|
|
|
|
114
|
unless ($self->state == $self->OPEN) { |
146
|
0
|
|
|
|
|
0
|
throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open FILTER"; |
147
|
|
|
|
|
|
|
} |
148
|
33
|
|
|
|
|
587
|
delete $self->[0]{filter}; |
149
|
33
|
50
|
|
|
|
337
|
if (blessed($self->pattern)) { |
150
|
33
|
|
|
|
|
87
|
$self->pattern->close(); |
151
|
|
|
|
|
|
|
} |
152
|
33
|
|
|
|
|
160
|
$self->SUPER::close(); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item C<< pattern >> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns the query plan that will be used to produce the data to be filtered. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub pattern { |
162
|
135
|
|
|
135
|
1
|
193
|
my $self = shift; |
163
|
135
|
|
|
|
|
590
|
return $self->[2]; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item C<< active_graph >> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns the active graph. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub active_graph { |
173
|
82
|
|
|
82
|
1
|
113
|
my $self = shift; |
174
|
82
|
|
|
|
|
389
|
return $self->[3]; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item C<< distinct >> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Returns true if the pattern is guaranteed to return distinct results. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub distinct { |
184
|
35
|
|
|
35
|
1
|
59
|
my $self = shift; |
185
|
35
|
|
|
|
|
112
|
return $self->pattern->distinct; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item C<< ordered >> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Returns true if the pattern is guaranteed to return ordered results. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub ordered { |
195
|
34
|
|
|
34
|
1
|
55
|
my $self = shift; |
196
|
34
|
|
|
|
|
87
|
return $self->pattern->ordered; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item C<< plan_node_name >> |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Returns the string name of this plan node, suitable for use in serialization. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub plan_node_name { |
206
|
0
|
|
|
0
|
1
|
|
return 'filter'; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item C<< plan_prototype >> |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Returns a list of scalar identifiers for the type of the content (children) |
212
|
|
|
|
|
|
|
nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable |
213
|
|
|
|
|
|
|
identifiers. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub plan_prototype { |
218
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
219
|
0
|
|
|
|
|
|
return qw(E P); |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item C<< plan_node_data >> |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Returns the data for this plan node that corresponds to the values described by |
225
|
|
|
|
|
|
|
the signature returned by C<< plan_prototype >>. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub plan_node_data { |
230
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
231
|
0
|
|
|
|
|
|
my $expr = $self->[1]; |
232
|
0
|
|
|
|
|
|
return ($expr, $self->pattern); |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
1; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
__END__ |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=back |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 AUTHOR |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |