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

Rename Postgres*Expression to Pg*Expression #2912

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public NpgsqlGeometryMethodTranslator(
arguments[1].TypeMapping),

nameof(NpgsqlNetTopologySuiteDbFunctionsExtensions.DistanceKnn) => _sqlExpressionFactory.MakePostgresBinary(
PostgresExpressionType.Distance,
PgExpressionType.Distance,
arguments[1],
arguments[2]),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public NpgsqlNodaTimeMethodCallTranslator(

if (method == Instant_Distance)
{
return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]);
return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]);
}

return null;
Expand Down Expand Up @@ -232,7 +232,7 @@ public NpgsqlNodaTimeMethodCallTranslator(

if (method == ZonedDateTime_Distance)
{
return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]);
return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]);
}

return null;
Expand All @@ -250,7 +250,7 @@ public NpgsqlNodaTimeMethodCallTranslator(

if (method == LocalDateTime_Distance)
{
return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]);
return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]);
}

return null;
Expand All @@ -263,7 +263,7 @@ public NpgsqlNodaTimeMethodCallTranslator(
{
if (method == LocalDate_Distance)
{
return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]);
return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]);
}

return null;
Expand Down Expand Up @@ -318,8 +318,8 @@ public NpgsqlNodaTimeMethodCallTranslator(

return null;

static PostgresFunctionExpression IntervalPart(string datePart, SqlExpression parameter)
=> PostgresFunctionExpression.CreateWithNamedArguments(
static PgFunctionExpression IntervalPart(string datePart, SqlExpression parameter)
=> PgFunctionExpression.CreateWithNamedArguments(
"make_interval",
new[] { parameter },
new[] { datePart },
Expand All @@ -329,7 +329,7 @@ static PostgresFunctionExpression IntervalPart(string datePart, SqlExpression pa
typeof(Period),
typeMapping: null);

PostgresFunctionExpression IntervalPartOverBigInt(string datePart, SqlExpression parameter)
PgFunctionExpression IntervalPartOverBigInt(string datePart, SqlExpression parameter)
{
parameter = _sqlExpressionFactory.ApplyDefaultTypeMapping(parameter);

Expand Down Expand Up @@ -376,12 +376,12 @@ PostgresFunctionExpression IntervalPartOverBigInt(string datePart, SqlExpression

if (method == DateInterval_Intersection)
{
return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeIntersect, instance!, arguments[0]);
return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeIntersect, instance!, arguments[0]);
}

if (method == DateInterval_Union)
{
return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeUnion, instance!, arguments[0]);
return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeUnion, instance!, arguments[0]);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public NpgsqlByteArrayMethodTranslator(ISqlExpressionFactory sqlExpressionFactor
typeMapping);

return _sqlExpressionFactory.GreaterThan(
PostgresFunctionExpression.CreateWithArgumentSeparators(
PgFunctionExpression.CreateWithArgumentSeparators(
"position",
new[] { value, source },
new[] { "IN" }, // POSITION(x IN y)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public NpgsqlDateTimeMethodTranslator(

if (method == DateTime_Distance)
{
return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]);
return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]);
}
}
else
Expand Down Expand Up @@ -249,7 +249,7 @@ public NpgsqlDateTimeMethodTranslator(

if (method == DateOnly_Distance)
{
return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]);
return _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.Distance, arguments[1], arguments[2]);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public NpgsqlFullTextSearchMethodTranslator(
// Operators

nameof(NpgsqlFullTextSearchLinqExtensions.And)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.TextSearchAnd, arguments[0], arguments[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.TextSearchAnd, arguments[0], arguments[1]),
nameof(NpgsqlFullTextSearchLinqExtensions.Or)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.TextSearchOr, arguments[0], arguments[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.TextSearchOr, arguments[0], arguments[1]),

nameof(NpgsqlFullTextSearchLinqExtensions.ToNegative)
=> new SqlUnaryExpression(ExpressionType.Not, arguments[0], arguments[0].Type,
Expand All @@ -162,7 +162,7 @@ public NpgsqlFullTextSearchMethodTranslator(

nameof(NpgsqlFullTextSearchLinqExtensions.Matches)
=> _sqlExpressionFactory.MakePostgresBinary(
PostgresExpressionType.TextSearchMatch,
PgExpressionType.TextSearchMatch,
arguments[0],
arguments[1].Type == typeof(string)
? _sqlExpressionFactory.Function(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public NpgsqlJsonDbFunctionsTranslator(
// If a function is invoked over a JSON traversal expression, that expression may come with
// returnText: true (i.e. operator ->> and not ->). Since the functions below require a json object and
// not text, we transform it.
.Select(a => a is PostgresJsonTraversalExpression traversal ? WithReturnsText(traversal, false) : a)
.Select(a => a is PgJsonTraversalExpression traversal ? WithReturnsText(traversal, false) : a)
.ToArray();

if (!args.Any(a => a.TypeMapping is NpgsqlJsonTypeMapping || a is PostgresJsonTraversalExpression))
if (!args.Any(a => a.TypeMapping is NpgsqlJsonTypeMapping || a is PgJsonTraversalExpression))
{
throw new InvalidOperationException("The EF JSON methods require a JSON parameter and none was found.");
}
Expand Down Expand Up @@ -91,11 +91,11 @@ public NpgsqlJsonDbFunctionsTranslator(
nameof(NpgsqlJsonDbFunctionsExtensions.JsonContained)
=> _sqlExpressionFactory.ContainedBy(Jsonb(args[0]), Jsonb(args[1])),
nameof(NpgsqlJsonDbFunctionsExtensions.JsonExists)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.JsonExists, Jsonb(args[0]), args[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.JsonExists, Jsonb(args[0]), args[1]),
nameof(NpgsqlJsonDbFunctionsExtensions.JsonExistAny)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.JsonExistsAny, Jsonb(args[0]), args[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.JsonExistsAny, Jsonb(args[0]), args[1]),
nameof(NpgsqlJsonDbFunctionsExtensions.JsonExistAll)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.JsonExistsAll, Jsonb(args[0]), args[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.JsonExistsAll, Jsonb(args[0]), args[1]),

_ => null
};
Expand All @@ -117,11 +117,11 @@ static SqlExpression RemoveConvert(SqlExpression e)
return e;
}

PostgresJsonTraversalExpression WithReturnsText(PostgresJsonTraversalExpression traversal, bool returnsText)
PgJsonTraversalExpression WithReturnsText(PgJsonTraversalExpression traversal, bool returnsText)
=> traversal.ReturnsText == returnsText
? traversal
: returnsText
? new PostgresJsonTraversalExpression(traversal.Expression, traversal.Path, true, typeof(string), _stringTypeMapping)
: new PostgresJsonTraversalExpression(traversal.Expression, traversal.Path, false, traversal.Type, traversal.Expression.TypeMapping);
? new PgJsonTraversalExpression(traversal.Expression, traversal.Path, true, typeof(string), _stringTypeMapping)
: new PgJsonTraversalExpression(traversal.Expression, traversal.Path, false, traversal.Type, traversal.Expression.TypeMapping);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ public NpgsqlJsonDomTranslator(

if (method == GetProperty || method == ArrayIndexer)
{
return instance is PostgresJsonTraversalExpression prevPathTraversal
return instance is PgJsonTraversalExpression prevPathTraversal
? prevPathTraversal.Append(_sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]))
: null;
}

if (GetMethods.Contains(method.Name) &&
arguments.Count == 0 &&
instance is PostgresJsonTraversalExpression traversal)
instance is PgJsonTraversalExpression traversal)
{
var traversalToText = new PostgresJsonTraversalExpression(
var traversalToText = new PgJsonTraversalExpression(
traversal.Expression,
traversal.Path,
returnsText: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public NpgsqlJsonPocoTranslator(
Type returnType,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
if (instance?.TypeMapping is not NpgsqlJsonTypeMapping && instance is not PostgresJsonTraversalExpression)
if (instance?.TypeMapping is not NpgsqlJsonTypeMapping && instance is not PgJsonTraversalExpression)
{
return null;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public NpgsqlJsonPocoTranslator(
_stringTypeMapping),
returnType),

PostgresJsonTraversalExpression prevPathTraversal
PgJsonTraversalExpression prevPathTraversal
=> ConvertFromText(
prevPathTraversal.Append(_sqlExpressionFactory.ApplyDefaultTypeMapping(member)),
returnType),
Expand All @@ -137,11 +137,11 @@ PostgresJsonTraversalExpression prevPathTraversal
argumentsPropagateNullability: TrueArrays[2],
typeof(int));

case PostgresJsonTraversalExpression traversal:
case PgJsonTraversalExpression traversal:
// The traversal expression has ReturnsText=true (e.g. ->> not ->), so we recreate it to return
// the JSON object instead.
var lastPathComponent = traversal.Path.Last();
var newTraversal = new PostgresJsonTraversalExpression(
var newTraversal = new PgJsonTraversalExpression(
traversal.Expression, traversal.Path,
returnsText: false,
lastPathComponent.Type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,32 @@ public NpgsqlLTreeTranslator(
return method.Name switch
{
nameof(LTree.IsAncestorOf)
=> new PostgresBinaryExpression(
PostgresExpressionType.Contains,
=> new PgBinaryExpression(
PgExpressionType.Contains,
ApplyTypeMappingOrConvert(instance!, _ltreeTypeMapping),
ApplyTypeMappingOrConvert(arguments[0], _ltreeTypeMapping),
typeof(bool),
_boolTypeMapping),

nameof(LTree.IsDescendantOf)
=> new PostgresBinaryExpression(
PostgresExpressionType.ContainedBy,
=> new PgBinaryExpression(
PgExpressionType.ContainedBy,
ApplyTypeMappingOrConvert(instance!, _ltreeTypeMapping),
ApplyTypeMappingOrConvert(arguments[0], _ltreeTypeMapping),
typeof(bool),
_boolTypeMapping),

nameof(LTree.MatchesLQuery)
=> new PostgresBinaryExpression(
PostgresExpressionType.LTreeMatches,
=> new PgBinaryExpression(
PgExpressionType.LTreeMatches,
ApplyTypeMappingOrConvert(instance!, _ltreeTypeMapping),
ApplyTypeMappingOrConvert(arguments[0], _lqueryTypeMapping),
typeof(bool),
_boolTypeMapping),

nameof(LTree.MatchesLTxtQuery)
=> new PostgresBinaryExpression(
PostgresExpressionType.LTreeMatches,
=> new PgBinaryExpression(
PgExpressionType.LTreeMatches,
ApplyTypeMappingOrConvert(instance!, _ltreeTypeMapping),
ApplyTypeMappingOrConvert(arguments[0], _ltxtqueryTypeMapping),
typeof(bool),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public NpgsqlMiscAggregateMethodTranslator(
// These methods accept two enumerable (column) arguments; this is represented in LINQ as a projection from the grouping
// to a tuple of the two columns. Since we generally translate tuples to PostgresRowValueExpression, we take it apart
// here.
if (source.Selector is not PostgresRowValueExpression rowValueExpression)
if (source.Selector is not PgRowValueExpression rowValueExpression)
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ public NpgsqlNetworkTranslator(
=> _sqlExpressionFactory.ContainedBy(arguments[1], arguments[2]),
nameof(NpgsqlNetworkDbFunctionsExtensions.ContainedByOrEqual)
=> _sqlExpressionFactory.MakePostgresBinary(
PostgresExpressionType.NetworkContainedByOrEqual, arguments[1], arguments[2]),
PgExpressionType.NetworkContainedByOrEqual, arguments[1], arguments[2]),
nameof(NpgsqlNetworkDbFunctionsExtensions.Contains)
=> _sqlExpressionFactory.Contains(arguments[1], arguments[2]),
nameof(NpgsqlNetworkDbFunctionsExtensions.ContainsOrEqual)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.NetworkContainsOrEqual, arguments[1], arguments[2]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.NetworkContainsOrEqual, arguments[1], arguments[2]),
nameof(NpgsqlNetworkDbFunctionsExtensions.ContainsOrContainedBy)
=> _sqlExpressionFactory.MakePostgresBinary(
PostgresExpressionType.NetworkContainsOrContainedBy, arguments[1], arguments[2]),
PgExpressionType.NetworkContainsOrContainedBy, arguments[1], arguments[2]),

nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseNot)
=> new SqlUnaryExpression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ public NpgsqlRangeTranslator(
nameof(NpgsqlRangeDbFunctionsExtensions.Overlaps)
=> _sqlExpressionFactory.Overlaps(arguments[0], arguments[1]),
nameof(NpgsqlRangeDbFunctionsExtensions.IsStrictlyLeftOf)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeIsStrictlyLeftOf, arguments[0], arguments[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeIsStrictlyLeftOf, arguments[0], arguments[1]),
nameof(NpgsqlRangeDbFunctionsExtensions.IsStrictlyRightOf)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeIsStrictlyRightOf, arguments[0], arguments[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeIsStrictlyRightOf, arguments[0], arguments[1]),
nameof(NpgsqlRangeDbFunctionsExtensions.DoesNotExtendRightOf)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeDoesNotExtendRightOf, arguments[0], arguments[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeDoesNotExtendRightOf, arguments[0], arguments[1]),
nameof(NpgsqlRangeDbFunctionsExtensions.DoesNotExtendLeftOf)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeDoesNotExtendLeftOf, arguments[0], arguments[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeDoesNotExtendLeftOf, arguments[0], arguments[1]),
nameof(NpgsqlRangeDbFunctionsExtensions.IsAdjacentTo)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeIsAdjacentTo, arguments[0], arguments[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeIsAdjacentTo, arguments[0], arguments[1]),
nameof(NpgsqlRangeDbFunctionsExtensions.Union)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeUnion, arguments[0], arguments[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeUnion, arguments[0], arguments[1]),
nameof(NpgsqlRangeDbFunctionsExtensions.Intersect)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeIntersect, arguments[0], arguments[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeIntersect, arguments[0], arguments[1]),
nameof(NpgsqlRangeDbFunctionsExtensions.Except)
=> _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.RangeExcept, arguments[0], arguments[1]),
=> _sqlExpressionFactory.MakePostgresBinary(PgExpressionType.RangeExcept, arguments[0], arguments[1]),

_ => null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public NpgsqlRowValueTranslator(NpgsqlSqlExpressionFactory sqlExpressionFactory)
// Translate ValueTuple.Create
if (method.DeclaringType == typeof(ValueTuple) && method is { IsStatic: true, Name: nameof(ValueTuple.Create) })
{
return new PostgresRowValueExpression(arguments, method.ReturnType);
return new PgRowValueExpression(arguments, method.ReturnType);
}

// Translate EF.Functions.GreaterThan and other comparisons
Expand All @@ -69,13 +69,13 @@ public NpgsqlRowValueTranslator(NpgsqlSqlExpressionFactory sqlExpressionFactory)
return null;
}

var leftCount = arguments[1] is PostgresRowValueExpression leftRowValue
var leftCount = arguments[1] is PgRowValueExpression leftRowValue
? leftRowValue.Values.Count
: arguments[1] is SqlConstantExpression { Value : ITuple leftTuple }
? (int?)leftTuple.Length
: null;

var rightCount = arguments[2] is PostgresRowValueExpression rightRowValue
var rightCount = arguments[2] is PgRowValueExpression rightRowValue
? rightRowValue.Values.Count
: arguments[2] is SqlConstantExpression { Value : ITuple rightTuple }
? (int?)rightTuple.Length
Expand Down
Loading
Loading