Skip to content

Commit

Permalink
fix(server/pypika/filter): Fix "notmatches" operator for backends usi…
Browse files Browse the repository at this point in the history
…ng REGEXP (#1507)

relates to TCTC-3808

Signed-off-by: Luka Peschke <luka.peschke@toucantoco.com>
  • Loading branch information
lukapeschke authored Oct 4, 2022
1 parent 0906b44 commit 8ffacc3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ def _get_single_condition_criterion(
elif condition.operator == "notmatches":
match self.REGEXP_OP:
case RegexOp.REGEXP:
return column_field.regexp(condition.value).negate()
return column_field.regexp(compliant_regex).negate()
case RegexOp.SIMILAR_TO:
return BasicCriterion(
RegexpMatching.not_similar_to,
Expand Down
30 changes: 30 additions & 0 deletions server/tests/backends/fixtures/filter/notmatches_pypika.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
exclude:
- mongo
- pandas
- snowflake
step:
pipeline:
- condition:
column: name
operator: notmatches
value: beer
name: filter
- columns:
- name
name: select
expected:
data:
- name: Ninkasi Ploploplop
- name: Brewdog Nanny State Alcoholvrij
- name: Ardwen Blonde
- name: "Cuv\xE9e des Trolls"
- name: Weihenstephan Hefe Weizen Alcoholarm
- name: Bellfield Lawless Village IPA
- name: Pauwel Kwak
- name: Brasserie De Sutter Brin de Folie
- name: Brugse Zot blonde
schema:
fields:
- name: name
type: string
pandas_version: 1.4.0
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_notmatches_regexp_filter(
ctx = regexp_translator.filter(step=step, columns=selected_columns, **default_step_kwargs)
expected_query = (
Query.from_(previous_step)
.where(Field(column).regexp(regex).negate())
.where(Field(column).regexp(f"%{regex}%").negate())
.select(*selected_columns)
)

Expand Down Expand Up @@ -358,7 +358,7 @@ def test_notmatches_regexp__like_filter(
ctx = regexp_translator.filter(step=step, columns=selected_columns, **default_step_kwargs)
expected_query = (
Query.from_(previous_step)
.where(Field(column).regexp(regex).negate())
.where(Field(column).regexp(f"%{regex}%").negate())
.select(*selected_columns)
)

Expand Down Expand Up @@ -417,7 +417,7 @@ def test_notmatches_regexp__contains_filter(
ctx = regexp_translator.filter(step=step, columns=selected_columns, **default_step_kwargs)
expected_query = (
Query.from_(previous_step)
.where(Field(column).regexp(regex).negate())
.where(Field(column).regexp(f"%{regex}%").negate())
.select(*selected_columns)
)

Expand Down

0 comments on commit 8ffacc3

Please sign in to comment.