/usr/share/perl5/RDF/Query/Plan/ThresholdUnion.pm is in librdf-query-perl 2.916-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | # RDF::Query::Plan::ThresholdUnion
# -----------------------------------------------------------------------------
=head1 NAME
RDF::Query::Plan::ThresholdUnion - Executable query plan for unions.
=head1 VERSION
This document describes RDF::Query::Plan::ThresholdUnion version 2.916.
=head1 METHODS
Beyond the methods documented below, this class inherits methods from the
L<RDF::Query::Plan> class.
=over 4
=cut
package RDF::Query::Plan::ThresholdUnion;
use strict;
use warnings;
use base qw(RDF::Query::Plan);
use Time::HiRes qw(time);
use Scalar::Util qw(blessed);
use RDF::Query::ExecutionContext;
######################################################################
our ($VERSION);
BEGIN {
$VERSION = '2.916';
}
######################################################################
=item C<< new ( $time, @plans ) >>
=cut
sub new {
my $class = shift;
my $time = shift;
my @plans = @_;
my $self = $class->SUPER::new( $time, \@plans );
my %vars;
foreach my $plan (@plans) {
foreach my $v ($plan->referenced_variables) {
$vars{ $v }++;
}
}
$self->[0]{referenced_variables} = [ keys %vars ];
return $self;
}
=item C<< execute ( $execution_context ) >>
=cut
sub execute ($) {
my $self = shift;
my $context = shift;
$self->[0]{delegate} = $context->delegate;
if ($self->state == $self->OPEN) {
throw RDF::Query::Error::ExecutionError -text => "ThresholdUnion plan can't be executed while already open";
}
my $l = Log::Log4perl->get_logger("rdf.query.plan.thresholdunion");
my $iter = $self->[2][0];
$l->trace("threshold union initialized with first sub-plan: " . $iter->sse);
$iter->execute( $context );
if ($iter->state == $self->OPEN) {
$self->[0]{iter} = $iter;
$self->[0]{idx} = 0;
$self->[0]{context} = $context;
$self->[0]{start_time} = time;
$self->state( $self->OPEN );
} else {
warn "no iterator in execute()";
}
$self;
}
=item C<< next >>
=cut
sub next {
my $self = shift;
unless ($self->state == $self->OPEN) {
throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open ThresholdUnion";
}
my $iter = $self->[0]{iter};
my $row = $iter->next;
my $l = Log::Log4perl->get_logger("rdf.query.plan.thresholdunion");
if ($row) {
if (my $d = $self->delegate) {
$d->log_result( $self, $row );
}
return $row;
} else {
$l->trace("thresholdunion sub-plan finished");
delete $self->[0]{iter};
return undef unless ($self->[0]{idx} < $#{ $self->[2] });
$iter->close();
my $iter;
my $index;
my $threshold = $self->threshold_time;
my $elapsed = time - $self->[0]{start_time};
if (($threshold == 0) or ($elapsed < $threshold)) {
# we haven't passed the threshold of execution time, so go on
# to the next optimistic plan:
$l->trace("the elapsed time ($elapsed) hasn't passed the threshold time ($threshold); continuing to next plan");
$index = ++$self->[0]{idx};
$iter = $self->[2][ $index ];
} else {
# the elapsed time has passed the threshold time, so jump straight to the default plan
$l->trace("the elapsed time ($elapsed) has passed the threshold time ($threshold); jumping to the default plan");
$index = ($self->[0]{idx} = $#{ $self->[2] });
$iter = $self->[2][ $index ];
}
$l->trace("threshold union executing next sub-plan: " . $iter->sse);
$iter->execute( $self->[0]{context} );
if ($iter->state == $self->OPEN) {
$self->[0]{iter} = $iter;
my $bindings = $self->next;
if (my $d = $self->delegate) {
$d->log_result( $self, $bindings );
}
return $bindings;
} else {
throw RDF::Query::Error::ExecutionError -text => "execute() on child [${index}] of UNION failed during next()";
}
}
}
=item C<< close >>
=cut
sub close {
my $self = shift;
unless ($self->state == $self->OPEN) {
throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open ThresholdUnion";
}
if ($self->[0]{iter}) {
$self->[0]{iter}->close();
delete $self->[0]{iter};
}
$self->SUPER::close();
}
=item C<< children >>
=cut
sub children {
my $self = shift;
return @{ $self->[2] };
}
=item C<< threshold_time >>
=cut
sub threshold_time {
my $self = shift;
return $self->[1];
}
=item C<< optimistic >>
=cut
sub optimistic {
my $self = shift;
return @{ $self->[2] }[ 0 .. $#{ $self->[2] } - 1 ];
}
=item C<< default >>
=cut
sub default {
my $self = shift;
return $self->[2][ $#{ $self->[2] } ];
}
=item C<< distinct >>
Returns true if the pattern is guaranteed to return distinct results.
=cut
sub distinct {
return 0;
}
=item C<< ordered >>
Returns true if the pattern is guaranteed to return ordered results.
=cut
sub ordered {
return [];
}
=item C<< plan_node_name >>
Returns the string name of this plan node, suitable for use in serialization.
=cut
sub plan_node_name {
return 'threshold-union';
}
=item C<< plan_prototype >>
Returns a list of scalar identifiers for the type of the content (children)
nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable
identifiers.
=cut
sub plan_prototype {
my $self = shift;
return qw(i *P);
}
=item C<< plan_node_data >>
Returns the data for this plan node that corresponds to the values described by
the signature returned by C<< plan_prototype >>.
=cut
sub plan_node_data {
my $self = shift;
my $exprs = $self->[2];
return ($self->threshold_time, $self->children);
}
=item C<< graph ( $g ) >>
=cut
sub graph {
my $self = shift;
my $g = shift;
my (@children) = map { $_->graph( $g ) } ($self->children);
$g->add_node( "$self", label => "Threshold Union" . $self->graph_labels );
$g->add_edge( "$self", $_ ) for (@children);
return "$self";
}
1;
__END__
=back
=head1 AUTHOR
Gregory Todd Williams <gwilliams@cpan.org>
=cut
|