From 9724c993419952fbcbeb8cd19e51a723fc663b04 Mon Sep 17 00:00:00 2001 From: Darwin Correa Date: Mon, 8 Jul 2024 13:58:28 -0500 Subject: [PATCH] feat: add support to NOT LIKE operator (#29384) --- .../packages/superset-ui-core/src/query/types/Operator.ts | 1 + superset/models/helpers.py | 5 +++++ superset/utils/core.py | 1 + 3 files changed, 7 insertions(+) diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/Operator.ts b/superset-frontend/packages/superset-ui-core/src/query/types/Operator.ts index 5b598312c..0d2cb5b59 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/types/Operator.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/types/Operator.ts @@ -30,6 +30,7 @@ const BINARY_OPERATORS = [ '<=', 'ILIKE', 'LIKE', + 'NOT LIKE', 'REGEX', 'TEMPORAL_RANGE', ] as const; diff --git a/superset/models/helpers.py b/superset/models/helpers.py index b841426ff..1c6ad2f5d 100644 --- a/superset/models/helpers.py +++ b/superset/models/helpers.py @@ -1909,6 +1909,11 @@ class ExploreMixin: # pylint: disable=too-many-public-methods where_clause_and.append(sqla_col.like(eq)) else: where_clause_and.append(sqla_col.ilike(eq)) + elif op in {utils.FilterOperator.NOT_LIKE.value}: + if target_generic_type != GenericDataType.STRING: + sqla_col = sa.cast(sqla_col, sa.String) + + where_clause_and.append(sqla_col.not_like(eq)) elif ( op == utils.FilterOperator.TEMPORAL_RANGE.value and isinstance(eq, str) diff --git a/superset/utils/core.py b/superset/utils/core.py index ee5e451f3..d01dd517e 100644 --- a/superset/utils/core.py +++ b/superset/utils/core.py @@ -217,6 +217,7 @@ class FilterOperator(StrEnum): GREATER_THAN_OR_EQUALS = ">=" LESS_THAN_OR_EQUALS = "<=" LIKE = "LIKE" + NOT_LIKE = "NOT LIKE" ILIKE = "ILIKE" IS_NULL = "IS NULL" IS_NOT_NULL = "IS NOT NULL"