You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add AggregateFunctionExpression as a relational base for provider aggregate functions - #39234
Adds a public AggregateFunctionExpression to Relational. It is the base type for provider aggregate function expressions: SqlServerAggregateFunctionExpression now, and later SqliteAggregateFunctionExpression and Npgsql's PgFunctionExpression.
Changes
Relational
New AggregateFunctionExpression (Query/SqlExpressions) with Name, Arguments, Orderings, IsNullable and ArgumentsPropagateNullability.
Subclasses override one hook, protected virtual Create(...), so Update, ApplyTypeMapping and VisitChildren keep returning the derived type.
protected virtual QuoteConstructorArguments() lets subclasses with the same constructor implement Quote() without duplicating code.
Equals also compares the runtime type.
QuerySqlGenerator: generates NAME(args ORDER BY ...), the SQL-standard form, by default. Providers can change where the orderings go by overriding the new GenerateAggregateFunctionOrderings(expression, insideArgumentList) hook.
SqlNullabilityProcessor: the nullability logic for aggregate functions moved here from the SQL Server processor.
SqlServerAggregateFunctionExpression is now a thin subclass with the constructor, Create, Quote and its WITHIN GROUP printing.
SqlServerQuerySqlGenerator overrides only the orderings hook, to emit WITHIN GROUP (ORDER BY ...).
Removed the duplicated code from SqlServerSqlNullabilityProcessor, SqlServerQuerySqlGenerator and SqlServerSqlExpressionFactory.
Design notes
IsDistinct and FILTER (WHERE ...) are deliberately left out of the base. Relational already represents them with DistinctExpression and CASE WHEN, and no in-box provider emits FILTER.
They can be added later without a breaking change, and Npgsql can carry them in its subclass.
This PR is a refactor only. The generated SQL does not change. Translating ordered group_concat on SQLite (which needs SQLite 3.44 or later) will come in a follow-up PR built on this base.
The new Create dispatch lacks focused regression coverage: the added generator tests render an unchanged base instance, and the existing SQL Server precompiled-query test covers quoting rather than preservation of extra subclass state. Add relational expression tests with a subclass carrying extra state. Force recreation through Update, ApplyTypeMapping, and visitor rewrites of arguments and orderings, then assert that the runtime type and state survive. Also verify that an unchanged Update returns the same instance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #38357
Adds a public
AggregateFunctionExpressionto Relational. It is the base type for provider aggregate function expressions:SqlServerAggregateFunctionExpressionnow, and laterSqliteAggregateFunctionExpressionand Npgsql'sPgFunctionExpression.Changes
Relational
AggregateFunctionExpression(Query/SqlExpressions) withName,Arguments,Orderings,IsNullableandArgumentsPropagateNullability.protected virtual Create(...), soUpdate,ApplyTypeMappingandVisitChildrenkeep returning the derived type.protected virtual QuoteConstructorArguments()lets subclasses with the same constructor implementQuote()without duplicating code.Equalsalso compares the runtime type.QuerySqlGenerator: generatesNAME(args ORDER BY ...), the SQL-standard form, by default. Providers can change where the orderings go by overriding the newGenerateAggregateFunctionOrderings(expression, insideArgumentList)hook.SqlNullabilityProcessor: the nullability logic for aggregate functions moved here from the SQL Server processor.SqlExpressionFactory.ApplyTypeMapping: handlesAggregateFunctionExpression.SQL Server
SqlServerAggregateFunctionExpressionis now a thin subclass with the constructor,Create,Quoteand itsWITHIN GROUPprinting.SqlServerQuerySqlGeneratoroverrides only the orderings hook, to emitWITHIN GROUP (ORDER BY ...).SqlServerSqlNullabilityProcessor,SqlServerQuerySqlGeneratorandSqlServerSqlExpressionFactory.Design notes
IsDistinctandFILTER (WHERE ...)are deliberately left out of the base. Relational already represents them withDistinctExpressionandCASE WHEN, and no in-box provider emitsFILTER.They can be added later without a breaking change, and Npgsql can carry them in its subclass.
group_concaton SQLite (which needs SQLite 3.44 or later) will come in a follow-up PR built on this base.