Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

implement PartialOrd for days_ms and months_days_ns types #395

Closed
wants to merge 1 commit into from

Conversation

houqp
Copy link
Collaborator

@houqp houqp commented Sep 11, 2021

No description provided.

@jorgecarleitao
Copy link
Owner

Thanks a lot, @houqp ! Unfortunately, intervals do not seem to have a natural order (at least in Java and C++). See this comment from @emkornfield, which led me to remove the PartialOrd from both interval types.

@houqp houqp closed this Sep 11, 2021
@houqp
Copy link
Collaborator Author

houqp commented Sep 11, 2021

Interesting, that's a good call. It looks like days_ms should have an order though right?

On that note, this is causing problem in datafusion because ScalarValue now implements PartialOrd. I am going think about what's the best way to handle it.

@emkornfield
Copy link

it is still unclear to me if day_ms is supposed to have ms normalized to less then a day (in which case partial order makes sense). but month, day, nanos do not based on how we defined them.

@houqp
Copy link
Collaborator Author

houqp commented Sep 11, 2021

@jorgecarleitao how about we implement partial_cmp for months days manually to always return None?

@jorgecarleitao
Copy link
Owner

Good idea on using the Option aspect here.

If ns is less than a day and days is less than 28 we do have an order; else we return None (and equivalent for day_ms)?

@houqp
Copy link
Collaborator Author

houqp commented Sep 11, 2021

@emkornfield good point on the ms part. After thinking more on this, I think we can define a better partial_cmp implementation for both types instead of just always return None.

For months_days, we can check for the days component, if it's less than 28, then it's safe to return an order.

@houqp
Copy link
Collaborator Author

houqp commented Sep 11, 2021

ha, never mind, @jorgecarleitao beat me to it :D

@houqp
Copy link
Collaborator Author

houqp commented Sep 11, 2021

I think this is exactly what partial order is for, return no order when there is ambiguity.

@jorgecarleitao
Copy link
Owner

exactly, great idea, @houqp with the None!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants