Performs the test for non-null and non-blank values in one or more columns of a DataFrame.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Examples:
>>> from pyspark.sql import SparkSession
>>> from pyspark.sql.types import StructType, StructField, StringType
>>> spark = SparkSession.builder.getOrCreate()
>>> data = [
... ("123.456.789-00", "Maria Silva", ""),
... ("987.654.321-00", "Joao Souza", "joao.souza@example.com"),
... (None, "Carlos Pereira", "carlos.pereira@example.com")
... ]
>>> schema = StructType([
... StructField("cpf", StringType(), True),
... StructField("full_name", StringType(), True),
... StructField("email", StringType(), True)
... ])
>>> df = spark.createDataFrame(data, schema)
>>> required_columns = {
... "cpf": "error",
... "email": "warning"
... }
>>> try:
... result = not_null_test(df, required_columns)
... except Exception as e:
... print(e)
Not Null Test Failed: Columns with NULL or blank values found!
Logs:
-
ERROR: Not Null Test Failed: cpf has 1 NULL or blank values!
-
WARNING: Not Null Test Warning: email has 1 NULL or blank values!
-
Exception: Not Null Test Failed: Columns with NULL or blank values found! # noqa : E501