Skip to content

Conversation

@vonzshik
Copy link
Contributor

Closes #4898

@vonzshik vonzshik force-pushed the 4898-make-ranges-opt-in branch from 4d4b77c to b0bebcd Compare January 21, 2023 16:52
@vonzshik vonzshik force-pushed the 4898-make-ranges-opt-in branch from c7026df to 9a14eb3 Compare January 22, 2023 13:13
@vonzshik vonzshik force-pushed the 4898-make-ranges-opt-in branch from 9a14eb3 to a6e2a9a Compare February 1, 2023 12:17
@vonzshik vonzshik force-pushed the 4898-make-ranges-opt-in branch from a6e2a9a to 50029f2 Compare February 11, 2023 16:33
@vonzshik vonzshik force-pushed the 4898-make-ranges-opt-in branch from 50029f2 to 234618b Compare February 26, 2023 17:39
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

BTW I wonder if it doesn't make sense also split multiranges into their own opt-in resolver, with the logic that using them is maybe even more rare than using ranges.

@vonzshik vonzshik force-pushed the 4898-make-ranges-opt-in branch from 234618b to 69fec32 Compare February 26, 2023 22:12
};
}

static DateTimeKind GetRangeKind(NpgsqlRange<DateTime> 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.

I really don't like the fact that BuildInTypeHandlerResolver still references ranges, but without that it's going to make mapping quite difficult (you would have to add range resolver on GlobalTypeMapper) 😭

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't adding the range resolver to GlobalTypeMapper undo what this PR is trying to do, i.e. allow all the range stuff to get trimmed? If we did that, all the ranges/range handlers would become visible again via the GlobalTypeMapper...

Yeah, this is a crappy situation, but it's a result of us having to resolve mapping stuff on NpgsqlParameter without having an actual connection (e.g. in "static" context); this has always been a pain.

We can consider breaking this, and making the getters on NpgsqlParameter (DbType, NpgsqlDbType, DataTypeName) work only if the parameter is attached to a command and through that to a connection (which has a type mapper). Or we could have a minimum, "default" mapping list on GlobalTypeMapper which doesn't include the ranges, and if the parameter is attached to a connection, go to its resolvers. This way, if you've opted into ranges on your data source, NpgsqlParameter.NpgsqlDbType will know about it, otherwise it won't.

Maybe open a separate issue for thinking about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't adding the range resolver to GlobalTypeMapper undo what this PR is trying to do, i.e. allow all the range stuff to get trimmed? If we did that, all the ranges/range handlers would become visible again via the GlobalTypeMapper...

Not exactly. We don't need to return a handler from GlobalTypeMapper, just an ability to resolve a mapping by value. We pretty much only need:

  1. Dictionary<string, TypeMappingInfo> (where string is dataTypeName)
  2. Dictionary<Type, string> (where string is dataTypeName)
  3. ValueDependentValueToDataTypeName (and that's because of DataTime.Kind, where we can return either tstzrange or tsrange)

Maybe open a separate issue for thinking about it?

Yeah, sure.

Copy link
Member

Choose a reason for hiding this comment

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

Not exactly. We don't need to return a handler from GlobalTypeMapper, just an ability to resolve a mapping by value.

Hmm.. Right, I remember now that GlobalTypeMapper only deals with type handler factories (which also manage the "static" global mappings). But adding the range resolver factory to the global mapper would also make it available for actually creating the resolver, which is where the trimming problems come in.

We could refactor to split the static mapping thing from the resolver factory (it's a bit ugly that both functions are combined in the factory anyway). At that point we can always add the range global mapping resolver (or whatever we call it), but not have a resolver factory for it without the opt-in...

Anyway, I think it's OK to deal with it after this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyway, I think it's OK to deal with it after this PR.

Yeah, we should think about this later.

@vonzshik vonzshik marked this pull request as ready for review February 26, 2023 22:52
@vonzshik vonzshik requested a review from roji February 26, 2023 22:59
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

LGTM but see the unresolved comments

@vonzshik vonzshik merged commit 98a41c5 into main Feb 27, 2023
@vonzshik vonzshik deleted the 4898-make-ranges-opt-in branch February 27, 2023 12:01
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.

Make range/multirange support opt-in

2 participants