Skip to content

Commit

Permalink
Small primitive collection cleanup
Browse files Browse the repository at this point in the history
Apply Redshift opt-out in translation phase instead of in preprocessing,
like SQL Server.
  • Loading branch information
roji committed Apr 4, 2024
1 parent ac91e9a commit fe71701
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public static IServiceCollection AddEntityFrameworkNpgsql(this IServiceCollectio
.TryAdd<IEvaluatableExpressionFilter, NpgsqlEvaluatableExpressionFilter>()
.TryAdd<IQuerySqlGeneratorFactory, NpgsqlQuerySqlGeneratorFactory>()
.TryAdd<IRelationalSqlTranslatingExpressionVisitorFactory, NpgsqlSqlTranslatingExpressionVisitorFactory>()
.TryAdd<IQueryTranslationPreprocessorFactory, NpgsqlQueryTranslationPreprocessorFactory>()
.TryAdd<IQueryTranslationPostprocessorFactory, NpgsqlQueryTranslationPostprocessorFactory>()
.TryAdd<IRelationalParameterBasedSqlProcessorFactory, NpgsqlParameterBasedSqlProcessorFactory>()
.TryAdd<ISqlExpressionFactory, NpgsqlSqlExpressionFactory>()
Expand Down
43 changes: 0 additions & 43 deletions src/EFCore.PG/Query/Internal/NpgsqlQueryRootProcessor.cs

This file was deleted.

40 changes: 0 additions & 40 deletions src/EFCore.PG/Query/Internal/NpgsqlQueryTranslationPreprocessor.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;
using Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions;
using Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;
Expand All @@ -18,9 +19,9 @@ public class NpgsqlQueryableMethodTranslatingExpressionVisitor : RelationalQuery
private readonly RelationalQueryCompilationContext _queryCompilationContext;
private readonly NpgsqlTypeMappingSource _typeMappingSource;
private readonly NpgsqlSqlExpressionFactory _sqlExpressionFactory;
private readonly bool _isRedshift;
private RelationalTypeMapping? _ordinalityTypeMapping;


#region MethodInfos

private static readonly MethodInfo Like2MethodInfo =
Expand All @@ -46,12 +47,14 @@ private static readonly MethodInfo ILike2MethodInfo
public NpgsqlQueryableMethodTranslatingExpressionVisitor(
QueryableMethodTranslatingExpressionVisitorDependencies dependencies,
RelationalQueryableMethodTranslatingExpressionVisitorDependencies relationalDependencies,
RelationalQueryCompilationContext queryCompilationContext)
RelationalQueryCompilationContext queryCompilationContext,
INpgsqlSingletonOptions npgsqlSingletonOptions)
: base(dependencies, relationalDependencies, queryCompilationContext)
{
_queryCompilationContext = queryCompilationContext;
_typeMappingSource = (NpgsqlTypeMappingSource)relationalDependencies.TypeMappingSource;
_sqlExpressionFactory = (NpgsqlSqlExpressionFactory)relationalDependencies.SqlExpressionFactory;
_isRedshift = npgsqlSingletonOptions.UseRedshift;
}

/// <summary>
Expand All @@ -66,6 +69,7 @@ protected NpgsqlQueryableMethodTranslatingExpressionVisitor(NpgsqlQueryableMetho
_queryCompilationContext = parentVisitor._queryCompilationContext;
_typeMappingSource = parentVisitor._typeMappingSource;
_sqlExpressionFactory = parentVisitor._sqlExpressionFactory;
_isRedshift = parentVisitor._isRedshift;
}

/// <summary>
Expand All @@ -83,11 +87,18 @@ protected override QueryableMethodTranslatingExpressionVisitor CreateSubqueryVis
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override ShapedQueryExpression TranslatePrimitiveCollection(
protected override ShapedQueryExpression? TranslatePrimitiveCollection(
SqlExpression sqlExpression,
IProperty? property,
string tableAlias)
{
if (_isRedshift)
{
AddTranslationErrorDetails("Redshift does not support unnest, which is required for most forms of querying of JSON arrays.");

return null;
}

var elementClrType = sqlExpression.Type.GetSequenceType();
var elementTypeMapping = (RelationalTypeMapping?)sqlExpression.TypeMapping?.ElementTypeMapping;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal;

/// <summary>
Expand All @@ -8,6 +10,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal;
/// </summary>
public class NpgsqlQueryableMethodTranslatingExpressionVisitorFactory : IQueryableMethodTranslatingExpressionVisitorFactory
{
private readonly INpgsqlSingletonOptions _npgsqlSingletonOptions;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand All @@ -16,10 +20,12 @@ public class NpgsqlQueryableMethodTranslatingExpressionVisitorFactory : IQueryab
/// </summary>
public NpgsqlQueryableMethodTranslatingExpressionVisitorFactory(
QueryableMethodTranslatingExpressionVisitorDependencies dependencies,
RelationalQueryableMethodTranslatingExpressionVisitorDependencies relationalDependencies)
RelationalQueryableMethodTranslatingExpressionVisitorDependencies relationalDependencies,
INpgsqlSingletonOptions npgsqlSingletonOptions)
{
Dependencies = dependencies;
RelationalDependencies = relationalDependencies;
_npgsqlSingletonOptions = npgsqlSingletonOptions;
}

/// <summary>
Expand Down Expand Up @@ -48,5 +54,6 @@ public virtual QueryableMethodTranslatingExpressionVisitor Create(QueryCompilati
=> new NpgsqlQueryableMethodTranslatingExpressionVisitor(
Dependencies,
RelationalDependencies,
(RelationalQueryCompilationContext)queryCompilationContext);
(RelationalQueryCompilationContext)queryCompilationContext,
_npgsqlSingletonOptions);
}

0 comments on commit fe71701

Please sign in to comment.