diff --git a/chispa/schema_comparer.py b/chispa/schema_comparer.py index c2e2150..90ceb19 100644 --- a/chispa/schema_comparer.py +++ b/chispa/schema_comparer.py @@ -34,7 +34,7 @@ def inner(s1, s2, ignore_nullable, ignore_metadata): t = PrettyTable(["schema1", "schema2"]) zipped = list(zip_longest(s1, s2)) for sf1, sf2 in zipped: - if are_structfields_equal(sf1, sf2, True): + if are_structfields_equal(sf1, sf2, ignore_nullable, ignore_metadata): t.add_row([blue(sf1), blue(sf2)]) else: t.add_row([sf1, sf2]) @@ -70,12 +70,12 @@ def assert_schema_equality_ignore_nullable(s1, s2): # deprecate this. ignore_nullable should be a flag. -def are_schemas_equal_ignore_nullable(s1, s2): +def are_schemas_equal_ignore_nullable(s1, s2, ignore_metadata=False): if len(s1) != len(s2): return False zipped = list(zip_longest(s1, s2)) for sf1, sf2 in zipped: - if not are_structfields_equal(sf1, sf2, True): + if not are_structfields_equal(sf1, sf2, True, ignore_metadata): return False return True @@ -95,11 +95,11 @@ def are_structfields_equal(sf1, sf2, ignore_nullability=False, ignore_metadata=F if not ignore_metadata and sf1.metadata != sf2.metadata: return False else: - return are_datatypes_equal_ignore_nullable(sf1.dataType, sf2.dataType) + return are_datatypes_equal_ignore_nullable(sf1.dataType, sf2.dataType, ignore_metadata) # deprecate this -def are_datatypes_equal_ignore_nullable(dt1, dt2): +def are_datatypes_equal_ignore_nullable(dt1, dt2, ignore_metadata=False): """Checks if datatypes are equal, descending into structs and arrays to ignore nullability. """ @@ -108,7 +108,7 @@ def are_datatypes_equal_ignore_nullable(dt1, dt2): if dt1.typeName() == "array": return are_datatypes_equal_ignore_nullable(dt1.elementType, dt2.elementType) elif dt1.typeName() == "struct": - return are_schemas_equal_ignore_nullable(dt1, dt2) + return are_schemas_equal_ignore_nullable(dt1, dt2, ignore_metadata) else: return True else: diff --git a/tests/test_structfield_comparer.py b/tests/test_structfield_comparer.py index a6d181d..287f451 100644 --- a/tests/test_structfield_comparer.py +++ b/tests/test_structfield_comparer.py @@ -55,3 +55,8 @@ def it_returns_true_when_nested_types_have_different_nullability_with_ignore_nul sf1 = StructField("hi", StructType([StructField("world", IntegerType(), False)]), False) sf2 = StructField("hi", StructType([StructField("world", IntegerType(), True)]), False) assert are_structfields_equal(sf1, sf2, ignore_nullability=True) is True + + def it_returns_true_when_inner_metadata_is_different_but_ignored(): + sf1 = StructField("hi", StructType([StructField("world", IntegerType(), False)]), False) + sf2 = StructField("hi", StructType([StructField("world", IntegerType(), False, {"a": "b"})]), False) + assert are_structfields_equal(sf1, sf2, ignore_metadata=True) is True