Validates if a column in a DataFrame contains only accepted values.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Examples:
>>> from pyspark.sql import SparkSession
>>> from pyspark.sql.types import StructType, StructField, StringType
>>> spark = SparkSession.builder.getOrCreate()
>>> schema = StructType([
... StructField("id", StringType(), True),
... StructField("value", StringType(), True)
... ])
>>> data = [("A", "PT"), ("B", "EN"), ("C", "PT")]
>>> df = spark.createDataFrame(data, schema)
>>> valid_values = ["FR", "EN"]
>>> try:
... result = accepted_values_test(df, "value", valid_values)
... except ValueError as e:
... print(e)
Invalid values found in column 'value': ['PT']
Logs:
-
INFO: Invalid values found in column 'value': ['value']
-
INFO: Data Quality Check: Successfully processed freshness test.