From 16df325e88006e47cc34937f80a2868114cbc79e Mon Sep 17 00:00:00 2001 From: Matthias Veit Date: Thu, 5 Sep 2024 13:29:21 +0200 Subject: [PATCH] [core][fix] arangosearch predicates with array access (#2179) --- fixcore/fixcore/db/arango_query.py | 15 ++++++++------- fixcore/tests/fixcore/db/arango_query_test.py | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fixcore/fixcore/db/arango_query.py b/fixcore/fixcore/db/arango_query.py index c57420c2a9..46259e302b 100644 --- a/fixcore/fixcore/db/arango_query.py +++ b/fixcore/fixcore/db/arango_query.py @@ -270,13 +270,8 @@ def view_term(term: Term) -> Tuple[Optional[str], Term]: # we filter the list down as much as possible, but leave the context term untouched is_array_context = bool(array_marker.search(term.name)) context_in_array = context_in_array or is_array_context - # arangosearch view does not handle nested array searches correctly - # see: https://github.com/arangodb/arangodb/issues/21281 - # once this is resolved we can enable the next 3 lines - # - # sp, ct = view_term(term.predicate_term()) - # return sp, term if is_array_context else ct - return (None, term) if is_array_context else view_term(term.predicate_term()) + sp, ct = view_term(term.predicate_term()) + return sp, term if is_array_context else ct elif isinstance(term, IdTerm): if len(term.ids) == 1: sp = f"{crs}._key == @{ctx.add_bind_var(term.ids[0])}" @@ -301,6 +296,12 @@ def view_term(term: Term) -> Tuple[Optional[str], Term]: return None, term return combine_optional(lsp, rsp, lambda ll, rr: f"({ll} {term.op} {rr})"), lt.combine(term.op, rt) elif isinstance(term, Predicate): + # arangosearch view does not handle nested array searches correctly + # see: https://github.com/arangodb/arangodb/issues/21281 + # once this is resolved we can delete the next 2 lines + if term.op in ["!=", "not in"] and bool(array_marker.search(term.name)): + return "true", term # true will not filter anything leaving the term for the filter + return predicate_term(term) else: return None, term diff --git a/fixcore/tests/fixcore/db/arango_query_test.py b/fixcore/tests/fixcore/db/arango_query_test.py index 8651b64ba4..26e1708efa 100644 --- a/fixcore/tests/fixcore/db/arango_query_test.py +++ b/fixcore/tests/fixcore/db/arango_query_test.py @@ -437,7 +437,6 @@ def assert_view(query: str, expected: str, **kwargs: Any) -> Tuple[str, Json]: # asking for a specific element in an array can leverage the view assert_view("g[*]==1", "SEARCH v0.g == @b0 RETURN v0") assert_view("g[*] in [1,2,3]", "SEARCH v0.g in @b0 RETURN v0) FOR result in view0") - assert_view("g[*] not in [1,2,3]", "SEARCH v0.g not in @b0 RETURN v0) FOR result in view0") # use like instead of regex if TranslateRegexpToLike: assert_view('name=~"^123"', "SEARCH v0.name LIKE @b0", b0="123%")