Skip to content

New EF.Functions.Collate - #20603

Merged
roji merged 1 commit into
masterfrom
CollationQuery
Apr 23, 2020
Merged

roji merged 1 commit into
masterfrom
CollationQuery

Conversation

@roji

@roji roji commented Apr 11, 2020

Copy link
Copy Markdown
Member

Closes #8813

@roji
roji requested review from maumar and smitpatel 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

roji commented Apr 14, 2020

Copy link
Copy Markdown
Member Author

@smitpatel addressed review comment.

@roji

roji commented Apr 14, 2020

Copy link
Copy Markdown
Member Author

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

@smitpatel

Copy link
Copy Markdown
Contributor

@roji be like

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

return collateExpresion.Update(

Copy link
Copy Markdown
Contributor

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

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

roji commented Apr 14, 2020

Copy link
Copy Markdown
Member Author

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

Today @roji be more like:

image

@ajcvickers

Copy link
Copy Markdown
Contributor

@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

roji commented Apr 14, 2020

Copy link
Copy Markdown
Member Author

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

@roji

roji commented Apr 15, 2020

Copy link
Copy Markdown
Member Author

@smitpatel new version up.

@roji

roji commented Apr 15, 2020 •

Copy link
Copy Markdown
Member Author

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


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

Copy link
Copy Markdown
Contributor

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

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

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

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

roji commented Apr 23, 2020

Copy link
Copy Markdown
Member Author

@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
Copy Markdown
Contributor

@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