- 
        Couldn't load subscription status. 
- Fork 249
Dictionary (hstore, json, and jsonb) query support #3285
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
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
  
    | @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. | 
| 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. | 
| I've now rebased this PR off of the hotfix/9.4 release as the  All tests are now passing in this PR and I think it's ready for a real review. Would this go into a maintenance release of 9 or will this PR eventually have to be targeted against  | 
| @yinzara sorry this is taking so long to merge. In principle, as this is a new feature, it needs to go into 10 and not into 9; aside from a few exceptions, only bug fixes go into patch releases. So can you please rebase back on top of main? Re the preview SDK, it should be pretty easy to set up - you can use the dotnet-install scripts to download the specific version of the SDK specified in the project's global.json, and use that. | 
| I've rebased against  | 
| SqlExpression? instance, | ||
| MethodInfo method, | ||
| IReadOnlyList<SqlExpression> arguments, | ||
| IDiagnosticsLogger<DbLoggerCategory.Query> logger) | 
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.
Here I attempted to "return null quickly" as much as possible so that you did the least amount of operations before returning null. The logic below was what I found to be the best combination while still being readable and efficient.
| /// any release. You should only use it directly in your code with extreme caution and knowing that | ||
| /// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
| /// </summary> | ||
| public SqlExpression? Keys(SqlExpression instance) | 
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 choose to make these methods public and not private so they could be used externally to this translator eventually (i.e. in some expression visitor translator for more complex translations).  Honestly internal probably would have been enough but I didn't see that used in a lot of places.
All public methods accept arguments of either json/jsonb or hstore arguments and return the translation or null if the arguments are not json/jsonb/hstore.
Thoughts?
| new NpgsqlDateTimeMemberTranslator(typeMappingSource, sqlExpressionFactory), | ||
| new NpgsqlJsonDomTranslator(typeMappingSource, sqlExpressionFactory, model), | ||
| new NpgsqlLTreeTranslator(typeMappingSource, sqlExpressionFactory, model), | ||
| new DictionaryTranslator(typeMappingSource, sqlExpressionFactory, model), | 
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.
Needs to be before the JsonPocoTranslator as it needs to intercept methods on Dictionary types that are json types.
        
          
                src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMemberTranslatorProvider.cs
          
            Show resolved
            Hide resolved
        
              
          
                src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMemberTranslatorProvider.cs
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/EFCore.PG/Query/Internal/NpgsqlQueryableMethodTranslatingExpressionVisitor.cs
          
            Show resolved
            Hide resolved
        
      9bcdc30    to
    c76f04d      
    Compare
  
    | I have now verified that all tests are passing locally after the rebase to  | 
| Ping | 
| I know this is kind of a big PR to review but I really feel like this could be a big .NET 10 feature. Queryable dictionaries of every type seems pretty helpful! Any chance you could get back to it? @roji | 
| @roji It has now been 10 months from my original submission. This feature is one that has been requested by users for more than 8 years and it is fully implemented. You had said you would get to this after the .NET 9 release which was now more than 6 months ago. This feature is fully implemented IMHO and ready for merge. Can I please get a review? | 
| This is a great PR, I hope it will get into version 10 release. Especially mapping of  | 
| @yinzara sorry that this hasn't received more attention in the previous months, I've simply been too busy (the PG provider has generally received very little attention). I admit this isn't on the top of my list generally, since hstore isn't exactly a widely-used/requested feature (the fact that something is open for X years isn't an indication that it's highly-needed, especially given it has received 6 votes total in all that time). But in any case I'll do my best to devote some time to EFCore.PG in the coming weeks and try to get this merged for 10. | 
This PR adds support for querying on
hstoretype columns which can map to eitherDictionary<string, string>orImmutableDictionary<string, string>in C# and for querying any otherDictionary<,>orImmutableDictionary<,>forjsonandjsonbtypes.See npgsql/doc#369 for full documentation.
Fixes #212