Skip to content

Commit

Permalink
[core][fix] Turn off regexp rewriting (#2142)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Jul 18, 2024
1 parent 4093b0a commit 5e7611f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion fixcore/fixcore/db/arango_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
regexp_leading_trailing = re.compile(r"(^\^?[.][*])|([.][*][$]?$)")
# see: cli.py
DefaultSort = [Sort("reported.kind"), Sort("reported.name"), Sort("reported.id")]
# Disabled for the moment, since likes are case-sensitive and regex are not
TranslateRegexpToLike = False


class ArangoQueryContext:
Expand Down Expand Up @@ -170,7 +172,7 @@ def empty_and_simple(value: Any) -> bool:
)

def regexp_like(value: Any) -> Optional[str]:
if not isinstance(value, str):
if not TranslateRegexpToLike or not isinstance(value, str):
return None
ml = regexp_leading_trailing.sub("", value)
ml = ml.replace("%", "\\%").replace("_", "\\_").replace(".*", "%").replace(".", "_")
Expand Down
14 changes: 8 additions & 6 deletions fixcore/tests/fixcore/db/arango_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
possible_values,
load_time_series,
history_query,
TranslateRegexpToLike,
)
from fixcore.db.graphdb import GraphDB
from fixcore.db.model import QueryModel
Expand Down Expand Up @@ -438,12 +439,13 @@ def assert_view(query: str, expected: str, **kwargs: Any) -> Tuple[str, Json]:
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
assert_view('name=~"^123"', "SEARCH v0.name LIKE @b0", b0="123%")
assert_view('name=~"^.*123$"', "SEARCH v0.name LIKE @b0", b0="%123")
assert_view('name=~".*123$"', "SEARCH v0.name LIKE @b0", b0="%123")
assert_view('name=~"^123$"', "SEARCH v0.name LIKE @b0", b0="123")
assert_view('name=~"^%1%2%.*3%$"', "SEARCH v0.name LIKE @b0", b0="\\%1\\%2\\%%3\\%")
assert_view('name=~"^...$"', "SEARCH v0.name LIKE @b0", b0="___")
if TranslateRegexpToLike:
assert_view('name=~"^123"', "SEARCH v0.name LIKE @b0", b0="123%")
assert_view('name=~"^.*123$"', "SEARCH v0.name LIKE @b0", b0="%123")
assert_view('name=~".*123$"', "SEARCH v0.name LIKE @b0", b0="%123")
assert_view('name=~"^123$"', "SEARCH v0.name LIKE @b0", b0="123")
assert_view('name=~"^%1%2%.*3%$"', "SEARCH v0.name LIKE @b0", b0="\\%1\\%2\\%%3\\%")
assert_view('name=~"^...$"', "SEARCH v0.name LIKE @b0", b0="___")

# cannot use like since regex cannot be expressed as glob. needs filter
assert_view('name=~"123[0-9]+"',
Expand Down

0 comments on commit 5e7611f

Please sign in to comment.