This wiki has been archived and is now read-only.


From SPARQL Working Group
Jump to: navigation, search
> I do have some issues to report with two testcases, both dealing with
> the AVG operator.
> Before I go into that: I have assumed that when the definition of AVG
> (http://www.w3.org/TR/sparql11-query/#setFunctions) uses the '/'
> division operator, this means it applies XPath's op:numeric-divide (as
> defined in section 16.3). It would actually be good to clarify this in
> the spec, I think (one way to do this would be to explicitly use
> op:numeric-divide in the definition, rather than just '/').
> Anyway, here goes:
> 1. testcase aggregates/agg-avg-01 ("AVG")
> This testcase currently assumes a particular precision in xsd:decimal
> division, which is not mandated by the XPath definition. XPath defines
> that in xsd:decimal operations, rounding is implementation dependent
> (see http://www.w3.org/TR/xpath-functions/#op.numeric, near the end of
> the section).

I'm not sure that was the intention:

"For xs:decimal values the number of digits of precision returned by the numeric operators is ·implementation-defined·. If the number of digits in the result exceeds the number of digits that the implementation supports, the result is truncated or rounded in an ·implementation-defined· manner."

The minimum number of decimal places that must be supported my minimally conforming implementations is 18, so I don't think it's correct to round to one decimal place.

> In the test, five numbers of type xsd:decimal are averaged (1.0, 2.0,
> 3.5, 2.2, 2.2). The average is computed by executing a op:numeric-divide
> on the sum of the five decimals: 11.1/5. The result of this is, as the
> testcase defines, 2.22. However, this result increases precision to 2
> decimals (note that the precision of the input is 1 decimal).
> While this is not wrong, it is not the *only* correct answer: an
> implementation that would round or truncate to 1 decimal and return 2.2
> as the answer would IMHO also perform the operation correctly.

I don't believe the definition of decimal sanctions rounding to one decimal place.

> To fix this, I would suggest that the testcase numbers are adapted so
> that the result of the division when not rounded is of the same
> precision as the input. Alternatively, change the test case to work on
> floats or doubles, as division behavior is more precisely defined for
> those datatypes.
> 2. testcase aggregates/agg-avg-02 ("AVG with GROUP BY")
> This testcase contains a typing error: the result of the AVG computation
> where ?s = ex:ints should be of type xsd:decimal, not xsd:integer (XPath
> defines the result of a op:numeric-divide on two integer arguments as
> always being of type xsd:decimal).

I belive this is now fixed.

Please respond to this mail saying whether this response satisfies your comment.

- Steve, on behalf of the SPARQL Working Group.