| 1 | # RDF::Query::Plan::Distinct | ||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||
| 3 | |||||||||||
| 4 | =head1 NAME | ||||||||||
| 5 | |||||||||||
| 6 | RDF::Query::Plan::Distinct - Executable query plan for Distincts. | ||||||||||
| 7 | |||||||||||
| 8 | =head1 VERSION | ||||||||||
| 9 | |||||||||||
| 10 | This document describes RDF::Query::Plan::Distinct 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::Distinct; | ||||||||||
| 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 base qw(RDF::Query::Plan); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | ###################################################################### | ||||||||||
| 28 | |||||||||||
| 29 | 35 | our ($VERSION); | |||||||||
| 30 | 35 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 35 | $VERSION = '2.919'; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | ###################################################################### | ||||||||||
| 35 | |||||||||||
| 36 | =item C<< new ( $plan ) >> | ||||||||||
| 37 | |||||||||||
| 38 | =cut | ||||||||||
| 39 | |||||||||||
| 40 | 10 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 41 | 10 | my $class = shift; | |||||||||
| 42 | 10 | my $plan = shift; | |||||||||
| 43 | 10 | my $self = $class->SUPER::new( $plan ); | |||||||||
| 44 | 10 | $self->[0]{referenced_variables} = [ $plan->referenced_variables ]; | |||||||||
| 45 | 10 | return $self; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | =item C<< execute ( $execution_context ) >> | ||||||||||
| 49 | |||||||||||
| 50 | =cut | ||||||||||
| 51 | |||||||||||
| 52 | 10 | ▶ | sub execute ($) { | ||||||||
|
Subroutine
execute: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||
| 53 | 10 | my $self = shift; | |||||||||
| 54 | 10 | my $context = shift; | |||||||||
| 55 | 10 | $self->[0]{delegate} = $context->delegate; | |||||||||
| 56 | 10 | ▶ | if ($self->state == $self->OPEN) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | throw RDF::Query::Error::ExecutionError -text => "DISTINCT plan can't be executed while already open"; | |||||||||
| 58 | } | ||||||||||
| 59 | 10 | my $plan = $self->[1]; | |||||||||
| 60 | 10 | $plan->execute( $context ); | |||||||||
| 61 | |||||||||||
| 62 | 10 | ▶ | if ($plan->state == $self->OPEN) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 10 | $self->[0]{seen} = {}; | |||||||||
| 64 | 10 | $self->state( $self->OPEN ); | |||||||||
| 65 | } else { | ||||||||||
| 66 | 0 | warn "could not execute plan in distinct"; | |||||||||
| 67 | } | ||||||||||
| 68 | 10 | $self; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | =item C<< next >> | ||||||||||
| 72 | |||||||||||
| 73 | =cut | ||||||||||
| 74 | |||||||||||
| 75 | 30 | ▶ | sub next { | ||||||||
|
Subroutine
next: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||
| 76 | 30 | my $self = shift; | |||||||||
| 77 | 30 | ▶ | unless ($self->state == $self->OPEN) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open DISTINCT"; | |||||||||
| 79 | } | ||||||||||
| 80 | 30 | my $plan = $self->[1]; | |||||||||
| 81 | 30 | while (1) { | |||||||||
| 82 | 33 | my $row = $plan->next; | |||||||||
| 83 | 33 | ▶ | return undef unless ($row); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 26 | ▶ | if (not $self->[0]{seen}{ $row->as_string }++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 23 | ▶ | if (my $d = $self->delegate) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | $d->log_result( $self, $row ); | |||||||||
| 87 | } | ||||||||||
| 88 | 23 | return $row; | |||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | =item C<< close >> | ||||||||||
| 94 | |||||||||||
| 95 | =cut | ||||||||||
| 96 | |||||||||||
| 97 | 10 | ▶ | sub close { | ||||||||
|
Subroutine
close: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 98 | 10 | my $self = shift; | |||||||||
| 99 | 10 | ▶ | unless ($self->state == $self->OPEN) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open DISTINCT"; | |||||||||
| 101 | } | ||||||||||
| 102 | 10 | delete $self->[0]{seen}; | |||||||||
| 103 | 10 | $self->[1]->close(); | |||||||||
| 104 | 10 | $self->SUPER::close(); | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | =item C<< pattern >> | ||||||||||
| 108 | |||||||||||
| 109 | Returns the query plan that will be used to produce the data to be made distinct. | ||||||||||
| 110 | |||||||||||
| 111 | =cut | ||||||||||
| 112 | |||||||||||
| 113 | 10 | ▶ | sub pattern { | ||||||||
|
Subroutine
pattern: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 114 | 10 | my $self = shift; | |||||||||
| 115 | 10 | return $self->[1]; | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | =item C<< distinct >> | ||||||||||
| 119 | |||||||||||
| 120 | Returns true if the pattern is guaranteed to return distinct results. | ||||||||||
| 121 | |||||||||||
| 122 | =cut | ||||||||||
| 123 | |||||||||||
| 124 | 10 | ▶ | sub distinct { | ||||||||
|
Subroutine
distinct: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 125 | 10 | return 1; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | =item C<< ordered >> | ||||||||||
| 129 | |||||||||||
| 130 | Returns true if the pattern is guaranteed to return ordered results. | ||||||||||
| 131 | |||||||||||
| 132 | =cut | ||||||||||
| 133 | |||||||||||
| 134 | 10 | ▶ | sub ordered { | ||||||||
|
Subroutine
ordered: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 135 | 10 | my $self = shift; | |||||||||
| 136 | 10 | return $self->pattern->ordered; | |||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | =item C<< plan_node_name >> | ||||||||||
| 140 | |||||||||||
| 141 | Returns the string name of this plan node, suitable for use in serialization. | ||||||||||
| 142 | |||||||||||
| 143 | =cut | ||||||||||
| 144 | |||||||||||
| 145 | 0 | ▶ | sub plan_node_name { | ||||||||
|
Subroutine
plan_node_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 146 | 0 | return 'distinct'; | |||||||||
| 147 | } | ||||||||||
| 148 | |||||||||||
| 149 | =item C<< plan_prototype >> | ||||||||||
| 150 | |||||||||||
| 151 | Returns a list of scalar identifiers for the type of the content (children) | ||||||||||
| 152 | nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable | ||||||||||
| 153 | identifiers. | ||||||||||
| 154 | |||||||||||
| 155 | =cut | ||||||||||
| 156 | |||||||||||
| 157 | 0 | ▶ | sub plan_prototype { | ||||||||
|
Subroutine
plan_prototype: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 158 | 0 | my $self = shift; | |||||||||
| 159 | 0 | return qw(P); | |||||||||
| 160 | } | ||||||||||
| 161 | |||||||||||
| 162 | =item C<< plan_node_data >> | ||||||||||
| 163 | |||||||||||
| 164 | Returns the data for this plan node that corresponds to the values described by | ||||||||||
| 165 | the signature returned by C<< plan_prototype >>. | ||||||||||
| 166 | |||||||||||
| 167 | =cut | ||||||||||
| 168 | |||||||||||
| 169 | 0 | ▶ | sub plan_node_data { | ||||||||
|
Subroutine
plan_node_data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 170 | 0 | my $self = shift; | |||||||||
| 171 | 0 | return ($self->pattern); | |||||||||
| 172 | } | ||||||||||
| 173 | |||||||||||
| 174 | =item C<< graph ( $g ) >> | ||||||||||
| 175 | |||||||||||
| 176 | =cut | ||||||||||
| 177 | |||||||||||
| 178 | 0 | ▶ | sub graph { | ||||||||
|
Subroutine
graph: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 179 | 0 | my $self = shift; | |||||||||
| 180 | 0 | my $g = shift; | |||||||||
| 181 | 0 | my $c = $self->pattern->graph( $g ); | |||||||||
| 182 | 0 | $g->add_node( "$self", label => "Distinct" . $self->graph_labels ); | |||||||||
| 183 | 0 | $g->add_edge( "$self", $c ); | |||||||||
| 184 | 0 | return "$self"; | |||||||||
| 185 | } | ||||||||||
| 186 | |||||||||||
| 187 | |||||||||||
| 188 | 35 | 1; | |||||||||
| 189 | |||||||||||
| 190 | __END__ | ||||||||||