apache / apache/datafusion

`PartialOrd` for structs with incomparable fields

Open
#12,537 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

### Is your feature request related to a problem or challenge?

> What requires this manual derivation? Is it some other extension trait would need to also require `PartialOrd`?
>
> I am thinking it would be really nice to file a ticket tracking what it would take to use a derived `PartialOrd` to make this code more maintainable

_Originally posted by @alamb in https://github.com/apache/datafusion/pull/12481#discussion_r1761693610_

#12481 gives a possible implementation for PartialOrd, using a mix of manual implementations and derivations. The main blocker on using only derivations is `DFSchemaRef`, which is an incomparable type, along with the associated `Schema`, and minorly `HashMap`.

### Describe the solution you'd like

There are a couple of possible solutions. One simple one might be to just give a manual implementation of `PartialOrd` for `DFSchemaRef` that just returns `None`, allowing for types using it to derive `PartialOrd`. However, this would still leave a gap for the other datatypes used.

### Describe alternatives you've considered

Another solution would be to use something like the [derivative](https://crates.io/crates/derivative) crate, but that means another attribute for the struct, and additional attributes for the fields being excluded.

The current alternate solution being used for structs with >3 fields in #12481 is to have a inner struct for the `PartialOrd` manual implementation, that excludes in incomparable fields. This is easier to maintain, but also has a few drawbacks.

### Additional context

Relevant: #8932.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing PR #12481 and the existing PartialOrd implementations involving DFSchemaRef, Schema, and HashMap; issue #8932 provides additional context. Determine which incomparable fields and struct patterns the project needs to support, then define and validate an agreed approach for maintainable derived or manual ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.