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

[fo] array:index-where #114

Closed
michaelhkay opened this issue May 4, 2022 · 4 comments
Closed

[fo] array:index-where #114

michaelhkay opened this issue May 4, 2022 · 4 comments
Labels
Feature A change that introduces a new feature XQFO An issue related to Functions and Operators

Comments

@michaelhkay
Copy link
Contributor

There is a need for an array:index-where() function to operate on arrays in the same way as fn:index-where() operates on sequences/

Use case: consider XMark query Q4, which uses the << operator:

(: Q4. List the reserves of those open auctions where a
       certain person issued a bid before another person. :)

for    $b in /site/open_auctions/open_auction
where  $b/bidder/personref[@person="person18829"] <<
            $b/bidder/personref[@person="person10487"]
return <history>{ $b/reserve }</history>

With the bidders held in an array like this:

     "bidders": [
        { "increase":18, "time":"13:16:15", "date":"2001-06-13", "personref":"person0" },
        { "increase":12, "time":"11:29:44", "date":"2000-09-18", "personref":"person23" },
        { "increase":18, "time":"10:23:59", "date":"1998-01-07", "personref":"person14" },
        { "increase":4.5, "time":"14:00:39", "date":"2001-07-10", "personref":"person16" }
      ],

the best way of expressing this query seems to be:

for    $b in ?open_auctions?*
let    $bidders := $b?bidders
where  array:index-where($bidders, ->($bidder) {$bidder?personref="person18829"}) <
            array:index-where($bidders, ->($bidder) {$bidder?personref="person10487"})
return <history>{ $b?reserve }</history>
@cedporter cedporter added XQFO An issue related to Functions and Operators Feature A change that introduces a new feature labels Sep 14, 2022
michaelhkay added a commit to michaelhkay/qtspecs that referenced this issue Nov 18, 2022
@dnovatchev
Copy link
Contributor

The currently provided oracle implementation in the spec is written in XQuery :

for $item at $position in $input where $predicate($item) return $position

and is more complex than the following pure XPath 3.1 implementation:

index-of($seq ! $pred(.), true())

Besides being simpler, the Xpath expression above can be directly used in both XSLT and XQuery, without needing any changes/adaptation.

@michaelhkay Could we use the above pure XPath 3.0 definition/implementation of the semantics of this function?

@michaelhkay
Copy link
Contributor Author

Sure, no problems.

@dnovatchev
Copy link
Contributor

index-of($seq ! $pred(.), true())

Sorry, I thought this was the fn:index-where, and for that the above expression works.

One XPath oracle function for array:index-where is:

index-of(array:members($array) ! $pred(.), true())

ndw added a commit that referenced this issue Dec 13, 2022
@ndw
Copy link
Contributor

ndw commented Dec 13, 2022

Closed by #258.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature A change that introduces a new feature XQFO An issue related to Functions and Operators
Projects
None yet
Development

No branches or pull requests

4 participants