Project

Profile

Help

Error in XMark queries

Added by Denis Sukhoroslov almost 8 years ago

Saxon HE 9.7.0-14

I'm running test queries against XMark auction.xml file. On smaller file all 20 queries return expected results. But on bigger file (111M) a couple of queries throw exceptions:

  1. (: Q10. List all persons according to their interest; use French markup in the result. :)

let $auction := doc("auction.xml") return for $i in distinct-values($auction/site/people/person/profile/interest/@category) let $p := for $t in $auction/site/people/person where $t/profile/interest/@category = $i return {$t/profile/gender/text()} {$t/profile/age/text()} {$t/profile/education/text()} {fn:data($t/profile/@income)} {$t/name/text()} {$t/address/street/text()} {$t/address/city/text()} {$t/address/country/text()} {$t/emailaddress/text()} {$t/homepage/text()} {$t/creditcard/text()} return {{$i}, $p}

the exception is:

java.lang.NullPointerException: null at net.sf.saxon.value.StringValue.getXPathComparable(StringValue.java:345) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.functions.DistinctValues$DistinctIterator.next(DistinctValues.java:74) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.functions.DistinctValues$DistinctIterator.next(DistinctValues.java:33) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.expr.ItemMappingIterator.next(ItemMappingIterator.java:108) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.query.XQueryExpression$ErrorReportingIterator.next(XQueryExpression.java:846) ~[Saxon-HE-9.7.0-14.jar:na]

  1. (: Q14. Return the names of all items whose description contains the word `gold'. :)

let $auction := doc("auction.xml") return for $i in $auction/site//item where contains(string(exactly-one($i/description)), "gold") return $i/name/text()

the exception is:

java.lang.NullPointerException: null at net.sf.saxon.functions.Contains.contains(Contains.java:26) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.functions.Contains.call(Contains.java:53) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.functions.Contains.call(Contains.java:23) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:546) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.expr.Expression.effectiveBooleanValue(Expression.java:837) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.expr.FilterIterator$NonNumeric.matches(FilterIterator.java:198) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.expr.FilterIterator.getNextMatchingItem(FilterIterator.java:81) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.expr.FilterIterator.next(FilterIterator.java:64) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.expr.MappingIterator.next(MappingIterator.java:58) ~[Saxon-HE-9.7.0-14.jar:na] at net.sf.saxon.query.XQueryExpression$ErrorReportingIterator.next(XQueryExpression.java:846) ~[Saxon-HE-9.7.0-14.jar:na]

Most probably this is some issue with data. Please have a look.

Thanks, Denis.


Replies (12)

Please register to reply

RE: Error in XMark queries - Added by Denis Sukhoroslov almost 8 years ago

sorry, that was a small file. the big one is:

RE: Error in XMark queries - Added by Denis Sukhoroslov almost 8 years ago

A small update:

  • The first exception goes away when I set proper DefaultCollationUri to the StaticContext.
  • The second one still remains, and with both files, actually.

RE: Error in XMark queries - Added by Michael Kay almost 8 years ago

Could you let us know how you are running the queries? E.g. what API calls you are using?

(Actually your last message contains a clue, it suggests you might be using the old StaticQueryContext API. So I'd like to see exactly what calls on this API you are making.)

RE: Error in XMark queries - Added by Denis Sukhoroslov almost 8 years ago

this is how I run it:

String query; StaticQueryContext stx; DynamicQueryContext dtx; XQueryExpression exp = stx.compileQuery(query); SequenceIterator itr = exp.iterator(dtx); // then iterate it through itr..

is this API obsolete? Which one you'd suggest instead?

Thanks, Denis.

RE: Error in XMark queries - Added by Michael Kay almost 8 years ago

I would recommend using the s9api API these days. The problem with the lower-level API you are using is that it's not always clear what's intended for client use and what is there for internal purposes.

You don't say how stx and dtx are initialized, which we will need to know if we are to reproduce and fix the problem.

RE: Error in XMark queries - Added by Denis Sukhoroslov almost 8 years ago

Thanks, will try to use the s9api. But I probably do use some lower level features of Saxon. I initialize contexts as follows:

    config = Configuration.newConfiguration();
    stx = config.newStaticQueryContext();
    dtx = new DynamicQueryContext(config);
    dtx.setApplyFunctionConversionRulesToExternalVariables(false);
    // then i register a number of my callbacks
	config.setCollectionFinder(<my_collection_finder>);
    config.setDefaultCollection("");
    config.setSourceResolver(<my_source_resolver>);
    config.setURIResolver(<my_uri_resolver>);
    config.setModuleURIResolver(<my_module_resolver>);
    dtx.setUnparsedTextURIResolver(<my_text_uri_resolver>);

RE: Error in XMark queries - Added by Denis Sukhoroslov almost 8 years ago

CollectionFinder and ModuleURIResolver are not used in this scenario. SourceResolver is invoked and return Source over the auction document. I then also set a number of properties in StaticQueryContext (the call is comming from my XQJ driver, so I set all properties mirroring XQStaticContext). The query is compiled properly and I got the exceptions at iteration phase.

RE: Error in XMark queries - Added by Michael Kay almost 8 years ago

Sorry to drop the ball on this.

I haven't been able to reproduce the failure from the information provided.

Could you please try to devise a free-standing Java program that I can run to reproduce the failure? (Don't worry about the XMark data, I've got that).

Both failures look clearly as if the default collation name in the static query context is null. But I can't find a way in which that could happen (other than the app explicitly setting it to null).

RE: Error in XMark queries - Added by Denis Sukhoroslov almost 8 years ago

Ok, I'll try to prepare some reproducer test. But I do have a set of unit tests where all XMark queries passed successfully. So, it is possible the issue is somewhere on my side and my driver set the collation name to null by mistake.

RE: Error in XMark queries - Added by Denis Sukhoroslov almost 8 years ago

Michael,

this is the reproducer test:

@Test
public void testCollationQuery() throws XPathException {
        Configuration config = Configuration.newConfiguration();
        StaticQueryContext sqc = config.newStaticQueryContext();
        sqc.declareDefaultCollation("");
        DynamicQueryContext dqc = new DynamicQueryContext(config);
        dqc.setApplyFunctionConversionRulesToExternalVariables(false);

	String query = "declare base-uri \"../../etc/samples/xmark/\";\n" +
				"let $auction := fn:doc(\"auction.xml\") return\n" +
				"for $i in $auction/site//item\n" +
				"where contains(string(exactly-one($i/description)), \"gold\")\n" +
				"return $i/name/text()";
				
   	XQueryExpression xqExp = sqc.compileQuery(query);
        SequenceIterator itr = xqExp.iterator(dqc);
        Item item = itr.next();
   	assertNotNull(item);
   	assertNotNull(item.getStringValue());
}

in my env it throws NPE:

java.lang.NullPointerException
	at net.sf.saxon.functions.Contains.contains(Contains.java:26)
	at net.sf.saxon.functions.Contains.call(Contains.java:53)
	at net.sf.saxon.functions.Contains.call(Contains.java:23)
	at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:546)
	at net.sf.saxon.expr.Expression.effectiveBooleanValue(Expression.java:837)
	at net.sf.saxon.expr.FilterIterator$NonNumeric.matches(FilterIterator.java:198)
	at net.sf.saxon.expr.FilterIterator.getNextMatchingItem(FilterIterator.java:81)
	at net.sf.saxon.expr.FilterIterator.next(FilterIterator.java:64)
	at net.sf.saxon.expr.MappingIterator.next(MappingIterator.java:58)
	at net.sf.saxon.query.XQueryExpression$ErrorReportingIterator.next(XQueryExpression.java:846)
	at com.bagri.xquery.saxon.SaxonQueryTest.testCollationQuery(SaxonQueryTest.java:63)
        ..............

Looks like Saxon does not allow null or empty collation uris. The declareDefaultCollation() method should check passed values or throw the declared exception, probably:

    /**
     * Set the default collation.
     *
     * @param name The collation name, as specified in the query prolog. The name
     *             is not validated until it is used.
     * @throws NullPointerException if the supplied value is null
     * @since 8.4. Changed in 8.6 so it no longer validates the collation name: this is
     *        because the base URI is not necessarily known at the point where the default
     *        collation is declared.
     */

    public void declareDefaultCollation(String name) {
        this.defaultCollationName = name;
    }

RE: Error in XMark queries - Added by Michael Kay almost 8 years ago

I have reproduced the problem and have logged it here.

https://saxonica.plan.io/issues/3121

Please use that thread to track progress.

Note, however, this will only lead to reporting of some proper error message, like "Default collation "" is not recognized". I'm not sure why you're setting the default collation to a zero length string, but it isn't going to achieve anything useful.

RE: Error in XMark queries - Added by Denis Sukhoroslov almost 8 years ago

Yes, the proper error message is what I'm looking for :). Sure, the issue is caused by an error on my side. But the NPE thrown currently is quite misleading, I've found the root cause only by accident when testing other queries. Also please note: for different queries the NPE thrown from different places. And the following query:

@ declare base-uri "../../etc/samples/xmark/"; let $auction := doc("auction.xml") return for $b in $auction/site/regions//item let $k := $b/name/text() order by zero-or-one($b/location) ascending empty greatest return {$b/location/text()} @

throws correct error at query compilation time:

; Line#: 6; Column#: 1
net.sf.saxon.trans.XPathException: Unknown collation ''
	at net.sf.saxon.expr.parser.XPathParser.grumble(XPathParser.java:282)
	at net.sf.saxon.expr.parser.XPathParser.grumble(XPathParser.java:239)
	at net.sf.saxon.query.XQueryParser.parseFLWORExpression(XQueryParser.java:2427)
	at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:630)
	at net.sf.saxon.query.XQueryParser.parseFLWORExpression(XQueryParser.java:2446)
	at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:630)
	at net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:593)
	at net.sf.saxon.query.XQueryParser.parseQuery(XQueryParser.java:408)
	at net.sf.saxon.query.XQueryParser.makeXQueryExpression(XQueryParser.java:156)
	at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:589)
    (1-12/12)

    Please register to reply