-
Notifications
You must be signed in to change notification settings - Fork 228
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
Dictionary (hstore, json, and jsonb) query support #3285
base: main
Are you sure you want to change the base?
Conversation
8f6dad8
to
49431a8
Compare
92992e5
to
1d6ee17
Compare
src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlHstoreTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlHstoreTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlHstoreTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlHstoreTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlHstoreTranslator.cs
Outdated
Show resolved
Hide resolved
test/EFCore.PG.FunctionalTests/TestModels/Dictionary/DictionaryContainerEntity.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @yinzara, looks pretty good overall! See comments below.
If you translate Keys via |
df2adf1
to
b4e4966
Compare
Apologies for the mountains of force pushes :-) I just kept realizing there was more I could do or make better :-) I think I'm done now lol all tests pass and everything I could possibly translate I have translated. I would have loved to have supported: string[] keys = ["key1", "key2"];
_ => _.Store.Keys.Any(k => keys.Contains(k))
which would become
"Store" ?| __keys and the equivalent .All => ?& however that simply isn't possible using the IMethodCallTranslator or a IMemberTranslator FINALLY |
I started to write up the changes to the I've still got a few more test cases to write, but the new and improved For more details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yinzara thanks for making these changes and for the enthusiasm.
First, in any case where there's a straightforward LINQ construct that can be used to express something, that's preferred over introducing a method on EF.Functions. For example, something like ContainsAnyKeys can be expressed in LINQ via dict.Keys.Contains(foo)
, so I wouldn't introduce EF.Functions.ContainsAnyKeys(). It's indeed a bit more complicated to do translations like the former (not possible in a method translator), but I think it's fine to leave them out for the time being.
Second, I appreciate the work, but I'd rather we didn't eagerly introduced translations for each and every possible thing that PostgreSQL supports, but rather base the work on what users actually express a need for. The hstore type generally is rarely used, and crucially, has been made somewhat obsolete by PG's json support - JSON can do pretty much everything hstore can, and more. Remember that at the end of the day, I have to maintain all this stuff going forward...!
So I'd be happier if at least as a first step, we added the basic, simple stuff which users would be more likely to use, and then wait for people to actually ask for more features before implementing them.
Hope that makes sense.
So it turns out this PR and its related issue is highly related to dotnet/efcore#29825 I think that I can actually change this PR so that it is focused on that instead and just happens to work with 'hstore' types as well that way this ends up being something people want as a whole. That would mean I'd refocus the PR on translating any Dictionary or ImmutableDictionary query no matter if it's hstore, json or jsonb |
50c95a9
to
961a7df
Compare
@roji This PR is now focused 100% on all forms of I removed all of the DBFunction extensions that could ever have a translation that would be supported without the DBFunctions. A future PR (or maybe if I get ansy) can address doing the expression visitor changes to support the other queries. I now have a test case with a Finally I made the new This does not fix dotnet/efcore#26903 as I was thinking it might, but it still seems quite useful overall and eventually it could support it. |
I know it's been a while since you've had time to look at this. Any chance you could take a peak and at least tell me if you are ok with my direction now? If so I'll update all the test cases and make sure it's ready for merge. |
@@ -135,6 +135,7 @@ protected override void Print(ExpressionPrinter expressionPrinter) | |||
PgExpressionType.JsonExists => "?", | |||
PgExpressionType.JsonExistsAny => "?|", | |||
PgExpressionType.JsonExistsAll => "?&", | |||
PgExpressionType.JsonValueForKeyAsText => "->>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this isn't necessary now and I'll make sure it's removed before the PR merges.
@yinzara I'll do my best to look soon, but it's a very busy time in the post 9.0 phase; so it may take a little while. Don't hesitate to ping me again in a month or two if you see no progress here. |
This PR adds support for querying on
hstore
type columns which can map to eitherDictionary<string, string>
orImmutableDictionary<string, string>
in C# and for querying any otherDictionary<,>
orImmutableDictionary<,>
forjson
andjsonb
types.See npgsql/doc#369 for full documentation.
Fixes #212