lib/sparql/algebra/operator/sum.rb in sparql-3.0.2 vs lib/sparql/algebra/operator/sum.rb in sparql-3.1.0
- old
+ new
@@ -4,16 +4,16 @@
# The SPARQL `sum` set function.
#
# @example
# (prefix ((: <http://www.example.org/>))
# (project (?sum)
- # (extend ((?sum ?.0))
- # (group () ((?.0 (sum ?o)))
+ # (extend ((?sum ??.0))
+ # (group () ((??.0 (sum ?o)))
# (bgp (triple ?s :dec ?o))))))
#
# @see http://www.w3.org/TR/sparql11-query/#defn_aggSum
- class Sum < Operator::Unary
+ class Sum < Operator
include Aggregate
NAME = :sum
##
@@ -21,9 +21,11 @@
#
# @param [Enumerable<Array<RDF::Term>>] enum
# enum of evaluated operand
# @return [RDF::Literal::Numeric] The sum of the terms
def apply(enum)
+ # FIXME: we don't actually do anything with distinct
+ operands.shift if distinct = (operands.first == :distinct)
if enum.empty?
RDF::Literal(0)
elsif enum.flatten.all? {|n| n.is_a?(RDF::Literal::Numeric)}
enum.flatten.reduce(:+)
else