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

New EF.Functions.Collate #20603

Merged
merged 1 commit into from
Apr 23, 2020
Merged

New EF.Functions.Collate #20603

merged 1 commit into from
Apr 23, 2020

Conversation

roji
Copy link
Member

@roji roji commented Apr 11, 2020

Closes #8813

@roji roji requested review from smitpatel and maumar April 11, 2020 17:40
@roji roji force-pushed the CollationQuery branch 2 times, most recently from 9de5bd5 to ea7adcf Compare April 11, 2020 19:13
@roji
Copy link
Member Author

roji commented Apr 14, 2020

@smitpatel addressed review comment.

@roji
Copy link
Member Author

roji commented Apr 14, 2020

Sorry about the previous nonsense, hopefully I got it right this time.

@smitpatel
Copy link
Member

@roji be like

{
Check.NotNull(collateExpresion, nameof(collateExpresion));

return collateExpresion.Update(
Copy link
Member

Choose a reason for hiding this comment

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

@maumar to verify

Copy link
Member Author

Choose a reason for hiding this comment

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

@maumar @smitpatel are we waiting for anything in particular here? Would be good to merge this for preview4.

Copy link
Member

Choose a reason for hiding this comment

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

Waiting for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is correct - signed off

@roji
Copy link
Member Author

roji commented Apr 14, 2020

Made abstract, let me know if you have any more comments.

Today @roji be more like:

image

@ajcvickers
Copy link
Member

@roji @smitpatel I haven't read through the comments here but I noticed there are a lot! Is there anything in particular I should take a look at or needs resolving?

@roji
Copy link
Member Author

roji commented Apr 14, 2020

@ajcvickers I don't think so, from my side everything is fine - just waiting for approval.

@roji
Copy link
Member Author

roji commented Apr 15, 2020

@smitpatel new version up.

@roji
Copy link
Member Author

roji commented Apr 15, 2020

Rebased and made collation abstract in migrations tests too (#20646)


namespace Microsoft.EntityFrameworkCore.Query.Internal
{
public class CollateTranslator : IMethodCallTranslator
Copy link
Member

Choose a reason for hiding this comment

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

Can you add internal docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

These seem to be missing from all translators, will submit a separate PR for this.

Copy link
Member

Choose a reason for hiding this comment

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

Ignore. I already did this as part of query docs work. I am trying to make sure we have docs for all new stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK thanks!

async,
ss => ss.Set<Customer>(),
ss => ss.Set<Customer>(),
c => EF.Functions.Collate(c.ContactName, CaseSensitiveCollation) == "maria anders",
Copy link
Member

Choose a reason for hiding this comment

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

What is the effect of using EF.Functions.Collate on a string column and projecting it out?

Copy link
Member Author

Choose a reason for hiding this comment

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

Assuming I understand your question: the collation aspect bubbles up across projections - does this look good?

SQL Server:

DROP TABLE data;
CREATE TABLE data (
    id INT IDENTITY,
    cs VARCHAR(MAX) COLLATE Latin1_General_CS_AS
);
INSERT INTO data (cs) VALUES ('foo');

SELECT * FROM data WHERE cs = 'FOO'; -- no results because column is case-sensitive

SELECT * FROM (
    SELECT cs COLLATE Latin1_General_CI_AS AS cs
    FROM data
) AS t
WHERE t.cs = 'FOO'; -- returns row because cs projects out with the explicitly-applied collation

PostgreSQL:

CREATE COLLATION cs_collation (LC_COLLATE = 'en-u-ks-primary',
    LC_CTYPE = 'en-u-ks-primary',
    PROVIDER = icu,
    DETERMINISTIC = False
);

DROP TABLE IF EXISTS data;
CREATE TABLE data (
    id INT GENERATED ALWAYS AS IDENTITY,
    cs TEXT COLLATE "POSIX"
);
INSERT INTO data (cs) VALUES ('foo');

SELECT * FROM data WHERE cs = 'FOO'; -- no results because column is case-sensitive

SELECT * FROM (
    SELECT cs COLLATE cs_collation AS no_longer_cs
    FROM data
) AS t
WHERE t.no_longer_cs = 'FOO'; -- returns row because cs projects out with the explicitly-applied collation

Copy link
Member

Choose a reason for hiding this comment

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

Nooo. I wanted a test where you are using EF.Collate in projection and if it generates any difference in reading results. (which it should not.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ohh you mean top-most projection (i.e. on a column that will be read by the client)? If so I'll check that, no problem (did you mean you want actual test code for this?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean the following (which passes on both providers):

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Collate_column_projection(bool async)
    => AssertQuery(
        async,
        ss => ss.Set<Customer>().Select(c => EF.Functions.Collate(c.ContactName, CaseInsensitiveCollation)),
        ss => ss.Set<Customer>().Select(c => c.ContactName));

If so do you want this in the test suite?

@roji roji merged commit d1dee85 into master Apr 23, 2020
@roji roji deleted the CollationQuery branch April 23, 2020 16:54
@roji
Copy link
Member Author

roji commented Apr 23, 2020

@smitpatel @ajcvickers what's your opinion on merging this into the preview4 branch? It would be good to deliver this with the other collation functionality (column/database migration support)

@ajcvickers
Copy link
Member

@roji I think it's probably okay just to wait.

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.

Support per-operation collation using EF.Functions.Collate() or equivalent
5 participants