Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support int4range type #190

Closed
wants to merge 2 commits into from

Conversation

miketheman
Copy link
Contributor

This is an exploratory effort to support #164

It is not ready for merging, but I wanted to to open it for discussion
and review.

This is an exploratory effort to support will#164

It is not ready for merging, but I wanted to to open it for discussion
and review.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

def type
# TODO: do I actually need a new PG-specific type, or can we use real Crystal Ranges?
Range
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a specifically named Int4Range, or should the Range decoder emit a Crystal Range? Is the expectation that the end user desire to be super-specific about whether they are passing an Integer, BigInt, or Numeric type?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I've looked into ranges in crystal, but I think maybe postgres ranges have more "features" than crystal ranges.

In some cases, it is probably easy to normalize a postgres range into a crystal one, like how in the tests you have here the inclusive/exclusive adding 1. However in other cases it might not work, like for the float ranges and date ranges allowing positive and negative infinity. We may have to make our own range class for those. Or enhance the crystal stdlib ranges.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Range can take nil as start and/or end value, so maybe this could be used to represent infinity.

@@ -0,0 +1,10 @@
require "../../spec_helper"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new spec file to help organize the range specs outside of the regular specs - it looked like that's what happened with array_decoder_spec.cr
I guess if this turns into multiple structs for the different ranges, then maybe the decoder ought to be extracted as well?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don’t have any fully thought out reason, but it kinda makes sense since there will be a lot of related decoders for the ranges.

Copy link
Owner

@will will left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good first step. I'm curious how it evolves from a single range to supporting the different ranges, especially tstzrange

spec/pg/decoders/range_decoder_spec.cr Show resolved Hide resolved
@@ -0,0 +1,10 @@
require "../../spec_helper"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don’t have any fully thought out reason, but it kinda makes sense since there will be a lot of related decoders for the ranges.


def type
# TODO: do I actually need a new PG-specific type, or can we use real Crystal Ranges?
Range
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I've looked into ranges in crystal, but I think maybe postgres ranges have more "features" than crystal ranges.

In some cases, it is probably easy to normalize a postgres range into a crystal one, like how in the tests you have here the inclusive/exclusive adding 1. However in other cases it might not work, like for the float ranges and date ranges allowing positive and negative infinity. We may have to make our own range class for those. Or enhance the crystal stdlib ranges.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
@miketheman miketheman closed this Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants