| 1 | # RDF::Query::Algebra::Sort | ||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||
| 3 | |||||||||||||
| 4 | =head1 NAME | ||||||||||||
| 5 | |||||||||||||
| 6 | RDF::Query::Algebra::Sort - Algebra class for sorting | ||||||||||||
| 7 | |||||||||||||
| 8 | =head1 VERSION | ||||||||||||
| 9 | |||||||||||||
| 10 | This document describes RDF::Query::Algebra::Sort version 2.919. | ||||||||||||
| 11 | |||||||||||||
| 12 | =cut | ||||||||||||
| 13 | |||||||||||||
| 14 | package RDF::Query::Algebra::Sort; | ||||||||||||
| 15 | |||||||||||||
| 16 | 36 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 36 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 36 | ▶ | no warnings 'redefine'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 36 | ▶ | use base qw(RDF::Query::Algebra); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | |||||||||||||
| 21 | 36 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 36 | ▶ | use Set::Scalar; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | 36 | ▶ | use Log::Log4perl; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 36 | ▶ | use Scalar::Util qw(blessed); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 36 | ▶ | use Carp qw(carp croak confess); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 36 | ▶ | use Time::HiRes qw(gettimeofday tv_interval); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | |||||||||||||
| 28 | ###################################################################### | ||||||||||||
| 29 | |||||||||||||
| 30 | 36 | our ($VERSION); | |||||||||||
| 31 | 36 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 36 | $VERSION = '2.919'; | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | ###################################################################### | ||||||||||||
| 36 | |||||||||||||
| 37 | =head1 METHODS | ||||||||||||
| 38 | |||||||||||||
| 39 | Beyond the methods documented below, this class inherits methods from the | ||||||||||||
| 40 | L<RDF::Query::Algebra> class. | ||||||||||||
| 41 | |||||||||||||
| 42 | =over 4 | ||||||||||||
| 43 | |||||||||||||
| 44 | =cut | ||||||||||||
| 45 | |||||||||||||
| 46 | =item C<new ( $pattern, [ $dir => $expr ] )> | ||||||||||||
| 47 | |||||||||||||
| 48 | Returns a new Sort structure. | ||||||||||||
| 49 | |||||||||||||
| 50 | =cut | ||||||||||||
| 51 | |||||||||||||
| 52 | 15 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 53 | 15 | my $class = shift; | |||||||||||
| 54 | 15 | my $pattern = shift; | |||||||||||
| 55 | 15 | my @orderby = @_; | |||||||||||
| 56 | 15 | return bless( [ $pattern, @orderby ], $class ); | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | =item C<< construct_args >> | ||||||||||||
| 60 | |||||||||||||
| 61 | Returns a list of arguments that, passed to this class' constructor, | ||||||||||||
| 62 | will produce a clone of this algebra pattern. | ||||||||||||
| 63 | |||||||||||||
| 64 | =cut | ||||||||||||
| 65 | |||||||||||||
| 66 | 28 | ▶ | sub construct_args { | ||||||||||
|
Subroutine
construct_args: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 67 | 28 | my $self = shift; | |||||||||||
| 68 | 28 | my $pattern = $self->pattern; | |||||||||||
| 69 | 28 | my @orderby = $self->orderby; | |||||||||||
| 70 | 28 | return ($pattern, @orderby); | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | =item C<< pattern >> | ||||||||||||
| 74 | |||||||||||||
| 75 | Returns the pattern to be sorted. | ||||||||||||
| 76 | |||||||||||||
| 77 | =cut | ||||||||||||
| 78 | |||||||||||||
| 79 | 86 | ▶ | sub pattern { | ||||||||||
|
Subroutine
pattern: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||
| 80 | 86 | my $self = shift; | |||||||||||
| 81 | 86 | ▶ | if (@_) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 0 | $self->[0] = shift; | |||||||||||
| 83 | } | ||||||||||||
| 84 | 86 | return $self->[0]; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | =item C<< orderby >> | ||||||||||||
| 88 | |||||||||||||
| 89 | Returns the array of ordering definitions. | ||||||||||||
| 90 | |||||||||||||
| 91 | =cut | ||||||||||||
| 92 | |||||||||||||
| 93 | 79 | ▶ | sub orderby { | ||||||||||
|
Subroutine
orderby: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 94 | 79 | my $self = shift; | |||||||||||
| 95 | 79 | my @orderby = @{ $self }[ 1 .. $#{ $self } ]; | |||||||||||
| 96 | 79 | return @orderby; | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | =item C<< sse >> | ||||||||||||
| 100 | |||||||||||||
| 101 | Returns the SSE string for this algebra expression. | ||||||||||||
| 102 | |||||||||||||
| 103 | =cut | ||||||||||||
| 104 | |||||||||||||
| 105 | 36 | ▶ | sub sse { | ||||||||||
|
Subroutine
sse: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 106 | 36 | my $self = shift; | |||||||||||
| 107 | 36 | my $context = shift; | |||||||||||
| 108 | 36 | ▶ | my $prefix = shift || ''; | ||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 109 | 36 | ▶ | my $indent = $context->{indent} || ' '; | ||||||||||
|
Condition50%1/2
$context->{'indent'} || ' '
MC/DC0%0/1
$context->{'indent'} || ' '
$context->{'indent'}
Truth table50%1/2
A
A= $context->{'indent'}
| |||||||||||||
| 110 | |||||||||||||
| 111 | 36 | my @order_sse; | |||||||||||
| 112 | 36 | my @orderby = $self->orderby; | |||||||||||
| 113 | 36 | foreach my $o (@orderby) { | |||||||||||
| 114 | 36 | my ($dir, $val) = @$o; | |||||||||||
| 115 | 36 | push(@order_sse, sprintf("($dir %s)", $val->sse( $context, "${prefix}${indent}" ))); | |||||||||||
| 116 | } | ||||||||||||
| 117 | |||||||||||||
| 118 | 36 | return sprintf( | |||||||||||
| 119 | "(sort\n${prefix}${indent}%s\n${prefix}${indent}%s)", | ||||||||||||
| 120 | $self->pattern->sse( $context, "${prefix}${indent}" ), | ||||||||||||
| 121 | join(' ', @order_sse), | ||||||||||||
| 122 | ); | ||||||||||||
| 123 | } | ||||||||||||
| 124 | |||||||||||||
| 125 | =item C<< as_sparql >> | ||||||||||||
| 126 | |||||||||||||
| 127 | Returns the SPARQL string for this algebra expression. | ||||||||||||
| 128 | |||||||||||||
| 129 | =cut | ||||||||||||
| 130 | |||||||||||||
| 131 | 3 | ▶ | sub as_sparql { | ||||||||||
|
Subroutine
as_sparql: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 132 | 3 | my $self = shift; | |||||||||||
| 133 | 3 | ▶ | my $context = shift || {}; | ||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 134 | 3 | my $indent = shift; | |||||||||||
| 135 | |||||||||||||
| 136 | 3 | ▶ | if ($context->{ skip_sort }) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 137 | 1 | $context->{ skip_sort }--; | |||||||||||
| 138 | 1 | return $self->pattern->as_sparql( $context, $indent ); | |||||||||||
| 139 | } | ||||||||||||
| 140 | |||||||||||||
| 141 | 2 | my $order_exprs = $self->_as_sparql_order_exprs($context, $indent); | |||||||||||
| 142 | |||||||||||||
| 143 | 2 | my $string = sprintf( | |||||||||||
| 144 | "%s\nORDER BY %s", | ||||||||||||
| 145 | $self->pattern->as_sparql( $context, $indent ), | ||||||||||||
| 146 | $order_exprs, | ||||||||||||
| 147 | ); | ||||||||||||
| 148 | 2 | return $string; | |||||||||||
| 149 | } | ||||||||||||
| 150 | |||||||||||||
| 151 | 3 | ▶ | sub _as_sparql_order_exprs { | ||||||||||
|
Subroutine
_as_sparql_order_exprs: called CC=3 SCAR=11.0
| |||||||||||||
| 152 | 3 | my $self = shift; | |||||||||||
| 153 | 3 | my $context = shift; | |||||||||||
| 154 | 3 | my $intent = shift; | |||||||||||
| 155 | |||||||||||||
| 156 | 3 | my @order_sparql; | |||||||||||
| 157 | 3 | my @orderby = $self->orderby; | |||||||||||
| 158 | 3 | foreach my $o (@orderby) { | |||||||||||
| 159 | 3 | my ($dir, $val) = @$o; | |||||||||||
| 160 | 3 | $dir = uc($dir); | |||||||||||
| 161 | 3 | ▶ | my $str = ($dir eq 'ASC') | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 162 | ? $val->as_sparql( $context ) | ||||||||||||
| 163 | : sprintf("%s(%s)", $dir, $val->as_sparql( $context )); | ||||||||||||
| 164 | 3 | push(@order_sparql, $str); | |||||||||||
| 165 | } | ||||||||||||
| 166 | 3 | return join(' ', @order_sparql); | |||||||||||
| 167 | } | ||||||||||||
| 168 | |||||||||||||
| 169 | =item C<< as_hash >> | ||||||||||||
| 170 | |||||||||||||
| 171 | Returns the query as a nested set of plain data structures (no objects). | ||||||||||||
| 172 | |||||||||||||
| 173 | =cut | ||||||||||||
| 174 | |||||||||||||
| 175 | 0 | ▶ | sub as_hash { | ||||||||||
|
Subroutine
as_hash: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 176 | 0 | my $self = shift; | |||||||||||
| 177 | 0 | my $context = shift; | |||||||||||
| 178 | |||||||||||||
| 179 | 0 | my @order = $self->orderby; | |||||||||||
| 180 | 0 | my @expressions; | |||||||||||
| 181 | 0 | foreach my $o (@order) { | |||||||||||
| 182 | 0 | push(@expressions, { type => 'comparator', direction => $o->[0], expression => $o->[1]->as_hash }); | |||||||||||
| 183 | } | ||||||||||||
| 184 | |||||||||||||
| 185 | return { | ||||||||||||
| 186 | 0 | type => lc($self->type), | |||||||||||
| 187 | pattern => $self->pattern->as_hash, | ||||||||||||
| 188 | order => \@expressions, | ||||||||||||
| 189 | }; | ||||||||||||
| 190 | } | ||||||||||||
| 191 | |||||||||||||
| 192 | =item C<< type >> | ||||||||||||
| 193 | |||||||||||||
| 194 | Returns the type of this algebra expression. | ||||||||||||
| 195 | |||||||||||||
| 196 | =cut | ||||||||||||
| 197 | |||||||||||||
| 198 | 0 | ▶ | sub type { | ||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 199 | 0 | return 'SORT'; | |||||||||||
| 200 | } | ||||||||||||
| 201 | |||||||||||||
| 202 | =item C<< referenced_variables >> | ||||||||||||
| 203 | |||||||||||||
| 204 | Returns a list of the variable names used in this algebra expression. | ||||||||||||
| 205 | |||||||||||||
| 206 | =cut | ||||||||||||
| 207 | |||||||||||||
| 208 | 6 | ▶ | sub referenced_variables { | ||||||||||
|
Subroutine
referenced_variables: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 209 | 6 | my $self = shift; | |||||||||||
| 210 | 6 | return RDF::Query::_uniq($self->pattern->referenced_variables); | |||||||||||
| 211 | } | ||||||||||||
| 212 | |||||||||||||
| 213 | =item C<< potentially_bound >> | ||||||||||||
| 214 | |||||||||||||
| 215 | Returns a list of the variable names used in this algebra expression that will | ||||||||||||
| 216 | bind values during execution. | ||||||||||||
| 217 | |||||||||||||
| 218 | =cut | ||||||||||||
| 219 | |||||||||||||
| 220 | 0 | ▶ | sub potentially_bound { | ||||||||||
|
Subroutine
potentially_bound: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 221 | 0 | my $self = shift; | |||||||||||
| 222 | 0 | return RDF::Query::_uniq($self->pattern->potentially_bound); | |||||||||||
| 223 | } | ||||||||||||
| 224 | |||||||||||||
| 225 | =item C<< definite_variables >> | ||||||||||||
| 226 | |||||||||||||
| 227 | Returns a list of the variable names that will be bound after evaluating this algebra expression. | ||||||||||||
| 228 | |||||||||||||
| 229 | =cut | ||||||||||||
| 230 | |||||||||||||
| 231 | 0 | ▶ | sub definite_variables { | ||||||||||
|
Subroutine
definite_variables: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 232 | 0 | my $self = shift; | |||||||||||
| 233 | 0 | return $self->pattern->definite_variables; | |||||||||||
| 234 | } | ||||||||||||
| 235 | |||||||||||||
| 236 | =item C<< is_solution_modifier >> | ||||||||||||
| 237 | |||||||||||||
| 238 | Returns true if this node is a solution modifier. | ||||||||||||
| 239 | |||||||||||||
| 240 | =cut | ||||||||||||
| 241 | |||||||||||||
| 242 | 0 | ▶ | sub is_solution_modifier { | ||||||||||
|
Subroutine
is_solution_modifier: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 243 | 0 | return 1; | |||||||||||
| 244 | } | ||||||||||||
| 245 | |||||||||||||
| 246 | |||||||||||||
| 247 | 36 | 1; | |||||||||||
| 248 | |||||||||||||
| 249 | __END__ | ||||||||||||