RDF::Query::Plan::Join - Join query plan base class.


RDF-Query documentation Contained in the RDF-Query distribution.

Index


Code Index:

NAME

Top

RDF::Query::Plan::Join - Join query plan base class.

VERSION

Top

This document describes RDF::Query::Plan::Join version 2.907.

METHODS

Top

Beyond the methods documented below, this class inherits methods from the RDF::Query::Plan class.

new ( $lhs, $rhs, $optional )
lhs

Returns the left-hand-side plan to the join.

rhs

Returns the right-hand-side plan to the join.

optional
bf ()

Returns a string representing the state of the nodes of the triple (bound or free).

join_classes

Returns the class names of all available join algorithms.

distinct

Returns true if the pattern is guaranteed to return distinct results.

ordered

Returns true if the pattern is guaranteed to return ordered results.

plan_prototype

Returns 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_data

Returns the data for this plan node that corresponds to the values described by the signature returned by plan_prototype.

AUTHOR

Top

 Gregory Todd Williams <gwilliams@cpan.org>


RDF-Query documentation Contained in the RDF-Query distribution.
# RDF::Query::Plan::Join
# -----------------------------------------------------------------------------

package RDF::Query::Plan::Join;

use strict;
use warnings;
use base qw(RDF::Query::Plan);

use Scalar::Util qw(blessed);
use RDF::Query::ExecutionContext;

######################################################################

our ($VERSION);
BEGIN {
	$VERSION	= '2.907';
}

######################################################################

sub new {
	my $class	= shift;
	my $lhs		= shift;
	my $rhs		= shift;
	my $opt		= shift;
	my $self	= $class->SUPER::new( $lhs, $rhs, $opt, @_ );
	
	my %vars;
	my @lhs_rv	= $lhs->referenced_variables;
	my @rhs_rv	= $rhs->referenced_variables;
	foreach my $v (@lhs_rv, @rhs_rv) {
		$vars{ $v }++;
	}
	$self->[0]{referenced_variables}	= [ keys %vars ];
	return $self;
}

sub lhs {
	my $self	= shift;
	return $self->[1];
}

sub rhs {
	my $self	= shift;
	return $self->[2];
}

sub optional {
	my $self	= shift;
	return $self->[3];
}

sub bf {
	my $self	= shift;
	my $context	= shift;
	my @bf;
	my %var_to_num;
	my %use_count;
	my $counter	= 1;
	foreach my $t ($self->lhs, $self->rhs) {
		unless ($t->can('bf')) {
			throw RDF::Query::Error::ExecutionError -text => "Cannot compute bf for $t during join";
		}
		my $bf	= $t->bf( $context );
		if ($bf =~ /f/) {
			$bf	= '';
			foreach my $n ($t->nodes) {
				if ($n->isa('RDF::Trine::Node::Variable')) {
					my $name	= $n->name;
					my $num		= ($var_to_num{ $name } ||= $counter++);
					$use_count{ $name }++;
					$bf	.= "{${num}}";
				} else {
					$bf	.= 'b';
				}
			}
		}
		push(@bf, $bf);
	}
	if ($counter <= 10) {
		for (@bf) {
			s/[{}]//g;
		}
	}
	my $bf	= join(',',@bf);
	return wantarray ? @bf : $bf;
}

sub join_classes {
	my $class	= shift;
	my $config	= shift || {};
	our %JOIN_CLASSES;
	my @classes	= reverse sort keys %JOIN_CLASSES;
	my @ok	= grep { 
		my $name	= lc($_);
		$name	=~ s/::/./g;
		(exists $config->{ $name } and not($config->{ $name }))
			? 0
			: 1
	} @classes;
	return @ok;
}

sub distinct {
	return 0;
}

sub ordered {
	return 0;
}

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);
}


1;

__END__