Repository navigation
Better cast/convert support for Cosmos - #35000
Conversation
There was a problem hiding this comment.
Copilot reviewed 5 out of 12 changed files in this pull request and generated no suggestions.
Files not reviewed (7)
- src/EFCore.Cosmos/Query/Internal/CosmosQuerySqlGenerator.cs: Evaluated as low risk
- src/EFCore.Cosmos/Query/Internal/Expressions/SqlUnaryExpression.cs: Evaluated as low risk
- src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs: Evaluated as low risk
- src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs: Evaluated as low risk
- test/EFCore.Cosmos.FunctionalTests/Query/PrimitiveCollectionsQueryCosmosTest.cs: Evaluated as low risk
- test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs: Evaluated as low risk
- src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs: Evaluated as low risk
|
@roji Was just working on this to update and resync everything especially because of all your reorganization of the tests and have a question. In the original NorthwindFunctions you have the test Can be summarized by this test (based on In the current |
OK, understood. Yeah, part of the translation test refactoring was also about making it very clear the intent behind each test, and trying to test exactly one thing. If there's an issue specifically with the downcast, then that's something we should verify in a separate test that focuses on downcasting (and is named appropriately). There's a Translations/Operators folder where we have test suites for operator translation - a test inside MiscellaneousOperatorTranslationsTestBase probably makes sense here (or we could even start a new CastOperatorTransationsTestBase if we think we'll add more coverage specifically around casting...). How does that sound? |
|
CastOperatorTranslation would probably work if you had lots of casts in various ways that you wanted to test. To me it might make more sense to do it in the same place as the original i.e. you have one test normal with direct value and the next test with the cast. Then you end up dealing with the same tables and data and if you modify something for one, you have all the similar tests close by to modify as well |
The thing is that one test here (the missing one) tests only the downcast, without it mattering at all which function (or even type) is involved, whereas the other one tests translation for a specific function on a specific type (MathF.Floor), no? Unless you think there is (or could be) a specific issue with the translation of MathF.Floor around the cast? Also, note that all the translation tests already use the same tables and data. The idea is to try to be in a place where data can be added to accomodate new tests, without that breaking existing tests (it'll likely not be 100% successful, but that's the idea). |
Pretty sure its just the cast itself and doesn't matter what function its used in. But this is more of a Cosmos specific issue. Relational already has this sorted out since practically v1 Also, there are a bunch of other tests that seem to test this intrinsically and pass with this fix e.g. in NorthwindFunctions So a specific test might not be needed |
|
@roji Can see how this goes now. Should be updated and back in sync |
|
@roji Any update on this? |
|
Hey @ChrisJollyAU, this has been high up on my list of stuff to review, but unfortunately there simply has been too much higher-priority stuff going on. I'll do my best to get this merged for 10, but there's unfortunately a chance it'll slip into 11. Again, sorry about this - I know you invested your time and it must be frustrating to not have the PR reviewed and merged. |
|
@ChrisJollyAU apologies, but I didn't end up finding the time for this for 10 (and the window is just about to close). I'll try to tackle this early in the 11 release. |
249ae47 to
6b86657
Compare
|
@AndriySvyryd Do I need to resync with the main branch so that we can resolve any merge conflicts |
|
@ChrisJollyAU Yes, please |
Add an override for Two_parameters_with_same_case_insensitive_name_get_uniquified in NorthwindWhereQueryCosmosTest.cs. The test verifies that SQL parameter names are correctly uniquified when they differ only by case.
|
I have two failing tests I'm not sure on what to do with
This one was passing, but by the looks of it only because it couldnt translate so fell back to just query the items and then do the calculations client side. Now that we have this PR, the sql does get translated and executed properly. But it only returns 8 out of the 9 expected results. The difference is one of the results needs to be null. The problem is when It's a different issue to the cast/convert that getting the translation right manage to surface.
This one was expected to fail but it now fails with a different error message: System.InvalidOperationException : The expression '@parameters[0]' in the SQL tree does not have a type mapping assigned. The thing is we have an array of To me this is still an expected failure and should just adjust the test to expect that new message @AndriySvyryd Thoughts? |
Yes, change the expected query to filter out |
AndriySvyryd
left a comment
There was a problem hiding this comment.
Thanks for your contribution!
Improve the support and handling of the cast/converts in Cosmos
Originally started for #34963 but after #34982 was created extended that work to more cases
VisitUnarynow leaves theConvertoperation in place instead of stripping it. This has 2 potential benefits:intvalue will have a Convert to type ofObject- aka we know we need a convert but we don't yet know what to convert it to. The type mapping handling of the binary expression will work it out and apply to all sidesIn the QuerySqlGenerator, we effectively no-op most casts except for if we have a convert to string.
This does light up a number of math function tests that were failing - all of them due to #17246 (client evaluation exception)
Also some tests for #20677 are now passing (not all of them related to that issue)
The Cosmos tests for #34729 are now passing as well
This fixes #34982