You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: demos/dqx_demo_pii_detection.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
# MAGIC # Using DQX for PII Detection
4
4
# MAGIC Increased regulation makes Databricks customers responsible for any Personally Identifiable Information (PII) stored in Unity Catalog. Companies need to be able to perform PII detection for data at-rest and in-transit to proactively quarantine or anonymize PII before persisting the data.
5
5
# MAGIC
6
-
# MAGIC DQX provides in-flight data quality monitoring for Spark `DataFrames`. You can apply checks, get row-level metadata, and quarantine failing records. Workloads can also use DQX's built-in functions to check `DataFrames` for PII.
6
+
# MAGIC DQX provides in-transit data quality monitoring for Spark `DataFrames`. You can apply checks, get row-level metadata, and quarantine failing records. Workloads can also use DQX's built-in functions to check `DataFrames` for PII.
|**In-flight**| Code-level only | DQX allows data quality to be validated on the fly while the data is being processed, before it is written to storage. This requires DQX to be used as a library and integrated directly into user pipelines. |
24
+
|**In-transit**| Code-level only | DQX allows data quality to be validated on the fly while the data is being processed, before it is written to storage. This requires DQX to be used as a library and integrated directly into user pipelines. |
25
25
|**At-rest**| Code-level or No-code (Workflows) | DQX enables data quality checking on existing data stored in tables. For no-code integration, DQX must first be installed in the workspace as a tool to deploy workflows. |
For local execution without a Databricks workspace, please refer to the [local testing section](/docs/reference/testing/#local-testing-with-dqengine).
44
+
For local execution without a Databricks workspace, please refer to the [local testing section](/docs/reference/testing/#local-execution-and-testing-with-dqengine).
45
45
46
46
## DQX engine methods
47
47
@@ -60,11 +60,11 @@ The following table outlines the available methods of the `DQEngine` and their f
60
60
|`validate_checks`| Validates the provided quality checks to ensure they conform to the expected structure and types. |`checks`: List of checks to validate; `custom_check_functions`: (optional) dictionary of custom check functions that can be used; `validate_custom_check_functions`: (optional) if set to True, validates custom check functions (defaults to True). | Yes |
61
61
|`get_invalid`| Retrieves records from the DataFrame that violate data quality checks (records with warnings and errors). |`df`: Input DataFrame. | Yes |
62
62
|`get_valid`| Retrieves records from the DataFrame that pass all data quality checks. |`df`: Input DataFrame. | Yes |
63
-
|`load_checks`| Loads quality rules (checks) from storage backend. Multiple storage backends are supported including tables, files or workspace files, installation-managed sources where the location is inferred automatically from run config|`config`: Configuration for loading checks from a storage backend, i.e. `FileChecksStorageConfig`: file in a local filesystem (YAML or JSON), or workspace files if invoked from Databricks notebook or job; `WorkspaceFileChecksStorageConfig`: file in a workspace (YAML or JSON) using absolute paths; `VolumeFileChecksStorageConfig`: file in a Unity Catalog Volume (YAML or JSON); `TableChecksStorageConfig`: a table; `InstallationChecksStorageConfig`: installation-managed storage backend, using the `checks_location` field from the run configuration. See more details below. | Yes (only with `FileChecksStorageConfig`) |
64
-
|`save_checks`| Saves quality rules (checks) to storage backend. Multiple storage backends are supported including tables, files or workspace files, installation-managed targets where the location is inferred automatically from run config|`checks`: List of checks defined as dictionary; `config`: Configuration for saving checks in a storage backend, i.e. `FileChecksStorageConfig`: file in a local filesystem (YAML or JSON), or workspace files if invoked from Databricks notebook or job; `WorkspaceFileChecksStorageConfig`: file in a workspace (YAML or JSON); `VolumeFileChecksStorageConfig`: file in a Unity Catalog Volume (YAML or JSON); `TableChecksStorageConfig`: a table; `InstallationChecksStorageConfig`: storage defined in the installation context, using the `checks_location` field from the run configuration. See more details below. | Yes (only with `FileChecksStorageConfig`) |
63
+
|`load_checks`| Loads quality rules (checks) from storage backend. Multiple storage backends are supported including tables, files or workspace files, installation-managed sources where the location is inferred automatically from run config.|`config`: Configuration for loading checks from a storage backend, i.e. `FileChecksStorageConfig`: file in a local filesystem (YAML or JSON), or workspace files if invoked from Databricks notebook or job; `WorkspaceFileChecksStorageConfig`: file in a workspace (YAML or JSON) using absolute paths; `VolumeFileChecksStorageConfig`: file in a Unity Catalog Volume (YAML or JSON); `TableChecksStorageConfig`: a table; `InstallationChecksStorageConfig`: installation-managed storage backend, using the `checks_location` field from the run configuration. See more details below. | Yes (only with `FileChecksStorageConfig`) |
64
+
|`save_checks`| Saves quality rules (checks) to storage backend. Multiple storage backends are supported including tables, files or workspace files, installation-managed targets where the location is inferred automatically from run config.|`checks`: List of checks defined as dictionary; `config`: Configuration for saving checks in a storage backend, i.e. `FileChecksStorageConfig`: file in a local filesystem (YAML or JSON), or workspace files if invoked from Databricks notebook or job; `WorkspaceFileChecksStorageConfig`: file in a workspace (YAML or JSON); `VolumeFileChecksStorageConfig`: file in a Unity Catalog Volume (YAML or JSON); `TableChecksStorageConfig`: a table; `InstallationChecksStorageConfig`: storage defined in the installation context, using the `checks_location` field from the run configuration. See more details below. | Yes (only with `FileChecksStorageConfig`) |
65
65
|`save_results_in_table`| Save quality checking results in delta table(s). |`output_df`: (optional) Dataframe containing the output data; `quarantine_df`: (optional) Dataframe containing the output data; `output_config`: `OutputConfig` object with the table name, output mode, and options for the output data; `quarantine_config`: `OutputConfig` object with the table name, output mode, and options for the quarantine data - if provided, data will be split; `run_config_name`: Name of the run config to use; `assume_user`: If True, assume user installation. | No |
66
66
67
-
The 'Supports local execution' in the above table indicates which methods can be used for local testing without a Databricks workspace (see the usage in [local testing section](/docs/reference/testing/#local-testing-with-dqengine)).
67
+
The 'Supports local execution' in the above table indicates which methods can be used for local testing without a Databricks workspace (see the usage in [local testing section](/docs/reference/testing/#local-execution-and-testing-with-dqengine)).
68
68
69
69
`InputConfig` support the following parameters:
70
70
*`location`: The location of the input data source (e.g. table name or file path).
Copy file name to clipboardExpand all lines: docs/dqx/docs/reference/quality_checks.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2650,8 +2650,8 @@ This is because the metadata format relies on string representations that can't
2650
2650
DQX provides both built-in PII detection and support for custom PII detection implementations. PII detection checks can be installed and run as extras:
PII detection using natural language models is non-deterministic. DQX cannot guarantee detection of all PII in an input dataset. While DQX makes a best-effort to detect PII in your data, a broader system should be designed to ensure data is cleansed of PII.
Copy file name to clipboardExpand all lines: docs/dqx/docs/reference/testing.mdx
+27-26Lines changed: 27 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,14 +114,25 @@ To run the integration tests on serverless compute, add the `DATABRICKS_SERVERLE
114
114
```
115
115
When `DATABRICKS_SERVERLESS_COMPUTE_ID` is set, the `DATABRICKS_CLUSTER_ID` is ignored, and tests run on serverless compute.
116
116
117
-
### Local testing with DQEngine
117
+
### Local execution and testing with DQEngine
118
118
119
-
If workspace-level access is unavailable in your testing environment, you can perform local testing by installing the latest `pyspark` package and mocking the workspace client.
120
-
Below is an example test.
119
+
If workspace-level access is unavailable in your environment, you can execute DQX locally without workspace connection by installing the latest `pyspark` package and mocking the workspace client:
You need a python version that is compatible with the pyspark version, e.g. Python 3.9, 3.10, 3.11, and 3.12 are compatible with PySpark 3.5, but Python 3.13 is not supported.
131
+
</Admonition>
121
132
122
133
<Admonitiontype="tip"title="Usage tips">
123
134
**This approach should be treated as experimental!** It does not offer the same level of testing as the standard approach, and it is only applicable to selected methods (see [here](/docs/reference/engine/#dqx-engine-methods)).
124
-
We strongly recommend following the standard testing procedure outlined above, which includes proper initialization of the workspace client.
135
+
We strongly recommend following the standard execution procedure outlined above, which includes proper initialization of the workspace client.
125
136
</Admonition>
126
137
127
138
<Tabs>
@@ -130,35 +141,25 @@ We strongly recommend following the standard testing procedure outlined above, w
130
141
from unittest.mock import MagicMock
131
142
from databricks.sdk import WorkspaceClient
132
143
from pyspark.sql import SparkSession
133
-
from chispa.dataframe_comparer import assert_df_equality
134
-
from databricks.labs.dqx.check_funcs import is_not_null_and_not_empty
144
+
from databricks.labs.dqx.check_funcs import is_not_null
135
145
from databricks.labs.dqx.engine import DQEngine
136
146
from databricks.labs.dqx.rule import DQRowRule
137
-
from databricks.labs.dqx.schema import dq_result_schema
138
147
148
+
spark = SparkSession.builder.master("local[*]").getOrCreate() # create spark local session
149
+
ws = MagicMock(spec=WorkspaceClient) # mock the workspace client
139
150
140
-
deftest_dq():
141
-
spark = SparkSession.builder.master("local[*]").getOrCreate() # create spark local session
142
-
ws = MagicMock(spec=WorkspaceClient, **{"current_user.me.return_value": None}) # mock the workspace client
0 commit comments