Class: SPARQL::Algebra::Operator::Max
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::Max
- Includes:
- Aggregate
- Defined in:
- lib/sparql/algebra/operator/max.rb
Overview
The SPARQL max
set function.
[127] Aggregate::= … | ‘MAX’ ‘(’ ‘DISTINCT’? Expression ‘)’
Constant Summary collapse
- NAME =
:max
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#apply(enum, **options) ⇒ RDF::Literal
Max is a SPARQL set function that return the maximum value from a group respectively.
-
#initialize(*operands, **options) ⇒ Max
constructor
A new instance of Max.
-
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Aggregate
#aggregate, #replace_aggregate!, #replace_vars!
Methods inherited from SPARQL::Algebra::Operator
#aggregate?, arity, #base_uri, base_uri, base_uri=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #inspect, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars
Methods included from Expression
cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?
Constructor Details
#initialize(*operands, **options) ⇒ Max
Returns a new instance of Max.
26 27 28 29 30 31 |
# File 'lib/sparql/algebra/operator/max.rb', line 26 def initialize(*operands, **) raise ArgumentError, "max operator accepts at most one argument with an optional :distinct" if (operands - %i{distinct}).length != 1 super end |
Instance Method Details
#apply(enum, **options) ⇒ 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.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sparql/algebra/operator/max.rb', line 41 def apply(enum, **) # FIXME: we don't actually do anything with distinct operands.shift if distinct = (operands.first == :distinct) 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 |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
58 59 60 61 62 |
# File 'lib/sparql/algebra/operator/max.rb', line 58 def to_sparql(**) distinct = operands.first == :distinct args = distinct ? operands[1..-1] : operands "MAX(#{'DISTINCT ' if distinct}#{args.to_sparql(**)})" end |