Performs the relationship test (referential integrity) between two DataFrames based on a foreign key of the first DataFrame and the primary key of the target DataFrame.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Examples:
>>> from pyspark.sql import SparkSession
>>> from pyspark.sql.types import ( # noqa : F401
... StructType,
... StructField,
... IntegerType,
... StringType,
... )
>>> spark = SparkSession.builder.getOrCreate()
>>> foreign_data = [
... (1, "Record1"),
... (2, "Record2"),
... (3, "Record3"),
... (4, "Record4")
... ]
>>> foreign_columns = ["id", "value"]
>>> target_data = [
... (1, "Target1"),
... (2, "Target2"),
... (3, "Target3")
... ]
>>> target_columns = ["id_target", "target_value"]
>>> foreign_df = spark.createDataFrame(foreign_data, foreign_columns)
>>> target_df = spark.createDataFrame(target_data, target_columns)
>>> try:
... result = relationship_test(
... foreign_df,
... target_df,
... 'id',
... 'id_target'
... )
... except Exception as e:
... print(e)
Data Quality Check Failed: Found 1 unmatched records!
Logs:
-
ERROR: Data Quality Check Failed: Found 1 unmatched records!
-
INFO: Data Quality Check: Successfully processed relationship test.