| RDF-Query documentation | Contained in the RDF-Query distribution. |
RDF::Query::Plan::Offset - Executable query plan for Offsets.
This document describes RDF::Query::Plan::Offset version 2.907.
Beyond the methods documented below, this class inherits methods from the RDF::Query::Plan class.
new ( $plan, $offset )execute ( $execution_context )nextclosepatternReturns the query plan that will be used to produce the data to be offset.
offsetReturns the number of results that are discarded as offset.
distinctReturns true if the pattern is guaranteed to return distinct results.
orderedReturns true if the pattern is guaranteed to return ordered results.
plan_node_nameReturns the string name of this plan node, suitable for use in serialization.
plan_prototypeReturns a list of scalar identifiers for the type of the content (children) nodes of this plan node. See RDF::Query::Plan for a list of the allowable identifiers.
plan_node_dataReturns the data for this plan node that corresponds to the values described by
the signature returned by plan_prototype.
graph ( $g )Gregory Todd Williams <gwilliams@cpan.org>
| RDF-Query documentation | Contained in the RDF-Query distribution. |
# RDF::Query::Plan::Offset # -----------------------------------------------------------------------------
package RDF::Query::Plan::Offset; use strict; use warnings; use base qw(RDF::Query::Plan); ###################################################################### our ($VERSION); BEGIN { $VERSION = '2.907'; } ######################################################################
sub new { my $class = shift; my $offset = shift; my $plan = shift; my $self = $class->SUPER::new( $offset, $plan ); $self->[0]{referenced_variables} = [ $plan->referenced_variables ]; return $self; }
sub execute ($) { my $self = shift; my $context = shift; if ($self->state == $self->OPEN) { throw RDF::Query::Error::ExecutionError -text => "OFFSET plan can't be executed while already open"; } my $plan = $self->[2]; $self->[0]{exhausted} = 0; $plan->execute( $context ); if ($plan->state == $self->OPEN) { $self->state( $self->OPEN ); for (my $i = 0; $i < $self->offset; $i++) { my $row = $plan->next; if(not(defined($row))) { $self->[0]{exhausted} = 1; last; } } } else { warn "could not execute plan in OFFSET"; } $self; }
sub next { my $self = shift; if ($self->[0]{exhausted}) { return undef; } unless ($self->state == $self->OPEN) { throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open OFFSET"; } my $plan = $self->[2]; my $row = $plan->next; unless ($row) { $self->[0]{exhausted} = 1; return undef; } return $row; }
sub close { my $self = shift; unless ($self->state == $self->OPEN) { throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open OFFSET"; } $self->[2]->close(); $self->SUPER::close(); }
sub pattern { my $self = shift; return $self->[2]; }
sub offset { my $self = shift; return $self->[1]; }
sub distinct { my $self = shift; return $self->pattern->distinct; }
sub ordered { my $self = shift; return $self->pattern->ordered; }
sub plan_node_name { return 'offset'; }
sub plan_prototype { my $self = shift; return qw(i P); }
sub plan_node_data { my $self = shift; return ($self->offset, $self->pattern); }
sub graph { my $self = shift; my $g = shift; my $c = $self->pattern->graph( $g ); $g->add_node( "$self", label => "Offset ($self->[1])" . $self->graph_labels ); $g->add_edge( "$self", $c ); return "$self"; } 1; __END__