Skip to content

Commit

Permalink
[core][fix] arangosearch predicates with array access (#2179)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Sep 5, 2024
1 parent 7cda232 commit 16df325
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 8 additions & 7 deletions fixcore/fixcore/db/arango_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])}"
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion fixcore/tests/fixcore/db/arango_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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%")
Expand Down

0 comments on commit 16df325

Please sign in to comment.