Skip to content

Incorrect implementation of PartialOrd for ScalarUDF, WindowUDF and AggregateUDF #17064

Closed

Description

@findepi

PartialOrd implementation for ScalarUDF, WindowUDF and AggregateUDF compares name and signature only.
PartialEq implementation for these structs delegates to the function implementation and thus may compare other properties.

the contract for these traits is (https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html):

a == b if and only if partial_cmp(a, b) == Some(Equal).
[...]

thus the contract is violated

We should remove these incorrect PartialOrd implementations.

Activity

  1. added
    bugSomething isn't working
    api changeChanges the API exposed to users of the crate
    on Aug 7, 2025
  2. added theissue type on Aug 7, 2025
  3. findepi commented on Aug 8, 2025

    @findepi
    MemberAuthor

    Removing the PartialOrd would be the best way to go.
    This would probably mean removing PartialOrd from Expr, perhaps reverting

    cc @ngli-me @jayzhan211 @alamb

  4. alamb commented on Aug 12, 2025

    @alamb
    Contributor

    Getting it consistent would be very good, thank you @findepi

  5. findepi commented on Aug 12, 2025

    @findepi
    MemberAuthor

    Getting it consistent would require delegating to UDF impl, just like we do with Eq and Hash in #16677. (and thus a breaking change).
    Echoing @jayzhan211 's suggestion #12421 (comment), I'd like to understand whether we can remove PartialOrd instead.
    Why do we have ordering?

  6. alamb commented on Aug 13, 2025

    @alamb
    Contributor

    Why do we have ordering?

    I think it was used to generate a consistent canonical version of an expression

    For example to ensure that IN (x, y, z) and IN(y, z, x) were the same, and that the join predicates are normalized or something

    I can't remember the specifics though

  7. findepi commented on Aug 13, 2025

    @findepi
    MemberAuthor

    For this having partial ordering, or ordering by a partial projection from an Expr, should be sufficient.

    However, there remains a problem of discrepancy between PartialOrd and PartialEq/Eq impls.
    We can fix the PartialOrd implementation by consulting Eq. Maybe something like

  8. alamb commented on Sep 10, 2025

    @alamb
    Contributor

    🎉

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    api changeChanges the API exposed to users of the cratebugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions