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.916. |
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
|
|
190
|
use strict; |
|
35
|
|
|
|
|
73
|
|
|
35
|
|
|
|
|
973
|
|
24
|
35
|
|
|
35
|
|
195
|
use warnings; |
|
35
|
|
|
|
|
71
|
|
|
35
|
|
|
|
|
974
|
|
25
|
35
|
|
|
35
|
|
184
|
use base qw(RDF::Query::Plan); |
|
35
|
|
|
|
|
82
|
|
|
35
|
|
|
|
|
2614
|
|
26
|
35
|
|
|
35
|
|
202
|
use RDF::Query::Error qw(:try); |
|
35
|
|
|
|
|
72
|
|
|
35
|
|
|
|
|
285
|
|
27
|
35
|
|
|
35
|
|
5095
|
use Scalar::Util qw(blessed); |
|
35
|
|
|
|
|
84
|
|
|
35
|
|
|
|
|
2441
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
###################################################################### |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our ($VERSION); |
32
|
|
|
|
|
|
|
BEGIN { |
33
|
35
|
|
|
35
|
|
14234
|
$VERSION = '2.916'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
###################################################################### |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item C<< new ( $plan, $expr, $active_graph ) >> |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
43
|
37
|
|
|
37
|
1
|
65
|
my $class = shift; |
44
|
37
|
|
|
|
|
75
|
my $expr = shift; |
45
|
37
|
|
|
|
|
57
|
my $plan = shift; |
46
|
37
|
|
|
|
|
61
|
my $graph = shift; |
47
|
37
|
|
|
|
|
167
|
my $self = $class->SUPER::new( $expr, $plan, $graph ); |
48
|
37
|
|
|
|
|
199
|
$self->[0]{referenced_variables} = [ $plan->referenced_variables ]; |
49
|
37
|
|
|
|
|
188
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item C<< execute ( $execution_context ) >> |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub execute ($) { |
57
|
37
|
|
|
37
|
1
|
72
|
my $self = shift; |
58
|
37
|
|
|
|
|
78
|
my $context = shift; |
59
|
37
|
|
|
|
|
130
|
$self->[0]{delegate} = $context->delegate; |
60
|
37
|
50
|
|
|
|
175
|
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
|
|
|
|
|
84
|
my $plan = $self->[2]; |
64
|
37
|
|
|
|
|
176
|
$plan->execute( $context ); |
65
|
37
|
|
|
|
|
172
|
my $l = Log::Log4perl->get_logger("rdf.query.plan.filter"); |
66
|
|
|
|
|
|
|
|
67
|
37
|
50
|
|
|
|
4549
|
if ($plan->state == $self->OPEN) { |
68
|
37
|
|
|
|
|
153
|
$self->state( $self->OPEN ); |
69
|
37
|
|
|
|
|
76
|
my $expr = $self->[1]; |
70
|
37
|
|
|
|
|
188
|
my $bool = RDF::Query::Node::Resource->new( "sparql:ebv" ); |
71
|
37
|
|
|
|
|
759
|
my $filter = RDF::Query::Expression::Function->new( $bool, $expr ); |
72
|
37
|
50
|
|
|
|
143
|
if ($l->is_trace) { |
73
|
0
|
|
|
|
|
0
|
$l->trace("filter constructed for " . $expr->sse({}, '')); |
74
|
|
|
|
|
|
|
} |
75
|
37
|
|
|
|
|
385
|
my $query = $context->query; |
76
|
37
|
|
|
|
|
147
|
my $bridge = $context->model; |
77
|
|
|
|
|
|
|
$self->[0]{filter} = sub { |
78
|
84
|
|
|
84
|
|
123
|
my $row = shift; |
79
|
84
|
|
|
|
|
118
|
my $bool = 0; |
80
|
|
|
|
|
|
|
try { |
81
|
84
|
|
|
|
|
2877
|
my $qok = ref($query); |
82
|
84
|
|
|
|
|
283
|
local($query->{_query_row_cache}) = {}; |
83
|
84
|
50
|
|
|
|
226
|
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
|
84
|
|
|
|
|
241
|
my $value = $filter->evaluate( $query, $row, $context, $self->active_graph ); |
90
|
84
|
100
|
|
|
|
287
|
$bool = ($value->literal_value eq 'true') ? 1 : 0; |
91
|
|
|
|
|
|
|
} catch RDF::Query::Error with { |
92
|
0
|
|
|
|
|
0
|
my $e = shift; |
93
|
35
|
|
|
35
|
|
213
|
no warnings 'uninitialized'; |
|
35
|
|
|
|
|
85
|
|
|
35
|
|
|
|
|
22409
|
|
94
|
0
|
|
|
|
|
0
|
$l->debug( 'exception thrown during filter evaluation: ' . $e->text ); |
95
|
|
|
|
|
|
|
} otherwise { |
96
|
0
|
|
|
|
|
0
|
$l->debug( 'error during filter evaluation: ' . $@); |
97
|
84
|
|
|
|
|
882
|
}; |
98
|
84
|
|
|
|
|
1845
|
return $bool; |
99
|
37
|
|
|
|
|
296
|
}; |
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
|
|
|
|
0
|
warn "could not execute plan in filter"; |
102
|
|
|
|
|
|
|
} |
103
|
37
|
|
|
|
|
119
|
$self; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item C<< next >> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub next { |
111
|
80
|
|
|
80
|
1
|
132
|
my $self = shift; |
112
|
80
|
50
|
|
|
|
256
|
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
|
|
|
|
|
153
|
my $plan = $self->[2]; |
116
|
80
|
|
|
|
|
170
|
my $filter = $self->[0]{filter}; |
117
|
80
|
|
|
|
|
273
|
my $l = Log::Log4perl->get_logger("rdf.query.plan.filter"); |
118
|
80
|
|
|
|
|
1494
|
while (1) { |
119
|
111
|
|
|
|
|
546
|
my $row = $plan->next; |
120
|
111
|
100
|
|
|
|
338
|
unless (defined($row)) { |
121
|
27
|
|
|
|
|
106
|
$l->debug("no remaining rows in filter"); |
122
|
27
|
|
|
|
|
267
|
return; |
123
|
|
|
|
|
|
|
} |
124
|
84
|
50
|
|
|
|
282
|
if ($l->is_trace) { |
125
|
0
|
|
|
|
|
0
|
$l->trace("filter processing bindings $row"); |
126
|
|
|
|
|
|
|
} |
127
|
84
|
100
|
|
|
|
607
|
if ($filter->( $row )) { |
128
|
53
|
|
|
|
|
195
|
$l->trace( "- filter returned true on row" ); |
129
|
53
|
50
|
|
|
|
532
|
if (my $d = $self->delegate) { |
130
|
0
|
|
|
|
|
0
|
$d->log_result( $self, $row ); |
131
|
|
|
|
|
|
|
} |
132
|
53
|
|
|
|
|
208
|
return $row; |
133
|
|
|
|
|
|
|
} else { |
134
|
31
|
|
|
|
|
122
|
$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
|
80
|
my $self = shift; |
145
|
33
|
50
|
|
|
|
107
|
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
|
|
|
|
|
625
|
delete $self->[0]{filter}; |
149
|
33
|
50
|
|
|
|
362
|
if (blessed($self->pattern)) { |
150
|
33
|
|
|
|
|
104
|
$self->pattern->close(); |
151
|
|
|
|
|
|
|
} |
152
|
33
|
|
|
|
|
147
|
$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
|
201
|
my $self = shift; |
163
|
135
|
|
|
|
|
602
|
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
|
84
|
|
|
84
|
1
|
151
|
my $self = shift; |
174
|
84
|
|
|
|
|
405
|
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
|
73
|
my $self = shift; |
185
|
35
|
|
|
|
|
103
|
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
|
56
|
my $self = shift; |
196
|
34
|
|
|
|
|
97
|
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 |