- From: Ashok Malhotra <ashokma@microsoft.com>
- Date: Fri, 3 Oct 2003 05:02:54 -0700
- To: "Michael Brundage" <xquery@attbi.com>, <public-qt-comments@w3.org>
Michael: Thank you for your comments. The semantics of fn:avg(), and in fact all the aggregate functions, were overhauled at the last meeting. Specifically, values of type xdt:untypedAtomic are now always converted to xs:double and if the input sequence contains a NaN the result is NaN. If the input sequence is the empty sequence, the empty sequence is returned. The wording has also been changed and clarified. So, I would like to close the issue we created based on your mail. Please take a look at the next version of the F&O and let us know if you are satisfied with it. All the best, Ashok > -----Original Message----- > From: Michael Brundage [mailto:xquery@attbi.com] > Sent: Wednesday, May 28, 2003 6:47 PM > To: Ashok Malhotra; public-qt-comments@w3.org > Subject: RE: [F&O] avg() > > Well, the first sentence is already wrong when $arg is the empty sequence: > > sum(()) div count(()) => 0.0E0 div 0 => NaN > avg(()) => () > > So I'd have to say I still don't like it :-) > > -----Original Message----- > From: public-qt-comments-request@w3.org > [mailto:public-qt-comments-request@w3.org] On Behalf Of Ashok Malhotra > Sent: Sunday, May 25, 2003 11:32 AM > To: Michael Brundage; public-qt-comments@w3.org > Subject: RE: [F&O] avg() > > > > Michael: > Thank you for your comments. The sentence about date/time values was a > cut and paste error. Clearly you cannot take the average (or sum) of > date/time values since addition is not defined on them. I have removed > this sentence. > I have also adjusted the wording based on your other comments. See if > you like this better. > > 15.3.2 fn:avg > fn:avg($arg as xdt:anyAtomicType*) as xdt:anyAtomicType? > > Returns a value of the same type as the items in $arg that is the > average of the values (computed as sum($arg) div count($arg)). > > If $arg is the empty sequence, the empty sequence is returned. > > Duration values must either all be xdt:yearMonthDuration values or must > all be xdt:dayTimeDuration values. For numeric values, the numeric > promotion rules defined in 6.2 Operators on Numeric Values are used to > promote all values to a single common type. Values of type > xdt:untypedAtomic are cast to the type of the other items in $arg. If > all values in $arg are of type xdt:untypedAtomic they are converted to > xs:double. After these operations, $arg must contain items of a single > type or one if its subtypes. In addition, the type must support addition > and division by an integer. > > If the above conditions are not met, then an error is raised ("Invalid > argument to fn:avg()"). > > If $arg contains xs:float or xs:double values, NaN values are discarded. > > For detailed semantics, see section 6.2.8 of [XQuery 1.0 and XPath 2.0 > Formal Semantics]. > > > All the best, Ashok > > > -----Original Message----- > > From: public-qt-comments-request@w3.org [mailto:public-qt-comments- > > request@w3.org] On Behalf Of Michael Brundage > > Sent: Saturday, May 17, 2003 1:12 PM > > To: public-qt-comments@w3.org > > Subject: [F&O] avg() > > > > > > The definition of avg() contains some statements that are > contradictory > > and others that are unclear (at least to me). For example, > > > > (0) > > "$srcval must contain items of a single type or one if its subtypes." > > > > Followed by a description of (for example) how to promote > > xdt:untypedAtomic > > into double. Clearly avg(xs:double(1.0), xs:untypedAtomic(2.0)) is > valid, > > but the quoted sentence above would rule it out. > > > > (1) > > "In addition, the type must support addition and division by an > integer. > > If date/time values do not have a timezone, the implicit timezone > provided > > by the evaluation context is added and the adjusted normalized value > is > > used in the calculation." > > > > I see several problems with these two sentences: > > (a) xs:date and xs:time do not support addition (with themselves), > but > > the second sentence implies sequences of dates and times are allowed. > > Is avg((xs:time('01:01:01'), xs:time('03:03:03'))) allowed? > > What about avg(xs:time('01:01:01'))? > > > > (b) What about avg(xs:date('1972-05-13'), > xs:yearMonthDuration('P31Y'))? > > These two support addition (with each other) and division by an > integer. > > > > (2) > > Are the typing rules described here applied to the static or runtime > types > > of the arguments? > > For example, is the expression > > avg((if ($someRuntimeCondition) then xdt:yearMonthDuration('P1Y') else > > xdt:dayTimeDuration('PT1H'), > > if ($someOtherRuntimeCondition) then xdt:yearMonthDuration('P3Y') > > else > > xdt:dayTimeDuration('PT3H'))) > > always a static type error, or will it succeed when > > $someRuntimeCondition=$someOtherRuntimeCondition and fail otherwise. > > > > > > These confusions could be avoided if there were separate average > > functions: > > one for the numeric types (backwards compatible with XPath 1.0, > > non-numeric items in the sequence are promoted to a numeric type); > > another function (or set of functions) for date/time/dateTime/ > > dayTimeDuration/yearMonthDuration values, say > > avg-date(xs:date*) as xs:date? > > avg-yearMonthDuration(xdt:yearMonthDuration*) as > xdt:yearMonthDuration? > > etc. > > > > > > Best wishes, > > > > Michael Brundage > > Writing as > > Author, "XQuery: The XML Query Language" (Addison-Wesley, to appear > 2003) > > Co-author, "Professional XML Databases" (Wrox Press, 2000) > > > > not as > > Technical Lead > > Common Query Runtime/XML Query Processing > > WebData XML Team > > Microsoft > > > >
Received on Friday, 3 October 2003 08:02:57 UTC