Skip to content

Infer type mapping suitable for concatenating two results#32510

Merged
ajcvickers merged 3 commits intomainfrom
231203_InfernalInferences
Dec 4, 2023
Merged

Infer type mapping suitable for concatenating two results#32510
ajcvickers merged 3 commits intomainfrom
231203_InfernalInferences

Conversation

@ajcvickers
Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread test/EFCore.SqlServer.FunctionalTests/Query/CompositeKeysQuerySqlServerTest.cs Outdated

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Contains_over_concatenated_column_and_constant(bool async)
Copy link
Copy Markdown
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).

Comment thread src/EFCore.Relational/Query/SqlExpressionFactory.cs Outdated
public class Scrathcy
{
[ConditionalFact]
public async Task Main()
Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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.

Comment thread test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs Outdated
@ajcvickers
Copy link
Copy Markdown
Contributor 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
@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