One Problem with XQJ API and one with XQuery Update

Thursday, 21 January 2010 · 3 messages
MK
Marcus Kessel21 Jan 2010 11:04 #

Hi,

first of all: Great work! BaseX is the fastest/feature-rich XQuery Processor I have found so far.

Currently, I'm working on a RESTful Service, where your processor is a great enhancement.

So far, I've encountered a few problems.

First: There is problem with XQuery Update, especially with "insert", which is not always reproducable. Example query:

declare variable $newrec as node() external;
insert node $newrec as first into basex:db('Recordings')/recordings

The variable $newrec is bound to a "recording" Node with XQJ
*.bindNode(new QName("newrec"), node, null);

Sometimes, a ArrayIndexOutOfBoundsException is thrown in "org.basex.query.up.Primitives" at line 51.

I did a quick hack, and replaced the null constraint with:

} else if(l.length < pos) {
      l = new UpdatePrimitive[PrimitiveType.values().length];
      l[pos] = p;

But I think it's only a quick hack ..

The second problem I've encountered is with "order by" clause and XQJ API. Order by has no effect, if I use the XQJ Api something like this:

	XQResultSequence result = null;
        XQExpression loadExp = null;
        try {
            loadExp = this.xqueryManager.createExpression();
            result = loadExp.executeQuery(queryString);
            while(result.next()) {
                // do something
            }
        }

But when I use the classes of BaseX directly, "order by" orders correctly. For example:

QueryProcessor processor = new QueryProcessor(queryString, context);
Result resultX = processor.query();
            resultX.serialize(new XMLSerializer(out));

Sample query:

element recordings {
  for $rec at $pos in basex:db('Recordings')/recordings/recording
  order by xs:dateTime($rec/startDate) descending
  return $rec }

Any comments are appreciated ;) Thanks!

Bye, Marcus

CG
Christian Grün21 Jan 2010 12:01 #

Hi Marcus,

thanks for your nice and helpful feedback. Some quick comments:

Quoted text · Marcus Kessel · 2 lines
> Currently, I'm working on a RESTful Service, where your processor is a > great enhancement.

This is an interesting note; one of our members, Lukas (lukas.lewandowski at uni-konstanz.de), is currently combining REST and BaseX as well; you are invited to exchange your experiences.

Quoted text · Marcus Kessel · 12 lines
> First: There is problem with XQuery Update, especially with "insert", > which is not always reproducable. > Example query: > > declare variable $newrec as node() external; > insert node $newrec as first into basex:db('Recordings')/recordings > > The variable $newrec is bound to a "recording" Node with XQJ > *.bindNode(new QName("newrec"), node, null); > > Sometimes, a ArrayIndexOutOfBoundsException is thrown in > "org.basex.query.up.Primitives" at line 51.

Yes, this pretty much looks like a bug - you'll get an answer on this soon.

Quoted text · Marcus Kessel · 11 lines
> The second problem I've encountered is with "order by" clause and XQJ > API. Order by has no effect, if I use the XQJ Api something like this: > XQResultSequence result = null; > XQExpression loadExp = null; > try { > loadExp = this.xqueryManager.createExpression(); > result = loadExp.executeQuery(queryString); > while(result.next()) { > // do something > } > }

An interesting one.. Could you provide us with a complete example (incl. a sample XML snippet) which demonstrates the behaviour? I just tried a small example query, which seems to be correctly evaluated by the XQJ API..

    result = loadExp.executeQuery("for $i in (3,2,1) order by $i return $i");
    while(result.next()) {
      System.out.println(result.getInt());
    }

Note that, in the long term, most BaseX developers tend to use our own code APIs, as both the XQJ and XML:DB APIs lack too many requested features. After all, however, we try to keep all APIs bug free, so all kind of feedback is welcome.

Hope this helps, Christian

___________________________

Christian Gruen Universitaet Konstanz Department of Computer & Information Science D-78457 Konstanz, Germany Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577 http://www.inf.uni-konstanz.de/~gruen

MK
Marcus Kessel21 Jan 2010 17:22 #
Quoted text · +0100 · 2 lines
Am Thu, 21 Jan 2010 12:01:45 +0100 schrieb Christian Grün <christian.gruen at gmail.com>:

Hi Christian,

thanks for your interest!

Quoted text · Christian Grün · 9 lines
> An interesting one.. Could you provide us with a complete example > (incl. a sample XML snippet) which demonstrates the behaviour? I just > tried a small example query, which seems to be correctly evaluated by > the XQJ API.. > > result = loadExp.executeQuery("for $i in (3,2,1) order by $i > return $i"); while(result.next()) { > System.out.println(result.getInt()); > }

I debugged my own implementation again and found that the "order by" problem is not caused by BaseX (XQJ), but was my own fault.

To put in a nutshell, the resulting XML is given to an JAXB unmarshaller, who unmarshals the XML to Java objects. The content is described as a Java Collection, but it seems that JAXB doesn't (?) care about the order in the the generated Collection. When I get the result Sequence as a String, the ordering is correct.

So there is no problem with ordering in BaseX (XQJ) at all ;-)

Bye, Marcus


⚡Generated with XQuery