krishnakeshan commented on code in PR #10902:
URL: https://github.com/apache/arrow-rs/pull/10902#discussion_r3890324170
##########
arrow-schema/src/datatype.rs:
##########
@@ -864,6 +863,76 @@ impl DataType {
pub fn new_fixed_size_list(data_type: DataType, size: i32, nullable: bool)
-> Self {
DataType::FixedSizeList(Arc::new(Field::new_list_field(data_type,
nullable)), size)
}
+ /// Compares this [`DataType`] with `other` for semantic equality,
according
+ /// to the rules configured by `gauge`.
+ ///
+ /// Unlike the derived [`PartialEq`], this recursively compares nested
+ /// [`Field`]s (e.g. the element field of a [`DataType::List`], or the
+ /// fields of a [`DataType::Struct`]) while letting the caller ignore
+ /// aspects of those fields that don't matter for their use case, such as
+ /// field names, nullability, or metadata. This is useful when comparing
+ /// data types that describe logically-compatible data but were built
+ /// with different conventions, e.g. a `List` whose inner field is named
+ /// `"item"` vs. one named `"element"`.
+ ///
+ /// # Example
+ /// ```
+ /// use std::sync::Arc;
+ /// use arrow_schema::{DataType, SemanticEqualityOptions, Field};
+ ///
+ /// let ignore_names = SemanticEqualityOptions {
+ /// check_nullibility: true,
+ /// check_field_name: false,
+ /// check_metadata: true,
+ /// };
+ ///
+ /// let a = DataType::new_list(DataType::Int32, true);
+ /// let b = DataType::List(Arc::new(Field::new("element", DataType::Int32,
true)));
+ ///
+ /// assert_ne!(a, b);
+ /// assert!(a.semantic_equality(&b, &ignore_names));
+ /// ```
+ pub fn semantic_equality(&self, other: &DataType, options:
&SemanticEqualityOptions) -> bool {
+ fn fields_eq(a: &Field, b: &Field, gauge: &SemanticEqualityOptions) ->
bool {
Review Comment:
should we call the last parameter also `options`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]