Class: SPARQL::Algebra::Operator::Max

Inherits:
Unary show all
Includes:
Aggregate
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/operator/max.rb

Overview

The SPARQL max set function.

Examples:

(prefix ((: <http://www.example.org/>))
  (project (?max)
    (extend ((?max ?.0))
      (group () ((?.0 (max ?o)))
        (bgp (triple ?s ?p ?o))))))

See Also:

Constant Summary collapse

NAME =
:max

Constants inherited from Unary

Unary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Aggregate

#aggregate, #replace_aggregate!, #replace_vars!

Methods inherited from Unary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, #base_uri, base_uri, base_uri=, #boolean, #constant?, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #parent, #parent=, prefixes, #prefixes, prefixes=, #rewrite, #to_binary, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, #optimize, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Unary

Instance Method Details

#apply(enum) ⇒ RDF::Literal

Max is a SPARQL set function that return the maximum value from a group respectively.

It makes use of the SPARQL ORDER BY ordering definition, to allow ordering over arbitrarily typed expressions.

Parameters:

Returns:



27
28
29
30
31
32
33
34
35
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-b66c70fb77a0/lib/sparql/algebra/operator/max.rb', line 27

def apply(enum)
  if enum.empty?
    raise TypeError, "Maximum of an empty multiset"
  elsif enum.flatten.all? {|n| n.literal?}
    RDF::Literal(enum.flatten.max)
  else
    raise TypeError, "Maximum of non-literals: #{enum.flatten}"
  end
end