Your question is Unit Test Spark Transformation Output. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
In Databricks, unit-testing a Spark transformation often means verifying that an output collection of rows matches the expected result even when row order is not guaranteed. Implement a Python function that compares two datasets and reports whether they are equivalent after applying deterministic normalization rules.
Write a function assert_spark_rows_equal(actual_rows, expected_rows, key_columns).
actual_rows: list of dictionaries representing transformed output rowsexpected_rows: list of dictionaries representing expected rowskey_columns: list of column names used to sort rows deterministically before comparisonThe function should return True if:
key_columnsNormalization rules:
Nonedef assert_spark_rows_equal(actual_rows, expected_rows, key_columns):