-
Notifications
You must be signed in to change notification settings - Fork 128
Allow custom check messages #1092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
c28d041
6721317
ab9a4ff
05baafb
468f229
e6fe9e5
0c2132f
c08cf31
b46ca2b
10313ce
e13b0ef
580a4af
6ec79a5
050c1d7
7ed09c7
52cd2df
4560ac6
f73a57d
c9a62a0
49c9a59
237a572
7d2ec21
7172765
2891bf0
80bcd2e
ec8dfd6
ebdf61e
a78bd20
1e169ea
0971779
7170d09
a950d73
dbf5137
243002c
0ff2415
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,9 +151,11 @@ def _build_result_struct(self, condition: Column, skipped: bool = False) -> Colu | |
| # or use literal run time if explicitly overridden | ||
| run_time_expr = F.current_timestamp() if self.run_time_overwrite is None else F.lit(self.run_time_overwrite) | ||
|
|
||
| message_col = self._build_message_col(condition) | ||
|
|
||
|
|
||
| return F.struct( | ||
| F.lit(self.check.name).alias("name"), | ||
| condition.alias("message"), | ||
| message_col.alias("message"), | ||
| self.check.columns_as_string_expr.alias("columns"), | ||
| F.lit(self.check.filter or None).cast("string").alias("filter"), | ||
| F.lit(self.check.check_func.__name__).alias("function"), | ||
|
|
@@ -167,6 +169,28 @@ def _build_result_struct(self, condition: Column, skipped: bool = False) -> Colu | |
| F.lit(skipped or None).alias("skipped"), | ||
|
mwojtyczka marked this conversation as resolved.
|
||
| ).cast(dq_result_item_schema) | ||
|
|
||
| def _build_message_col(self, condition: Column) -> Column: | ||
| """ | ||
| Builds the message column, using the default message or the user-supplied | ||
| ``message_expr`` from the rule definition. The expression is evaluated as-is — DQX | ||
| does not substitute placeholders. Accepts either a Spark SQL expression string or a | ||
| Spark Column. | ||
|
|
||
| Args: | ||
| condition: Default DQX condition message returned by evaluating the DQX check function | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When Passing as struct would be more flexible, but it will add significant complexity for users when defining the message func so maybe just document this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we should documente only |
||
|
|
||
| Returns: | ||
| The custom DQX condition message if ``message_expr`` is set on the rule, otherwise the | ||
| default DQX condition message. | ||
| """ | ||
| if self.check.message_expr is None: | ||
| return condition | ||
|
|
||
| custom_message = ( | ||
| self.check.message_expr if isinstance(self.check.message_expr, Column) else F.expr(self.check.message_expr) | ||
|
mwojtyczka marked this conversation as resolved.
Outdated
mwojtyczka marked this conversation as resolved.
Outdated
mwojtyczka marked this conversation as resolved.
Outdated
|
||
| ) | ||
| return F.when(condition.isNotNull(), custom_message).otherwise(F.lit(None).cast("string")) | ||
|
mwojtyczka marked this conversation as resolved.
Outdated
mwojtyczka marked this conversation as resolved.
Outdated
|
||
|
|
||
| def _get_invalid_cols_message(self) -> str: | ||
| """ | ||
| Returns invalid columns message containing info about invalid columns to check should be applied to or filter. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.