Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] XQuery return wrong results on start-with comparison #4810

Open
Twilight-Shuxin opened this issue Mar 20, 2023 · 12 comments
Open

[BUG] XQuery return wrong results on start-with comparison #4810

Twilight-Shuxin opened this issue Mar 20, 2023 · 12 comments
Labels
bug issue confirmed as bug investigate issues being looked at xquery issue is related to xquery implementation
Milestone

Comments

@Twilight-Shuxin
Copy link

Twilight-Shuxin commented Mar 20, 2023

Describe the bug

Given XML document:

<Y1 id="1">
  <H1 id="2" a2="2">true</H1>
</Y1>

and XPath query:
//*[starts-with(@a2,"1") = false()]

Exist db returns empty result set

Expected behavior

Should return

<Y1 id="1">
   <H1 id="2" a2="2">true</H1>
</Y1>
<H1 id="2" a2="2">true</H1>

as BaseX and Saxon

To Reproduce

  1. Go to Java admin client
  2. Add XML document to collection
  3. Use find command to execute XPath Query
  4. See error

Context (please always complete the following information)

  • Build: [eXist-6.2.0] (Also reproduced on latest development version built from source)
  • Java: [11] (With latest development version Java 17)
  • OS: [Windows]

Additional context

  • How is eXist-db installed? Jar installer
  • Any custom changes in e.g. conf.xml? No
@dizzzz dizzzz added the triage issue needs to be investigated label Mar 20, 2023
@dizzzz
Copy link
Member

dizzzz commented Mar 20, 2023

Are there any indexes defined?

@joewiz
Copy link
Member

joewiz commented Mar 20, 2023

I can reproduce this in eXist 6.2.0. Here's the XQSuite:

xquery version "3.1";

module namespace t="http://exist-db.org/xquery/test";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare variable $t:XML := document {
    <Y1 id="1">
        <H1 id="2" a2="2">true</H1>
    </Y1>
};

declare
    %test:setUp
function t:setup() {
    let $testCol := xmldb:create-collection("/db", "test")
    return
        xmldb:store("/db/test", "test.xml", $t:XML)
};

declare
    %test:tearDown
function t:tearDown() {
    xmldb:remove("/db/test")
};

declare
    %test:assertTrue
function t:test() {
    doc("/db/test/test.xml")//*[starts-with(@a2, "1") = false()]
    => exists()
};

The results showing the test failure:

<testsuite errors="0" failures="1" package="http://exist-db.org/xquery/test" pending="0" tests="1"
    time="PT0.003S" timestamp="2023-03-20T16:36:36.012-04:00">
    <testcase class="t:test" name="test">
        <failure message="assertTrue failed." type="failure-error-code-1"/>
        <output>false</output>
    </testcase>
</testsuite>

@joewiz joewiz added bug issue confirmed as bug and removed triage issue needs to be investigated labels Mar 20, 2023
@joewiz joewiz added this to the eXist-7.0.0 milestone Mar 20, 2023
@Twilight-Shuxin
Copy link
Author

Are there any indexes defined?

There is no index defined :)

@joewiz
Copy link
Member

joewiz commented Mar 21, 2023

A revised XQSuite, with XML trimmed of unnecessary info, and with an in-memory version that passes, when the version stored in the database fails:

xquery version "3.1";

module namespace t="http://exist-db.org/xquery/test";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare variable $t:XML := document {
    <X>
        <Y n="2"/>
    </X>
};

declare
    %test:setUp
function t:setup() {
    xmldb:create-collection("/db", "test"),
    xmldb:store("/db/test", "test.xml", $t:XML)
};

declare
    %test:tearDown
function t:tearDown() {
    xmldb:remove("/db/test")
};

declare
    %test:assertTrue
function t:test-db() {
    exists(
        doc("/db/test/test.xml")//*[starts-with(@n, "1") = false()]
    )
};

declare
    %test:assertTrue
function t:test-mem() {
    exists(
        $t:XML//*[starts-with(@n, "1") = false()]
    )
};

The results:

<testsuite errors="0" failures="1" package="http://exist-db.org/xquery/test" pending="0" tests="2"
    time="PT0.001S" timestamp="2023-03-20T23:30:23.526-04:00">
    <testcase class="t:test-db" name="test-db">
        <failure message="assertTrue failed." type="failure-error-code-1"/>
        <output>false</output>
    </testcase>
    <testcase class="t:test-mem" name="test-mem"/>
</testsuite>

@line-o
Copy link
Member

line-o commented Apr 4, 2023

This bug is closely related to #4824 as //*[somePredicate] does not iterate over the correct node set.

@line-o line-o added the xquery issue is related to xquery implementation label Apr 4, 2023
@line-o
Copy link
Member

line-o commented Apr 4, 2023

@Twilight-Shuxin I cannot reproduce the expected output with BaseX 10.4

The query <a><b c="1"/></a>//*[starts-with(@c, "a")=false()] does only return the inner element. And that is also meeting my expectations now that I learned what //* really stands for.

@line-o
Copy link
Member

line-o commented Apr 4, 2023

The test should be run agains document{<a><b c="1"/></a>}//*[starts-with(@c, "a")=false()] in eXist-db as that is where BaseX does return the expected results.
The document-node is the implicit root in this issue.

@line-o
Copy link
Member

line-o commented Apr 4, 2023

Exist-db does return the expected results as well when the document-node is added to the query.

@line-o
Copy link
Member

line-o commented Apr 4, 2023

For the given example that would be

xquery version "3.1";

let $test := document{<Y1 id="1"><H1 id="2" a2="2">true</H1></Y1>}

return
    $test//*[starts-with(@a2,"1") = false()]

@Twilight-Shuxin
Copy link
Author

Twilight-Shuxin commented Apr 4, 2023

@Twilight-Shuxin I cannot reproduce the expected output with BaseX 10.4

The query <a><b c="1"/></a>//*[starts-with(@c, "a")=false()] does only return the inner element. And that is also meeting my expectations now that I learned what //* really stands for.

Yes, I also had some misunderstandings on this issue, the expected result should only be when query is performed on the document. I will modify the report. Thanks for explaining!

@line-o
Copy link
Member

line-o commented Apr 4, 2023

@Twilight-Shuxin I cannot reproduce the reported issue when using the modified query

document{
  <Y1 id="1"><H1 id="2" a2="2">true</H1></Y1>
}//*[starts-with(@a2,"1") = false()]

returns

<Y1 id="1"><H1 id="2" a2="2">true</H1></Y1>,<H1 id="2" a2="2">true</H1>

tested on eXist-6.0.1 and 7.0.0-SNAPSHOT

@line-o line-o added investigate issues being looked at bug issue confirmed as bug and removed bug issue confirmed as bug labels Apr 4, 2023
@line-o
Copy link
Member

line-o commented Apr 4, 2023

Ah! This is a bug on persistent node-sets. @joewiz thanks for providing your findings and tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue confirmed as bug investigate issues being looked at xquery issue is related to xquery implementation
Projects
None yet
Development

No branches or pull requests

4 participants