Skip to content

Commit

Permalink
Use the proper type mapping for the result of AVG (#35023)
Browse files Browse the repository at this point in the history
Fixes #26378
  • Loading branch information
ChrisJollyAU authored Oct 31, 2024
1 parent 17ed217 commit 507e7f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private ShapedQueryExpression CreateShapedQueryExpression(SelectExpression selec
}

var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());
projection = _sqlExpressionFactory.Function("AVG", new[] { projection }, projection.Type, projection.TypeMapping);
projection = _sqlExpressionFactory.Function("AVG", new[] { projection }, resultType, _typeMappingSource.FindMapping(resultType));

return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,22 +699,19 @@ public override async Task Min_no_data_subquery(bool async)
AssertSql();
}

public override async Task Average_with_no_arg(bool async)
{
// Always throws for sync.
if (async)
{
// Average truncates. Issue #26378.
await Assert.ThrowsAsync<EqualException>(async () => await base.Average_with_no_arg(async));
public override Task Average_with_no_arg(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Average_with_no_arg(a);

AssertSql(
"""
AssertSql(
"""
SELECT VALUE AVG(c["OrderID"])
FROM root c
WHERE (c["$type"] = "Order")
""");
}
}
});

public override Task Average_with_binary_expression(bool async)
=> Fixture.NoSyncTest(
Expand All @@ -730,22 +727,19 @@ FROM root c
""");
});

public override async Task Average_with_arg(bool async)
{
// Always throws for sync.
if (async)
{
// Average truncates. Issue #26378.
await Assert.ThrowsAsync<EqualException>(async () => await base.Average_with_arg(async));
public override Task Average_with_arg(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Average_with_arg(a);

AssertSql(
"""
AssertSql(
"""
SELECT VALUE AVG(c["OrderID"])
FROM root c
WHERE (c["$type"] = "Order")
""");
}
}
});

public override Task Average_with_arg_expression(bool async)
=> Fixture.NoSyncTest(
Expand Down

0 comments on commit 507e7f1

Please sign in to comment.