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

range:index-keys-for-field with dynamic context only works correctly when wrapped inside dynamic function call #1226

Closed
olvidalo opened this Issue Jan 15, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@olvidalo
Contributor

olvidalo commented Jan 15, 2017

range:index-keys-for-field("some-field", function($key, $nums) { $key }, 10)`

returns all keys for some-field for the statically known documents.

collection("/db/some-collection/")/range:index-keys-for-field("some-field", function($key, $nums) { $key }, 10)`

will evaluate the function for each document in the collection instead of for the context document set at once, so it returns the keys multiple times for each document instead of once for the collection

let $func := function-lookup(xs:QName("range:index-keys-for-field"), 3) 
return  collection("/db/some-collection/")/$func("some-field", function($key, $nums) { $key }, 10)

however, wrapping it inside a dynamic function will make it work

let $func := function($a, $b, $c) {
    range:index-keys-for-field($a, $b, $c)
}

return  collection("/db/some-collection/")/$func("some-field", function($key, $nums) { $key }, 10)

also works

declare function local:func($a, $b, $c) {
  range:index-keys-for-field($a, $b, $c )  
};

return  collection("/db/some-collection/")/local:func("some-field", function($key, $nums) { $key }, 10)

does not work

It might have something to do with the expression dependencies being incorrectly set at one point down the stack (the evaluation path leading to the incorrect results seems to start in PathExpr.eval() when the expression's dependencies are determined) but as I have no idea what I'm actually talking about I'll leave it at that for the time being...

There'll be a pull request with a test coming in shortly

@olvidalo olvidalo changed the title from ft:index-keys with dynamic context only works correctly when wrapped inside dynamic function call to range:index-keys-for-field with dynamic context only works correctly when wrapped inside dynamic function call Jan 15, 2017

@dizzzz

This comment has been minimized.

Member

dizzzz commented Jan 15, 2017

did you test this with eXist-db 3.0RC2/develop ?

@olvidalo

This comment has been minimized.

Contributor

olvidalo commented Jan 15, 2017

Tested it with the current develop commit

@duncdrum

This comment has been minimized.

Member

duncdrum commented Mar 6, 2018

if the test is passing, this seems to be fixed?

@dizzzz dizzzz closed this Mar 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment