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

Translate List<T> operations to PG array #1185

Merged
merged 1 commit into from
Jan 10, 2020
Merged

Translate List<T> operations to PG array #1185

merged 1 commit into from
Jan 10, 2020

Conversation

roji
Copy link
Member

@roji roji commented Jan 6, 2020

  • Match our List translation capabilities to CLR array.
  • Improve some mapping and inference aspects.

Closes #395

src/EFCore.PG/Extensions/TypeExtensions.cs Outdated Show resolved Hide resolved
{
internal static class TypeExtensions
{
internal static bool IsGenericList(this Type type)
Copy link
Contributor

Choose a reason for hiding this comment

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

The name could be simplified:

Suggested change
internal static bool IsGenericList(this Type type)
internal static bool IsList(this Type type)

Copy link
Member Author

Choose a reason for hiding this comment

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

This was just to make it explicit that non-generic lists aren't covered.

src/EFCore.PG/Query/Internal/NpgsqlSqlExpressionFactory.cs Outdated Show resolved Hide resolved
/// Note that mapping PostgreSQL arrays to .NET List{T} is also supported via <see cref="NpgsqlArrayListTypeMapping"/>.
/// See: https://www.postgresql.org/docs/current/static/arrays.html
/// </remarks>
public class NpgsqlArrayArrayTypeMapping : NpgsqlArrayTypeMapping
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's rename this to NpgsqlArrayTypeMapping while NpgsqlArrayTypeMapping to NpgsqlCollectionTypeMapping. Otherwise, NpgsqlArrayArrayTypeMapping sounds like jagged array mapping.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is that this isn't about collections (which have a specific meaning in .NET)... The idea here was to include both the name of the .NET type and the PG type, since type mappings link the two. I wouldn't be too concerned about naming here - this is pretty internal types that users shouldn't ever encounter...

}
}

class SingleDimComparerWithEquals<TElem> : ValueComparer<TElem[]>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not to have only one comparer which internally will call EqualityComparer<TElem>.Defeault.Equals? The JIT can optimize some cases and inline method bodies (see dotnet/coreclr#14125).

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree there's probably some simplification to be done here, but let's do this in another PR, OK? This one is mostly about list translations and I don't want to go too far with other stuff etc...

@roji roji force-pushed the ListTranslations branch 2 times, most recently from 966929b to 3aa6b64 Compare January 10, 2020 13:29
@roji
Copy link
Member Author

roji commented Jan 10, 2020

@YohDeadfall can you please give this another look? #1189 depends on this.

// TODO: Handle List<>
if (methodCall.Arguments.Count > 0 && methodCall.Arguments[0].Type.IsArray)
if (methodCall.Arguments.Count > 0 && (
methodCall.Arguments[0].Type.IsArray || methodCall.Arguments[0].Type.IsGenericList()))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Having all on a single line would be better, but it's up to you. Is it perf sensitive?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess I'm starting to make more of an effort to respect 120 chars width :) Must be more bad EF influence...! But in this case it seems to express the logical structure better (or and and)...

Is it perf sensitive?

You mean because of the double methodCall.Arguments[0]? Definitely not perf sensitive to that degree :) This is part of "compilation", which happens once per LINQ query structure and the results are then cached.

* Match our List<T> translation capabilities to CLR array.
* Improve some mapping and inference aspects.

Closes #395
@roji roji force-pushed the ListTranslations branch from 3aa6b64 to 6759e00 Compare January 10, 2020 16:50
@roji roji merged commit e013f0e into dev Jan 10, 2020
@delete-merged-branch delete-merged-branch bot deleted the ListTranslations branch January 10, 2020 16:58
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.

Operation translation for List<T>
2 participants