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 bug on selecting nodes with last() #4824

Open
Twilight-Shuxin opened this issue Mar 23, 2023 · 7 comments
Open

[BUG] XQuery bug on selecting nodes with last() #4824

Twilight-Shuxin opened this issue Mar 23, 2023 · 7 comments
Labels
bug issue confirmed as bug xquery issue is related to xquery implementation
Milestone

Comments

@Twilight-Shuxin
Copy link

Twilight-Shuxin commented Mar 23, 2023

Describe the bug

Given XML document:

<A1 id="1">
  <B1 id="2"></B1>
</A1>

(No index defined)

and XPath query:

//*[last() <= 1]

Exist db returns empty result set

Expected behavior

Should return

<A1 id="1">
   <B1 id="2"/>
</A1>
<B1 id="2"/>

as BaseX, Saxon and Oracle

To Reproduce

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 {
    <A><B></B></A>
};

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:assertEquals("2")
function t:test-db() {
    count(
        doc("/db/test/test.xml")//*[last() <= 1]
    )
};
  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: latest development version built from source, commit b700a92
  • Java: 17
  • OS: [Windows]

Additional context

  • How is eXist-db installed? Jar installer
  • Any custom changes in e.g. conf.xml? No
@Twilight-Shuxin Twilight-Shuxin changed the title [BUG] Bug on selecting nodes with last() [BUG] XQuery bug on selecting nodes with last() Mar 23, 2023
@Twilight-Shuxin
Copy link
Author

Twilight-Shuxin commented Mar 23, 2023

I'm not very sure whether this is considered to be a bug or not, and might not be a common expression? Therefore it might not be of great importance or require a fix. Thanks!

@joewiz joewiz added the bug issue confirmed as bug label Mar 23, 2023
@joewiz joewiz added this to the eXist-7.0.0 milestone Mar 23, 2023
@joewiz
Copy link
Member

joewiz commented Mar 23, 2023

I can reproduce these results on 6.2.0.

A bug is a bug! Thank you for your reports!

My hunch is that this report is a variation of the earlier ones, and that solving them will solve this.

@line-o
Copy link
Member

line-o commented Mar 23, 2023

It is definitely a valid predicate. I am just not sure what it actually does :)

edit: Maybe it selects all elements, if there are less than 2 selected in the current XPath step.

@line-o
Copy link
Member

line-o commented Mar 23, 2023

in saxon <A><B></B></A>//*[last() <= 1] returns <B/>

@line-o
Copy link
Member

line-o commented Mar 23, 2023

The results in Saxon are ... mixed
https://xqueryfiddle.liberty-development.net/bdxZ98

@Twilight-Shuxin
Copy link
Author

Thank you very much!

@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

Christian Grün was so kind to explain to me what //*[somePredicate] actually means.

//*[last()] is a shortcut for /descendant-or-self::node()/child::*[last()]. It will give you the last child of each node of a document.

This can only mean that eXistdb is currently not rewriting the shortcut //* to the correct long form.

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

No branches or pull requests

3 participants