@@ -130,14 +130,15 @@ def sql_expression(expression: str, msg: str | None = None, name: str | None = N
130
130
expression_msg = expression
131
131
132
132
if negate :
133
- expr_col = ~ expr_col
134
133
expression_msg = "~(" + expression + ")"
134
+ message = F .concat_ws ("" , F .lit (f"Value is matching expression: { expression_msg } " ))
135
+ else :
136
+ expr_col = ~ expr_col
137
+ message = F .concat_ws ("" , F .lit (f"Value is not matching expression: { expression_msg } " ))
135
138
136
139
name = name if name else re .sub (normalize_regex , "_" , expression )
137
140
138
- if msg :
139
- return make_condition (expr_col , msg , name )
140
- return make_condition (expr_col , F .concat_ws ("" , F .lit (f"Value matches expression: { expression_msg } " )), name )
141
+ return make_condition (expr_col , msg or message , name )
141
142
142
143
143
144
def is_older_than_col2_for_n_days (col_name1 : str , col_name2 : str , days : int = 0 ) -> Column :
@@ -256,7 +257,7 @@ def is_not_less_than(
256
257
"""Checks whether the values in the input column are not less than the provided limit.
257
258
258
259
:param col_name: column name
259
- :param limit: limit to use in the condition as number, date, timestamp, column name or expression
260
+ :param limit: limit to use in the condition as number, date, timestamp, column name or sql expression
260
261
:return: new Column
261
262
"""
262
263
limit_expr = _get_column_expr_limit (limit )
@@ -275,7 +276,7 @@ def is_not_greater_than(
275
276
"""Checks whether the values in the input column are not greater than the provided limit.
276
277
277
278
:param col_name: column name
278
- :param limit: limit to use in the condition as number, date, timestamp, column name or expression
279
+ :param limit: limit to use in the condition as number, date, timestamp, column name or sql expression
279
280
:return: new Column
280
281
"""
281
282
limit_expr = _get_column_expr_limit (limit )
@@ -296,8 +297,8 @@ def is_in_range(
296
297
"""Checks whether the values in the input column are in the provided limits (inclusive of both boundaries).
297
298
298
299
:param col_name: column name
299
- :param min_limit: min limit to use in the condition as number, date, timestamp, column name or expression
300
- :param max_limit: max limit to use in the condition as number, date, timestamp, column name or expression
300
+ :param min_limit: min limit to use in the condition as number, date, timestamp, column name or sql expression
301
+ :param max_limit: max limit to use in the condition as number, date, timestamp, column name or sql expression
301
302
:return: new Column
302
303
"""
303
304
min_limit_expr = _get_column_expr_limit (min_limit )
@@ -329,8 +330,8 @@ def is_not_in_range(
329
330
"""Checks whether the values in the input column are outside the provided limits (inclusive of both boundaries).
330
331
331
332
:param col_name: column name
332
- :param min_limit: min limit to use in the condition as number, date, timestamp, column name or expression
333
- :param max_limit: min limit to use in the condition as number, date, timestamp, column name or expression
333
+ :param min_limit: min limit to use in the condition as number, date, timestamp, column name or sql expression
334
+ :param max_limit: min limit to use in the condition as number, date, timestamp, column name or sql expression
334
335
:return: new Column
335
336
"""
336
337
min_limit_expr = _get_column_expr_limit (min_limit )
@@ -364,11 +365,9 @@ def regex_match(col_name: str, regex: str, negate: bool = False) -> Column:
364
365
"""
365
366
if negate :
366
367
condition = F .col (col_name ).rlike (regex )
367
-
368
368
return make_condition (condition , f"Column { col_name } is matching regex" , f"{ col_name } _matching_regex" )
369
369
370
370
condition = ~ F .col (col_name ).rlike (regex )
371
-
372
371
return make_condition (condition , f"Column { col_name } is not matching regex" , f"{ col_name } _not_matching_regex" )
373
372
374
373
@@ -460,7 +459,7 @@ def _get_column_expr_limit(
460
459
) -> Column :
461
460
"""Helper function to generate a column expression limit based on the provided limit value.
462
461
463
- :param limit: limit to use in the condition (literal value or Column expression)
462
+ :param limit: limit to use in the condition (literal value or column expression)
464
463
:return: column expression.
465
464
:raises ValueError: if limit is not provided.
466
465
"""
0 commit comments