Skip to content
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

Infer type mapping suitable for concatenating two results #32510

Merged
merged 3 commits into from
Dec 4, 2023

Conversation

ajcvickers
Copy link
Member

Fixes #32325

The issue here is that the concatenation of strings requires a max length on the resulting SQL type that can handle the max length of both sides combined. We should make the type mapping be able to participate in this directly, as indicated in #32333, but this is a smaller fix just to address the regression.

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.

Looks good as a targeted fix specifically for #32325 (see comments).

The question in my mind is whether we should also try to handle other (binary?) operators, which still have the simple left-mapping-wins behavior. I'm not sure there's something relevant for string, but stuff like math on decimals with varying precision/scale...

Of course, we can wait and see.


[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Contains_over_concatenated_column_and_constant(bool async)
Copy link
Member

Choose a reason for hiding this comment

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

For completeness, would be good to also have tests for column+parameter, and also parameter+constant (these are evaluated as a single parameter in regular queries, but the tree is preserved for compiled queries).

src/EFCore.Relational/Query/SqlExpressionFactory.cs Outdated Show resolved Hide resolved
public class Scrathcy
{
[ConditionalFact]
public async Task Main()
Copy link
Member

Choose a reason for hiding this comment

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

Seems a bit much, does this add coverage that we don't have in the other tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will remove this. (This is just the customer's repo as a test. I didn't mean to include it in the PR; I use it while working to double check that the customer issue is still fixed after having written the other tests and implemented the fix.)

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see, I've got a separate console program (with ProjectReferences into the EF repo) for doing that stuff.

@ajcvickers
Copy link
Member Author

The question in my mind is whether we should also try to handle other (binary?) operators,

I will look into this for 9+.

@ajcvickers ajcvickers merged commit 1048f6a into main Dec 4, 2023
7 checks passed
@ajcvickers ajcvickers deleted the 231203_InfernalInferences branch December 4, 2023 15:30
ajcvickers added a commit that referenced this pull request Dec 5, 2023
* Work on type mapping inference for string concatenation

Fixes #32325, see also #32333

* Tweaks, update baselines add more tests and cleanup

* Update baselines, add more tests, some cleanup.

---------

Co-authored-by: Shay Rojansky <roji@roji.org>
wtgodbe pushed a commit that referenced this pull request Jan 3, 2024
…ts (#32510) (#32520)

* Infer type mapping suitable for concatenating two results (#32510)

* Work on type mapping inference for string concatenation

Fixes #32325, see also #32333

* Tweaks, update baselines add more tests and cleanup

* Update baselines, add more tests, some cleanup.

---------

Co-authored-by: Shay Rojansky <roji@roji.org>

* Qwerk

* Fix quirk.

---------

Co-authored-by: Shay Rojansky <roji@roji.org>
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.

LINQ "Contains" generates SQL with wrong char length
2 participants