| RDF-Query documentation | Contained in the RDF-Query distribution. |
RDF::Query::Plan::Union - Executable query plan for unions.
This document describes RDF::Query::Plan::Union version 2.907.
Beyond the methods documented below, this class inherits methods from the RDF::Query::Plan class.
new ( $lhs, $rhs )execute ( $execution_context )nextcloselhsReturns the left-hand-side plan to the union.
rhsReturns the right-hand-side plan to the union.
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::Union # -----------------------------------------------------------------------------
package RDF::Query::Plan::Union; use strict; use warnings; use base qw(RDF::Query::Plan); use Scalar::Util qw(blessed refaddr); use RDF::Query::ExecutionContext; ###################################################################### our ($VERSION); BEGIN { $VERSION = '2.907'; } ######################################################################
sub new { my $class = shift; my ($lhs, $rhs) = @_; my $self = $class->SUPER::new( [ $lhs, $rhs ] ); my %vars; foreach my $v ($lhs->referenced_variables, $rhs->referenced_variables) { $vars{ $v }++; } $self->[0]{referenced_variables} = [ keys %vars ]; return $self; }
sub execute ($) { my $self = shift; my $context = shift; if ($self->state == $self->OPEN) { throw RDF::Query::Error::ExecutionError -text => "BGP plan can't be executed while already open"; } my $iter = $self->[1][0]; $iter->execute( $context ); if ($iter->state == $self->OPEN) { $self->[0]{iter} = $iter; $self->[0]{idx} = 0; $self->[0]{context} = $context; $self->state( $self->OPEN ); } else { warn "no iterator in execute()"; } $self; }
sub next { my $self = shift; my $l = Log::Log4perl->get_logger("rdf.query.plan.union"); unless ($self->state == $self->OPEN) { throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open BGP"; } my $iter = $self->[0]{iter}; return undef unless ($iter); my $row = $iter->next; if (defined($row)) { $l->trace( "union row: $row" ); return $row; } else { $self->[0]{iter} = undef; if ($self->[0]{idx} < $#{ $self->[1] }) { $iter->close(); $self->[0]{idx}++; my $index = $self->[0]{idx}; my $iter = $self->[1][ $index ]; $iter->execute( $self->[0]{context} ); if ($iter->state == $self->OPEN) { $l->trace( "union moving to next branch" ); $self->[0]{iter} = $iter; return $self->next; } else { throw RDF::Query::Error::ExecutionError -text => "execute() on RHS of UNION failed during next()"; } } else { $l->trace( "union reached end of last branch" ); $iter->close(); delete $self->[0]{iter}; return undef; } } }
sub close { my $self = shift; unless ($self->state == $self->OPEN) { throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open BGP"; } if (my $iter = $self->[0]{iter}) { $iter->close(); delete $self->[0]{iter}; delete $self->[0]{idx}; } $self->SUPER::close(); }
sub lhs { my $self = shift; return $self->[1][0]; }
sub rhs { my $self = shift; return $self->[1][1]; }
sub distinct { return 0; }
sub ordered { return []; }
sub plan_node_name { return 'union'; }
sub plan_prototype { my $self = shift; return qw(P P); }
sub plan_node_data { my $self = shift; my $expr = $self->[2]; return ($self->lhs, $self->rhs); }
sub graph { my $self = shift; my $g = shift; my ($l, $r) = map { $_->graph( $g ) } ($self->lhs, $self->rhs); $g->add_node( "$self", label => "Union" . $self->graph_labels ); $g->add_edge( "$self", $l ); $g->add_edge( "$self", $r ); return "$self"; } 1; __END__