exist
exist copied to clipboard
[BUG] typed Lucene field values cannot be cast to xs:dateTime
related #4535
The test suite below fails with
<testsuites>
<testsuite package="http://exist-db.org/xquery/lucene-field-datetime-cast" timestamp="2022-09-02T22:10:49.116+02:00" tests="1" failures="0" errors="1" pending="0" time="PT0.004S">
<testcase name="datetime-values-cast" class="lfdc:datetime-values-cast">
<error type="java:org.exist.xquery.XPathException" message="exerr:ERROR xs:dateTime instance must have all fields set [at line 50, column 35, source: /db/test.xqm]
In function:
	lfdc:datetime-values-cast() [14:35:/db/test.xqm]
	test:apply(function(*), item()*) [581:9:jar:file:/Users/jll/projects/existdb/exist/exist-distribution/target/exist-distribution-6.1.0-SNAPSHOT-dir/lib/exist-core-6.1.0-SNAPSHOT.jar!/org/exist/xquery/lib/xqsuite/xqsuite.xql]
	test:apply(function(*), element(function), item()*) [488:9:jar:file:/Users/jll/projects/existdb/exist/exist-distribution/target/exist-distribution-6.1.0-SNAPSHOT-dir/lib/exist-core-6.1.0-SNAPSHOT.jar!/org/exist/xquery/lib/xqsuite/xqsuite.xql]
	test:call-test(function(*), element(function), element(annotation)*) [300:32:jar:file:/Users/jll/projects/existdb/exist/exist-distribution/target/exist-distribution-6.1.0-SNAPSHOT-dir/lib/exist-core-6.1.0-SNAPSHOT.jar!/org/exist/xquery/lib/xqsuite/xqsuite.xql]. xs:dateTime instance must have all fields set"/>
</testcase>
</testsuite>
</testsuites>
To reproduce
xquery version "3.1";
module namespace lfdc="http://exist-db.org/xquery/lucene-field-datetime-cast";
declare namespace test="http://exist-db.org/xquery/xqsuite";
declare variable $lfdc:data := document {
<items>
<item datetime="2022-08-07T10:34:56.789-02:00"/>
<item datetime="2022-08-07T14:34:56.789+02:00"/>
<item datetime="2022-08-07T12:34:56.789Z"/>
<item datetime="2022-08-07T12:34:56.789"/>
</items>
};
declare variable $lfdc:xconf :=
<collection xmlns="http://exist-db.org/collection-config/1.0">
<index xmlns:xs="http://www.w3.org/2001/XMLSchema">
<lucene>
<text qname="item">
<field name="datetime" expression="@datetime" type="xs:dateTime"/>
</text>
</lucene>
</index>
</collection>;
declare variable $lfdc:collection := "lucene-field-datetime-cast";
declare
%test:setUp
function lfdc:setup() {
let $testCol := xmldb:create-collection("/db", $lfdc:collection)
let $indexCol := xmldb:create-collection("/db/system/config/db", $lfdc:collection)
return (
xmldb:store("/db/" || $lfdc:collection, "test.xml", $lfdc:data),
xmldb:store("/db/system/config/db/" || $lfdc:collection, "collection.xconf", $lfdc:xconf),
xmldb:reindex("/db/" || $lfdc:collection)
)
};
declare
%test:tearDown
function lfdc:tearDown() {
xmldb:remove("/db/" || $lfdc:collection),
xmldb:remove("/db/system/config/db/" || $lfdc:collection)
};
declare
%test:assertEquals("2022-08-07T12:34:56.789Z", "2022-08-07T12:34:56.789Z", "2022-08-07T12:34:56.789Z", "2022-08-07T12:34:56.789Z")
function lfdc:datetime-values-cast() {
collection("/db/" || $lfdc:collection)
//item[
ft:query(., "datetime:*", map{
"leading-wildcard": "yes",
"fields": "datetime"
})]
! ft:field(., "datetime", "xs:dateTime")
};
Tested on:
- OS: MacOS 12.5.1
- eXist-db version: 6.1.0-SNAPSHOT
- Java Version Java8u342
Additional context
- How is eXist-db installed? built from source: commit f3424d7c44d2cc7d8eb722e0701709de6e497a34 (develop HEAD)
- Any custom changes in e.g.
conf.xml? none
In the index configuration the field is named time but in the lfdc:datetime-values-cast() function you appear to be querying a field named datetime.
Good catch @joewiz! I corrected the XQSuite