-
Notifications
You must be signed in to change notification settings - Fork 1
feat: normalize logically equivalent types (Utf8→LargeUtf8, etc.) #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -73,7 +73,7 @@ mod tests { | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||
| encode(ArrowDigester::new(schema.clone()).finalize()), | ||||||||||||||||||||||||||||||
| "0000019c75bd0c40bd2fb15e878418c151c0b792c966476b35ded7d0f6fd1922cf5a00" | ||||||||||||||||||||||||||||||
| "000001a5b5cd3fade0d81c59f10f99461aaaf6b970f116c82a4e7d5a70af17f008709b" | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let batch = RecordBatch::try_new( | ||||||||||||||||||||||||||||||
|
|
@@ -129,7 +129,7 @@ mod tests { | |||||||||||||||||||||||||||||
| // Hash the record batch | ||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||
| encode(ArrowDigester::hash_record_batch(&batch)), | ||||||||||||||||||||||||||||||
| "0000019944840b176dd3a88382dd08d77b50084d2b63b805c113780b8810babf01bba1" | ||||||||||||||||||||||||||||||
| "000001907c152d6b459901d86f1555b60846f4a5b646f6d8c5c6962014505eeaa39296" | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -199,18 +199,18 @@ mod tests { | |||||||||||||||||||||||||||||
| let hash = hex::encode(ArrowDigester::hash_array(&binary_array)); | ||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||
| hash, | ||||||||||||||||||||||||||||||
| "000001c73893c594350c05117a934571e7a480693447a319e269b36fa03c470383f2be" | ||||||||||||||||||||||||||||||
| "000001331f179fa074a02afbb060d5f38e776fb63d69494650934bafa51f6d5264f576" | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Test large binary array with same data to ensure consistency | ||||||||||||||||||||||||||||||
| // Large binary array with same data should produce the same hash (type normalization) | ||||||||||||||||||||||||||||||
| let large_binary_array = LargeBinaryArray::from(vec![ | ||||||||||||||||||||||||||||||
| Some(b"hello".as_ref()), | ||||||||||||||||||||||||||||||
| None, | ||||||||||||||||||||||||||||||
| Some(b"world".as_ref()), | ||||||||||||||||||||||||||||||
| Some(b"".as_ref()), | ||||||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| assert_ne!( | ||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||
| hex::encode(ArrowDigester::hash_array(&large_binary_array)), | ||||||||||||||||||||||||||||||
| hash | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
@@ -263,14 +263,14 @@ mod tests { | |||||||||||||||||||||||||||||
| let hash = hex::encode(ArrowDigester::hash_array(&string_array)); | ||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||
| hash, | ||||||||||||||||||||||||||||||
| "00000150f4ed059207a4606f71b278be3dd53869c65a22549d900f90c35da4df5c309e" | ||||||||||||||||||||||||||||||
| "0000017d2325032dd496c5ccbce50ea6afd7edf8e10d0f1695a5b35d1e8f3759b1b3e6" | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Test large string array with same data to ensure consistency | ||||||||||||||||||||||||||||||
| // Large string array with same data should produce the same hash (type normalization) | ||||||||||||||||||||||||||||||
| let large_string_array = | ||||||||||||||||||||||||||||||
| LargeStringArray::from(vec![Some("hello"), None, Some("world"), Some("")]); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| assert_ne!( | ||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||
| hex::encode(ArrowDigester::hash_array(&large_string_array)), | ||||||||||||||||||||||||||||||
| hash | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
@@ -289,7 +289,7 @@ mod tests { | |||||||||||||||||||||||||||||
| let hash = hex::encode(ArrowDigester::hash_array(&list_array)); | ||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||
| hash, | ||||||||||||||||||||||||||||||
| "00000105fc3ecc3e20fea732e2a4bedbbd58ab40b5d1f19ca324b5f3d8116b21c0d649" | ||||||||||||||||||||||||||||||
| "00000186ba22789af5e728982c0ed5c78dcc382e8cc9124bcdbd794638ee05a79f6796" | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| // LargeList array with the same logical values should produce the same hash | |
| let large_list_array = LargeListArray::from_iter_primitive::<Int32Type, _, _>(vec![ | |
| Some(vec![Some(1), Some(2), Some(3)]), | |
| None, | |
| Some(vec![Some(4), Some(5)]), | |
| Some(vec![Some(6)]), | |
| ]); | |
| let hash_large = hex::encode(ArrowDigester::hash_array(&large_list_array)); | |
| assert_eq!( | |
| hash_large, hash, | |
| "ListArray and LargeListArray with the same logical values should hash identically" | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normalize_data_type()only normalizes the top-levelDataType. Inhash_array(), this means nested logically-equivalent types can still hash differently (e.g.,List<Utf8>vsLargeList<LargeUtf8>will serialize differentDataTypemetadata even though the underlying values are equivalent). Consider making normalization recursive for list element fields (and also normalizing the child field type forLargeList), or reusingdata_type_to_value()/canonical JSON for array type metadata so nested offset-size variants are canonicalized too.