W3C home > Mailing lists > Public > public-rdf-dawg-comments@w3.org > May 2011

Re: avg testcase issues (was: Re: syntax error in testcase manifest)

From: Steve Harris <steve.harris@garlik.com>
Date: Tue, 17 May 2011 16:27:12 +0100
Message-Id: <C2623068-A467-4FF8-8575-BB41785F81E1@garlik.com>
Cc: Jeen Broekstra <jeen.broekstra@gmail.com>
To: public-rdf-dawg-comments@w3.org
In response to http://lists.w3.org/Archives/Public/public-rdf-dawg-comments/2011Feb/0025.html

 > 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 believe this is now fixed.

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

Regards,
   Steve, on behalf of the SPARQL Working Group.

-- 
Steve Harris, CTO, Garlik Limited
1-3 Halford Road, Richmond, TW10 6AW, UK
+44 20 8439 8203  http://www.garlik.com/
Registered in England and Wales 535 7233 VAT # 849 0517 11
Registered office: Thames House, Portsmouth Road, Esher, Surrey, KT10 9AD
Received on Tuesday, 17 May 2011 15:27:41 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 17 May 2011 15:27:41 GMT