| 1 | # RDF::Query::Plan::Project | ||||||||||||||||||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | RDF::Query::Plan::Project - Executable query plan for Projects. | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | This document describes RDF::Query::Plan::Project version 2.919. | ||||||||||||||||||||||||||||
| 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::Project; | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 35 | ▶ | use Scalar::Util qw(blessed refaddr); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 35 | ▶ | use base qw(RDF::Query::Plan); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | ###################################################################### | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 35 | our ($VERSION); | |||||||||||||||||||||||||||
| 31 | 35 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 35 | $VERSION = '2.919'; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | ###################################################################### | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =item C<< new ( $plan, \@keys ) >> | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 138 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 138 | my $class = shift; | |||||||||||||||||||||||||||
| 43 | 138 | my $plan = shift; | |||||||||||||||||||||||||||
| 44 | 138 | my $keys = shift; | |||||||||||||||||||||||||||
| 45 | 138 | my (@vars, @exprs); | |||||||||||||||||||||||||||
| 46 | 138 | foreach my $k (@$keys) { | |||||||||||||||||||||||||||
| 47 | 231 | ▶ | push(@exprs, $k) if ($k->isa('RDF::Query::Expression')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 231 | ▶ | push(@vars, $k->name) if ($k->isa('RDF::Query::Node::Variable')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 231 | ▶ | push(@vars, $k) if (not(ref($k))); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 138 | my $self = $class->SUPER::new( $plan, \@vars, \@exprs ); | |||||||||||||||||||||||||||
| 52 | 138 | $self->[0]{referenced_variables} = [ $plan->referenced_variables ]; | |||||||||||||||||||||||||||
| 53 | 138 | return $self; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =item C<< execute ( $execution_context ) >> | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 134 | ▶ | sub execute ($) { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 134 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 134 | my $context = shift; | |||||||||||||||||||||||||||
| 63 | 134 | $self->[0]{delegate} = $context->delegate; | |||||||||||||||||||||||||||
| 64 | 134 | ▶ | if ($self->state == $self->OPEN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | throw RDF::Query::Error::ExecutionError -text => "PROJECT plan can't be executed while already open"; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 134 | my $plan = $self->[1]; | |||||||||||||||||||||||||||
| 68 | 134 | $plan->execute( $context ); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 134 | ▶ | if ($plan->state == $self->OPEN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 134 | $self->[0]{context} = $context; | |||||||||||||||||||||||||||
| 72 | 134 | $self->state( $self->OPEN ); | |||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||
| 74 | 0 | warn "could not execute plan in PROJECT"; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 134 | $self; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =item C<< next >> | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 304 | ▶ | sub next { | ||||||||||||||||||||||||||
|
Subroutine
next: called CC=7 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 304 | my $self = shift; | |||||||||||||||||||||||||||
| 85 | 304 | my $ctx = $self->[0]{context}; | |||||||||||||||||||||||||||
| 86 | 304 | ▶ | unless ($self->state == $self->OPEN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open PROJECT"; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 304 | my $l = Log::Log4perl->get_logger("rdf.query.plan.project"); | |||||||||||||||||||||||||||
| 91 | 304 | my $plan = $self->[1]; | |||||||||||||||||||||||||||
| 92 | 304 | my $row = $plan->next; | |||||||||||||||||||||||||||
| 93 | 304 | ▶ | unless (defined($row)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 95 | $l->trace("no remaining rows in project"); | |||||||||||||||||||||||||||
| 95 | # if ($self->[1]->state == $self->[1]->OPEN) { | ||||||||||||||||||||||||||||
| 96 | # $self->[1]->close(); | ||||||||||||||||||||||||||||
| 97 | # } | ||||||||||||||||||||||||||||
| 98 | 95 | return; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 209 | ▶ | if ($l->is_trace) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | $l->trace( "project on row $row" ); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 209 | my $keys = $self->[2]; | |||||||||||||||||||||||||||
| 105 | 209 | my $exprs = $self->[3]; | |||||||||||||||||||||||||||
| 106 | 209 | my $query = $self->[0]{context}->query; | |||||||||||||||||||||||||||
| 107 | 209 | my $bridge = $self->[0]{context}->model; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 209 | my $proj = $row->project( @{ $keys } ); | |||||||||||||||||||||||||||
| 110 | 209 | foreach my $e (@$exprs) { | |||||||||||||||||||||||||||
| 111 | 0 | my $name = $e->sse; | |||||||||||||||||||||||||||
| 112 | 0 | my $var_or_expr = $e; | |||||||||||||||||||||||||||
| 113 | 0 | my $value = $query->var_or_expr_value( $bridge, $row, $var_or_expr, $ctx ); | |||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ($l->is_trace) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | $l->trace( "- project value $name -> $value" ); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | 0 | $proj->{ $name } = $value; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 209 | $l->trace( "- projected row: $proj" ); | |||||||||||||||||||||||||||
| 121 | 209 | ▶ | if (my $d = $self->delegate) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | $d->log_result( $self, $proj ); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | 209 | return $proj; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =item C<< close >> | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =cut | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 134 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | 134 | my $self = shift; | |||||||||||||||||||||||||||
| 133 | 134 | ▶ | unless ($self->state == $self->OPEN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open PROJECT"; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | 134 | delete $self->[0]{context}; | |||||||||||||||||||||||||||
| 137 | 134 | ▶ | if (blessed($self->[1]) and $self->[1]->state == $self->OPEN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($self->[1]) and $self->[1]->state == $self->OPEN
MC/DC0%0/2
builtin::blessed($self->[1]) and $self->[1]->state == $self->OPEN
builtin::blessed($self->[1])
$self->[1]->state == $self->OPEN
Truth table33%1/3
A and B
A= builtin::blessed($self->[1])B= $self->[1]->state == $self->OPEN
| |||||||||||||||||||||||||||||
| 138 | 134 | $self->[1]->close(); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 134 | $self->SUPER::close(); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =item C<< pattern >> | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | Returns the query plan that will be used to produce the data to be projected. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 259 | ▶ | sub pattern { | ||||||||||||||||||||||||||
|
Subroutine
pattern: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | 259 | my $self = shift; | |||||||||||||||||||||||||||
| 151 | 259 | return $self->[1]; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =item C<< distinct >> | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | Returns true if the pattern is guaranteed to return distinct results. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 123 | ▶ | sub distinct { | ||||||||||||||||||||||||||
|
Subroutine
distinct: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | 123 | my $self = shift; | |||||||||||||||||||||||||||
| 162 | 123 | return $self->pattern->distinct; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =item C<< ordered >> | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Returns true if the pattern is guaranteed to return ordered results. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =cut | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 133 | ▶ | sub ordered { | ||||||||||||||||||||||||||
|
Subroutine
ordered: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 172 | 133 | my $self = shift; | |||||||||||||||||||||||||||
| 173 | 133 | return $self->pattern->ordered; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =item C<< plan_node_name >> | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | Returns the string name of this plan node, suitable for use in serialization. | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =cut | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 2 | ▶ | sub plan_node_name { | ||||||||||||||||||||||||||
|
Subroutine
plan_node_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 183 | 2 | return 'project'; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =item C<< plan_prototype >> | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Returns a list of scalar identifiers for the type of the content (children) | ||||||||||||||||||||||||||||
| 189 | nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable | ||||||||||||||||||||||||||||
| 190 | identifiers. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =cut | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 2 | ▶ | sub plan_prototype { | ||||||||||||||||||||||||||
|
Subroutine
plan_prototype: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 196 | 2 | return qw(\J P); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =item C<< plan_node_data >> | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | Returns the data for this plan node that corresponds to the values described by | ||||||||||||||||||||||||||||
| 202 | the signature returned by C<< plan_prototype >>. | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 3 | ▶ | sub plan_node_data { | ||||||||||||||||||||||||||
|
Subroutine
plan_node_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 207 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 208 | 3 | my @vars = map { RDF::Query::Node::Variable->new( $_ ) } @{$self->[2]}; | |||||||||||||||||||||||||||
| 209 | 3 | my @exprs = @{$self->[3]}; | |||||||||||||||||||||||||||
| 210 | 3 | return ([ @vars, @exprs ], $self->pattern); | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =item C<< graph ( $g ) >> | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | ▶ | sub graph { | ||||||||||||||||||||||||||
|
Subroutine
graph: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 218 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 219 | 0 | my $g = shift; | |||||||||||||||||||||||||||
| 220 | 0 | my $c = $self->pattern->graph( $g ); | |||||||||||||||||||||||||||
| 221 | 0 | ▶ | my $expr = join(' ', @{$self->[2]}, map { blessed($_) ? $_->sse( {}, "" ) : $_ } @{$self->[3]}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 0 | $g->add_node( "$self", label => "Project ($expr)" . $self->graph_labels ); | |||||||||||||||||||||||||||
| 223 | 0 | $g->add_edge( "$self", $c ); | |||||||||||||||||||||||||||
| 224 | 0 | return "$self"; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =item C<< explain >> | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | Returns a string serialization of the plan appropriate for display on the | ||||||||||||||||||||||||||||
| 230 | command line. | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =cut | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | ▶ | sub explain { | ||||||||||||||||||||||||||
|
Subroutine
explain: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 235 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 236 | 0 | ▶ | my $s = shift || ' '; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ' '
MC/DC0%0/1
shift() || ' '
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 237 | 0 | ▶ | my $count = shift || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 238 | 0 | my $indent = $s x $count; | |||||||||||||||||||||||||||
| 239 | 0 | my $type = $self->plan_node_name; | |||||||||||||||||||||||||||
| 240 | 0 | my $string = sprintf("%s%s (0x%x)\n", $indent, $type, refaddr($self)); | |||||||||||||||||||||||||||
| 241 | 0 | my @vars = map { RDF::Query::Node::Variable->new( $_ ) } @{$self->[2]}; | |||||||||||||||||||||||||||
| 242 | 0 | my @exprs = @{$self->[3]}; | |||||||||||||||||||||||||||
| 243 | 0 | $string .= "${indent}${s}" . join(' ', @vars, @exprs) . "\n"; | |||||||||||||||||||||||||||
| 244 | 0 | $string .= $self->pattern->explain( $s, $count+1 ); | |||||||||||||||||||||||||||
| 245 | 0 | return $string; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 35 | 1; | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | __END__ | ||||||||||||||||||||||||||||