Consider this XQuery:
declare namespace _="urn:_"; declare function _:query-index___($dict as xs:string, $ind as xs:string, $str as xs:string) { let $rs := (# db:enforceindex #) { switch ($ind) case "any" return collection($dict)//index/w[text() contains text { $str } using wildcards] default return if ($str = '*') then collection($dict)//index[@id = $ind]/w else collection($dict)//index[@id = $ind]/w[text() contains text { $str } using wildcards] } return $rs };
_:query-index___('dc_arz_eng_publ__ind', 'any', 'beer.*')
where dc_arz_eng_publ__ind contians a single XML which looks like (probably irrelevant):
<indices> <index id="lem"> <w>-</w> <w>mafṛama</w> <w>without</w> </index> <index id="other"> </index> </indices>
There is a java.lang.ArrayIndexOutOfBoundsException:
Version: BaseX 9.7.2 Java: Azul Systems, Inc., 11.0.14.1 OS: Windows 10, amd64 Stack Trace: java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 8 at org.basex.query.var.QueryStack.get(QueryStack.java:99) at org.basex.query.QueryContext.get(QueryContext.java:553) at org.basex.query.var.VarRef.value(VarRef.java:46) at org.basex.query.expr.ParseExpr.atomValue(ParseExpr.java:61) at org.basex.query.expr.Expr.atomItem(Expr.java:116) at org.basex.query.func.fn.Docs.collection(Docs.java:36) at org.basex.query.func.fn.FnCollection.value(FnCollection.java:15) at org.basex.query.expr.index.IndexDynDb.data(IndexDynDb.java:86) at org.basex.query.expr.index.IndexDb.data(IndexDb.java:35) at org.basex.query.expr.ft.FTWords.iter(FTWords.java:153) at org.basex.query.expr.ft.FTIndexAccess.iter(FTIndexAccess.java:43) at org.basex.query.expr.ft.FTIndexAccess.value(FTIndexAccess.java:63) at org.basex.query.expr.path.CachedPath.nodes(CachedPath.java:43) at org.basex.query.expr.path.AxisPath.value(AxisPath.java:41) at org.basex.query.expr.Extension.value(Extension.java:59) at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:46) at org.basex.query.expr.gflwor.For$1.next(For.java:112) at org.basex.query.expr.gflwor.Let$LetEval.next(Let.java:144) at org.basex.query.expr.gflwor.OrderBy$1.sort(OrderBy.java:73) at org.basex.query.expr.gflwor.OrderBy$1.next(OrderBy.java:54) at org.basex.query.expr.gflwor.GFLWOR$1.next(GFLWOR.java:68) at org.basex.query.QueryContext.next(QueryContext.java:359) at org.basex.query.expr.constr.Constr.add(Constr.java:73) at org.basex.query.expr.constr.CElem.item(CElem.java:149) at org.basex.query.expr.constr.CElem.item(CElem.java:1) at org.basex.query.expr.ItemMap.item(ItemMap.java:29) at org.basex.query.expr.ParseExpr.value(ParseExpr.java:51) at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:46) at org.basex.query.scope.MainModule.iter(MainModule.java:60) at org.basex.query.QueryContext.iter(QueryContext.java:338) at org.basex.http.restxq.RestXqResponse.serialize(RestXqResponse.java:85) at org.basex.http.web.WebResponse.create(WebResponse.java:58) at org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:72) at org.basex.http.BaseXServlet.service(BaseXServlet.java:69) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1450) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:600) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.Server.handle(Server.java:516) at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) at java.base/java.lang.Thread.run(Thread.java:829)
If I don't use (# db:enforceindex #) {} it works as expected
Best regards
Omar,
Thanks for your observation and the reproducible query. The bug turns out to be an intricate one, so I’ve opened an issue for it [1].
Meanwhile, you can circumvent the problem by suppressing the inlining of the function …
declare %basex:inline(0) function _:query-index___( ...
… and (if that doesn’t suffice) by replacing …
let $rs := (# db:enforceindex #) { ... } return $rs
… by …
(# db:enforceindex #) { ... }
Best, Christian
The bug fix has been fixed, a new snapshot is available [1].
Best, Christian
[1] https://files.basex.org/releases/latest/
On Mon, Jun 20, 2022 at 10:52 PM Christian Grün christian.gruen@gmail.com wrote:
Omar,
Thanks for your observation and the reproducible query. The bug turns out to be an intricate one, so I’ve opened an issue for it [1].
Meanwhile, you can circumvent the problem by suppressing the inlining of the function …
declare %basex:inline(0) function _:query-index___( ...
… and (if that doesn’t suffice) by replacing …
let $rs := (# db:enforceindex #) { ... } return $rs
… by …
(# db:enforceindex #) { ... }
Best, Christian
basex-talk@mailman.uni-konstanz.de