-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Better cast/convert support for Cosmos #35000
base: main
Are you sure you want to change the base?
Conversation
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.
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 |
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
VisitUnary
now leaves theConvert
operation in place instead of stripping it. This has 2 potential benefits:int
value 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