Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
304 changes: 217 additions & 87 deletions docs/dqx/docs/reference/quality_rules.mdx

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions src/databricks/labs/dqx/check_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,68 @@ def is_not_in_near_future(column: str | Column, offset: int = 0, curr_timestamp:
)


@register_rule("row")
def is_equal_to(
column: str | Column, value: int | float | str | datetime.date | datetime.datetime | Column | None = None
) -> Column:
"""Check whether the values in the input column are equal to the given value.

Args:
column (str | Column): Column to check. Can be a string column name or a column expression.
value (int | float | str | datetime.date | datetime.datetime | Column | None, optional):
The value to compare with. Can be a literal or a Spark Column. Defaults to None.

Returns:
Column: A Spark Column condition that fails if the column value is not equal to the given value.
"""
col_str_norm, col_expr_str, col_expr = _get_normalized_column_and_expr(column)
value_expr = _get_limit_expr(value)
condition = col_expr != value_expr

return make_condition(
condition,
F.concat_ws(
"",
F.lit("Value '"),
col_expr.cast("string"),
F.lit(f"' in Column '{col_expr_str}' is not equal to value: "),
value_expr.cast("string"),
),
f"{col_str_norm}_not_equal_to_value",
)


@register_rule("row")
def is_not_equal_to(
column: str | Column, value: int | float | str | datetime.date | datetime.datetime | Column | None = None
) -> Column:
"""Check whether the values in the input column are not equal to the given value.

Args:
column (str | Column): Column to check. Can be a string column name or a column expression.
value (int | float | str | datetime.date | datetime.datetime | Column | None, optional):
The value to compare with. Can be a literal or a Spark Column. Defaults to None.

Returns:
Column: A Spark Column condition that fails if the column value is equal to the given value.
"""
col_str_norm, col_expr_str, col_expr = _get_normalized_column_and_expr(column)
value_expr = _get_limit_expr(value)
condition = col_expr == value_expr

return make_condition(
condition,
F.concat_ws(
"",
F.lit("Value '"),
col_expr.cast("string"),
F.lit(f"' in Column '{col_expr_str}' is equal to value: "),
value_expr.cast("string"),
),
f"{col_str_norm}_equal_to_value",
)


@register_rule("row")
def is_not_less_than(
column: str | Column, limit: int | datetime.date | datetime.datetime | str | Column | None = None
Expand Down
54 changes: 51 additions & 3 deletions src/databricks/labs/dqx/llm/resources/yaml_checks_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,42 @@
column: col3
min_limit: col2 + 10
max_limit: col2 * 10
- criticality: error
check:
function: is_equal_to
arguments:
column: col10
value: 2
- criticality: error
check:
function: is_equal_to
arguments:
column: col3
value: col2
- criticality: error
check:
function: is_not_equal_to
arguments:
column: col1
value: '''unknown'''
- criticality: error
check:
function: is_not_equal_to
arguments:
column: col5
value: 2025-02-24
- criticality: error
check:
function: is_not_equal_to
arguments:
column: col6
value: 2025-02-24 01:00:00
- criticality: error
check:
function: is_not_equal_to
arguments:
column: col3
value: col2 + 5
- criticality: error
check:
function: is_not_less_than
Expand Down Expand Up @@ -290,16 +326,28 @@
column: try_element_at(col4, 1)
- criticality: error
check:
function: is_not_greater_than
function: is_equal_to
arguments:
column: array_max(col4)
limit: 10
column: col8.field1
value: 1
- criticality: error
check:
function: is_not_equal_to
arguments:
column: try_element_at(col7, 'key1')
value: col10
- criticality: error
check:
function: is_not_less_than
arguments:
column: array_min(col4)
limit: 1
- criticality: error
check:
function: is_not_greater_than
arguments:
column: array_max(col4)
limit: 10
- criticality: error
check:
function: sql_expression
Expand Down
Loading
Loading