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

#10582 - Translate SequenceEqual for Sqlite and SqlServer byte arrays #19594

Merged
merged 11 commits into from
Jan 28, 2020

Conversation

svengeance
Copy link
Contributor

This fixes #10582

Hopefully straightforward and simple implementation. I don't believe anything other than a direct call to _sqlExpressionFactory.Equal is necessary since the method definition for SequenceEqual with 2 args demands both be the same type.

Would it be an improvement to place this in the RelationalSqlTranslatingExpressionVisitor.VisitBinary method? Both implementations are the same for SqlServer/Sqlite, but I didn't want to make assumptions about any future inheritors.

Cheers!

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.

@svengeance looks great, thanks! Aside from rebasing there's one small rename, but otherwise looks ready to merge.

@@ -18,6 +18,7 @@ internal static class EnumerableMethods
public static MethodInfo AnyWithoutPredicate { get; }
public static MethodInfo AnyWithPredicate { get; }
public static MethodInfo Contains { get; }
public static MethodInfo SequenceEquals { get; }
Copy link
Member

Choose a reason for hiding this comment

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

Please rename this to SequenceEqual (no s)

@roji
Copy link
Member

roji commented Jan 23, 2020

Regarding where to put this, I think it would make sense more as a separate RelationalByteArrayMethodCallTranslator, much like StringMethodTranslator or EnumHasFlagTranslator. These contain presumably "universal" relational translations, and we generally prefer implementing as method or member translator when possible, rather than modifying RelationalSqlTranslatingExpressionVisitor. @bricelam, does that sound like a good approach?

@svengeance
Copy link
Contributor Author

svengeance commented Jan 23, 2020

Makes sense to me - otherwise RelationalSqlTranslatingExpressionVisitor runs the risk of being bloated. I'll nip the name and rebase tonight for you.

Would you like to move the implementation to a relational method translator (as opposed to one each in sql/server method translator), or save that for another day?

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.

This looks good to me, but as I wrote before we should consider moving this up to relational instead of reimplementing for each provider. Comparing blobs/byte arrays with the equality operators seems to be a pretty universal feature (at least it works on SQL Server, Sqlite, PG, MySQL), so this seems to be similar to translators like StringMethodTranslator, LikeTranslator which are RelationalMethodCallTranslatorProvider.

Any objections @ajcvickers @AndriySvyryd @bricelam @maumar?


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

Choose a reason for hiding this comment

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

Rename to ByteArraySequenceEqualTranslator, to align with the other single-purpose translators. Other than that looks great.

@roji
Copy link
Member

roji commented Jan 26, 2020

Also needs a rebase.

@bricelam bricelam removed their assignment Jan 27, 2020
@svengeance
Copy link
Contributor Author

@roji should be good now. Let me know if there's anything else I can do to tidy up!

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.

Thanks for your contribution!

@roji roji merged commit b4ae282 into dotnet:master Jan 28, 2020
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.

Translate SequenceEquals for byte arrays
3 participants