Normalize aggregate calls in the SQL tree
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 8/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- csharp
- Lĩnh vực
- backend-api-design, databases
Hướng nghiên cứu
Start from AggregateFunctionExpression and SqlFunctionExpression in the relational query expression tree, then read QuerySqlGenerator.VisitAggregateFunction and VisitSqlFunction to see how schema/name quoting differs. Trace producers next: QueryableAggregateMethodTranslator and the SQL Server/SQLite aggregate translators, plus SqlNullabilityProcessor.VisitSqlFunction for the SUM special case. Done means built-in aggregates emit aggregate nodes, IReadOnlyDbFunction.IsAggregate drives translation, and the existing relational query tests (SQL Server and SQLite assertion suites) pass with the newnode shapes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Make the SQL expression tree authoritative: every aggregate invocation should be an AggregateFunctionExpression, while SqlFunctionExpression represents ordinary scalar invocations. Use IReadOnlyDbFunction.IsAggregate to select the correct node during translation of non-built-in functions.
This requires more than changing the folding visitor.
1. Complete the aggregate expression’s contract
AggregateFunctionExpression already supports arguments, ordering, nullability, type mapping, provider subclasses, and quoting. Extend it to support schema-qualified and non-built-in aggregates.
Consider using composition: let AggregateFunctionExpression contain a SqlFunctionExpression describing the underlying call. Also see #36545
Preserve existing constructors and add the necessary overloads. Carry the new identity fields through Create, Update, ApplyTypeMapping, equality, hashing, printing, and quoting. Update QuerySqlGenerator.VisitAggregateFunction to delimit schema/name correctly, reusing the naming rules currently in VisitSqlFunction.
Do not require providers to subclass merely to represent an unordered user-defined aggregate.
2. Migrate aggregate producers, not just consumers
Change every built-in aggregate translator to emit explicit aggregate nodes:
QueryableAggregateMethodTranslator:COUNT,SUM,AVG,MIN, andMAX.- SQL Server aggregate translators/helpers: statistics, string aggregation, and provider overrides.
- SQLite aggregate translators: including
ef_sum,ef_avg,ef_min, andef_max. - Reconcile
SqliteAggregateFunctionExpressionwith the relational aggregate representation, preserving its provider-specific state and syntax.
Retain scalar wrappers outside the aggregate:
COALESCE(AggregateFunctionExpression("SUM", ...), 0)
SQLite’s overloaded min/max then become unambiguous: the scalar method translator creates SqlFunctionExpression; the aggregate translator creates AggregateFunctionExpression. No downstream argument-count heuristic is needed.
Document the same contract for IAggregateMethodCallTranslator implementations. A translation can return a compound expression containing aggregates; it must mark the actual aggregate invocations, not necessarily make the whole result an aggregate node.
3. Preserve semantics in downstream consumers
Audit consumers that currently recognize aggregate names or require SqlFunctionExpression:
| Consumer | Required change |
|---|---|
| Grouping aggregate folding | Traverse scalar functions; treat aggregate and window expressions as boundaries. Remove IsKnownScalarFunction. |
SqlServerAggregateArgumentPostprocessor |
Recognize aggregate nodes, including ordered/provider-derived aggregates, rather than a function-name list. |
Window translation and CanTranslateAggregateAsWindowFunction |
Accept explicit aggregate nodes while keeping window support a separate provider capability. |
| Nullability processing | Preserve existing aggregate result semantics during migration. |
| Type mapping, simplification, quoting/precompilation | Preserve node kind and provider-specific state through rewrites. |
Nullability is a concrete migration hazard: SqlNullabilityProcessor.VisitSqlFunction currently special-cases SUM by adding zero compensation, whereas VisitAggregateFunction does not. Move responsibility deliberately—preferably into LINQ aggregate lowering—rather than transferring a name-based rule to every database aggregate called SUM. A mapped database aggregate may legitimately return null.
4. Make IsAggregate operational
Currently, DbFunction initializes IsAggregate to false, and RelationalAggregateMethodCallTranslatorProvider still has commented-out user-defined aggregate support.
To make the metadata reliable:
- Add aggregate configuration through the relevant mutable/convention/builder layers, with configuration precedence and validation.
- Require aggregates to have scalar results;
IsScalaralone must not imply non-aggregate. - Route mapped aggregate methods through aggregate translation, preserving their enumerable input, filters, distinctness, ordering, and additional scalar arguments.
- Use the metadata to construct
AggregateFunctionExpression, including schema and built-in identity. - Define a contract for custom translation callbacks: aggregate invocations in returned SQL must use aggregate nodes. Do not blindly wrap an arbitrary returned expression.
- Preserve classification through runtime models and compiled-model generation. Existing
RuntimeDbFunctionand runtime-model plumbing already carry the flag and can be reused.
This also addresses the underlying direction of custom-aggregate support, rather than making metadata classification a separate lookup mechanism.
- Ngôn ngữ chính
- C#
- Star
- 14.8k
- Fork
- 3.5k
- Merge trung bình
- 2 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 158
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/efcore
-
Test bug: Include_collection_with_cross_apply_with_filter relies on nondeterministic ORDER BY with TakeCó thể đã có người làm @Mohamedadel-prog đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
dotnet/efcore#39848 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
customer-reported
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Compiled model: generate a deterministic model IDCó thể đã có người làm @rgroenewoudt đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 2 ngày
-
customer-reported
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của dotnet/efcore
Issue tương tự
-
area-VM-meta-mono untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microsoft/sqltoolsservice#2851 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
elsa-workflows/elsa-foundation#6322 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
mohebifar/made-in-iran#273 ·