[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qexo-general] problems aggregating with sum()
From: |
Per Bothner |
Subject: |
Re: [Qexo-general] problems aggregating with sum() |
Date: |
Wed, 26 Oct 2005 22:30:02 -0700 |
User-agent: |
Mozilla Thunderbird 1.0.6-1.1.fc4 (X11/20050720) |
Kevin Y. Kim (Lists) wrote:
If I have an XML file, input.xml, that looks like this:
<record id="1">
<key>A</key>
<value>1</value>
</record>
<record id="2">
<key>B</key>
<value>2</value>
</record>
...
That is not a well-formed XML file. At least, it is not a legal
"XML document", which can have only a single top-level element.
I want the output to look like this:
<record>
<key>A</key>
<value>5</value>
</record>
<record>
<key>B</key>
<value>7</value>
</record>
<record>
<key>C</key>
<value>3</value>
</record>
Likewise not valid XML. It could be valid in the XQuery data model,
if you view it as a sequence of elements.
When I try this xquery with Qexo, I get an exception:
record><key>A</key><valueInvalid parameter, was: null
java.lang.ClassCastException
at gnu.kawa.functions.Arithmetic.asNumeric(Arithmetic.java:169)
at gnu.kawa.functions.AddOp.apply2(AddOp.java:76)
at gnu.kawa.functions.AddOp.applyN(AddOp.java:118)
at gnu.kawa.functions.AddOp.applyN(AddOp.java:133)
at gnu.mapping.ProcedureN.apply2(ProcedureN.java:39)
at gnu.xquery.util.Reduce.combine(Reduce.java:26)
at gnu.xquery.util.Reduce.apply1(Reduce.java:42)
at atInteractiveLevel$2.run(test.xq:13)
As far as I can tell, the problem is the SUM() function.
Correct. The "test.xq:13" refers to line 13, specifically the sum.
Just on a lark, I changed the SUM() to COUNT() - and it does
report the correct number of items in the sequence.
The problem is that $recs/value/text() evaluates to a sequence of
text nodes, and Qexo doesn't know how to convert each text node
to a number - only to a string. This has to do with complicated
XQuery typing rules - which Qexo doesn't implement correctly yet.
As a work-around try:
sum(for $none in $recs/value/text() return number($node))
--
--Per Bothner
address@hidden http://per.bothner.com/