Skip to content

Add a way to compare datatype for "semantic compatibility / equality" #3199

Open

Description

@alamb

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
In apache/datafusion#4346 from DataFusion, we have a check that between each optimization pass the schema hasn't changed (see apache/datafusion#4233 by @jackwener).

However it turns out that some passes may change the metadata or nullability for a plan which is ok, but this causes the schema equality check to fail incorrectly

Describe the solution you'd like
I would like a function that does "semanic equality" checking of a datatype -- specifically one that ignores any metadata or nullability information and only compares:

  1. field_name
  2. data_type

Describe alternatives you've considered
We can keep the code entirely in datafusion -- see initial implementation in apache/datafusion#4347

Additional context
As suggested by @mingmwang on apache/datafusion#4347 (comment)

Activity

  1. added
    arrow
    enhancement
    on Nov 26, 2022
  2. tustvold commented on Nov 26, 2022

    @tustvold
    Contributor
  3. alamb commented on Nov 27, 2022

    @alamb
    ContributorAuthor

    that sounds good to me

  4. Rich-T-kid commented on Aug 25, 2026

    @Rich-T-kid
    Contributor

    take

  5. Rich-T-kid commented on Aug 27, 2026

    @Rich-T-kid
    Contributor

    seems like arrow-cmp would be a nice destination for this function

  6. Rich-T-kid commented on Aug 27, 2026

    @Rich-T-kid
    Contributor

    actually it seems like this was implemented in datafusion apache/datafusion#4347

    @alamb is there any interest to place this logic in arrow-rs still or should we close this issues?

  7. alamb commented on Aug 27, 2026

    @alamb
    ContributorAuthor

    though arrow-cmp is mostly about comparing data -- I don't think it is really for comparing scheams

    Probably arrow-schema is best

    @alamb is there any interest to place this logic in arrow-rs still or should we close this issues?

    I think it would only make sense to put in arrow-rs if there are other users other than DataFUsion that would use it

    Since what "semantically compatible" means may be pretty specific to each use case, I am not sure how much value moving the code to arrow-rs would bring

  8. Rich-T-kid commented on Aug 27, 2026

    @Rich-T-kid
    Contributor

    Probably arrow-schema is best

    make sense to me.

    Since what "semantically compatible" means may be pretty specific to each use case, I am not sure how much value moving the code to arrow-rs would bring

    I was thinking of introducing an enum/struct that would serve as a gauge for how in-depth the comparison would be:

    struct EquivalenceGauge {
        check_nullability: bool,
        check_field_name: bool,
        check_metadata: bool,
    }
    

    fn compare_datatype(dt_1: &DataType, dt_2: &DataType, eq: EquivalenceGauge) -> bool

    decided to go with a struct since it allows us to update this in the future without making it a breaking api change

  9. Rich-T-kid commented on Aug 28, 2026

    @Rich-T-kid
    Contributor

    Probably arrow-schema is best

    make sense to me.

    Since what "semantically compatible" means may be pretty specific to each use case, I am not sure how much value moving the code to arrow-rs would bring

    I was thinking of introducing an enum/struct that would serve as a gauge for how in-depth the comparison would be:

    struct EquivalenceGauge {
        check_nullability: bool,
        check_field_name: bool,
        check_metadata: bool,
    }
    

    fn compare_datatype(dt_1: &DataType, dt_2: &DataType, eq: EquivalenceGauge) -> bool

    decided to go with a struct since it allows us to update this in the future without making it a breaking api change

    implemented in #10902 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arrowenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions