Skip to content

Commit

Permalink
SQLite: Translate Math.Sign
Browse files Browse the repository at this point in the history
Part of #18843
  • Loading branch information
bricelam committed May 19, 2023
1 parent 63dde72 commit c983103
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ public class SqliteMathTranslator : IMethodCallTranslator
{ typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(ushort), typeof(ushort) })!, "min" },
{ typeof(Math).GetMethod(nameof(Math.Round), new[] { typeof(double) })!, "round" },
{ typeof(Math).GetMethod(nameof(Math.Round), new[] { typeof(double), typeof(int) })!, "round" },
{ typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(double) })!, "sign" },
{ typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(float) })!, "sign" },
{ typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(long) })!, "sign" },
{ typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(sbyte) })!, "sign" },
{ typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(short) })!, "sign" },
{ typeof(MathF).GetMethod(nameof(MathF.Abs), new[] { typeof(float) })!, "abs" },
{ typeof(MathF).GetMethod(nameof(MathF.Max), new[] { typeof(float), typeof(float) })!, "max" },
{ typeof(MathF).GetMethod(nameof(MathF.Min), new[] { typeof(float), typeof(float) })!, "min" },
{ typeof(MathF).GetMethod(nameof(MathF.Round), new[] { typeof(float) })!, "round" },
{ typeof(MathF).GetMethod(nameof(MathF.Round), new[] { typeof(float), typeof(int) })!, "round" }
{ typeof(MathF).GetMethod(nameof(MathF.Round), new[] { typeof(float), typeof(int) })!, "round" },
{ typeof(MathF).GetMethod(nameof(MathF.Sign), new[] { typeof(float) })!, "sign" }
};

private readonly ISqlExpressionFactory _sqlExpressionFactory;
Expand Down Expand Up @@ -78,7 +84,7 @@ public SqliteMathTranslator(ISqlExpressionFactory sqlExpressionFactory)
{
RelationalTypeMapping? typeMapping;
List<SqlExpression>? newArguments = null;
if (sqlFunctionName == "max" || sqlFunctionName == "max")
if (sqlFunctionName == "max" || sqlFunctionName == "min")
{
typeMapping = ExpressionExtensions.InferTypeMapping(arguments[0], arguments[1]);
newArguments = new List<SqlExpression>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,17 @@ public override Task Sum_over_truncate_works_correctly_in_projection_2(bool asyn
public override Task Where_math_round2(bool async)
=> AssertTranslationFailed(() => base.Where_math_round2(async));

public override Task Where_math_sign(bool async)
=> AssertTranslationFailed(() => base.Where_math_sign(async));
public override async Task Where_math_sign(bool async)
{
await base.Where_math_sign(async);

AssertSql(
"""
SELECT "o"."OrderID", "o"."ProductID", "o"."Discount", "o"."Quantity", "o"."UnitPrice"
FROM "Order Details" AS "o"
WHERE "o"."OrderID" = 11077 AND sign("o"."Discount") > 0
""");
}

public override Task Where_math_sin(bool async)
=> AssertTranslationFailed(() => base.Where_math_sin(async));
Expand Down Expand Up @@ -174,8 +183,17 @@ public override Task Where_mathf_power(bool async)
public override Task Where_mathf_square(bool async)
=> AssertTranslationFailed(() => base.Where_mathf_square(async));

public override Task Where_mathf_sign(bool async)
=> AssertTranslationFailed(() => base.Where_mathf_sign(async));
public override async Task Where_mathf_sign(bool async)
{
await base.Where_mathf_sign(async);

AssertSql(
"""
SELECT "o"."OrderID", "o"."ProductID", "o"."Discount", "o"."Quantity", "o"."UnitPrice"
FROM "Order Details" AS "o"
WHERE "o"."OrderID" = 11077 AND sign("o"."Discount") > 0
""");
}

public override Task Where_mathf_sin(bool async)
=> AssertTranslationFailed(() => base.Where_mathf_sin(async));
Expand Down

0 comments on commit c983103

Please sign in to comment.