@@ -18,17 +18,25 @@ namespace Microsoft.EntityFrameworkCore.Query;
18
18
/// </summary>
19
19
public class RelationalWindowAggregateMethodTranslator : IWindowAggregateMethodCallTranslator
20
20
{
21
- private readonly ISqlExpressionFactory _sqlExpressionFactory ;
21
+ /// <summary>
22
+ /// todo
23
+ /// </summary>
24
+ public virtual ISqlExpressionFactory SqlExpressionFactory => Dependencies . SqlExpressionFactory ;
25
+
26
+ /// <summary>
27
+ /// todo
28
+ /// </summary>
29
+ public virtual RelationalWindowAggregateMethodTranslatorDependencies Dependencies { get ; }
22
30
23
31
/// <summary>
24
32
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
25
33
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
26
34
/// any release. You should only use it directly in your code with extreme caution and knowing that
27
35
/// doing so can result in application failures when updating to a new Entity Framework Core release.
28
36
/// </summary>
29
- public RelationalWindowAggregateMethodTranslator ( ISqlExpressionFactory sqlExpressionFactory )
37
+ public RelationalWindowAggregateMethodTranslator ( RelationalWindowAggregateMethodTranslatorDependencies dependencies )
30
38
{
31
- _sqlExpressionFactory = sqlExpressionFactory ;
39
+ Dependencies = dependencies ;
32
40
}
33
41
34
42
/// <summary>
@@ -50,118 +58,118 @@ public RelationalWindowAggregateMethodTranslator(ISqlExpressionFactory sqlExpres
50
58
case nameof ( RelationalWindowAggregateFunctionExtensions . Average )
51
59
when methodInfo == RelationalWindowAggregateMethods . Average :
52
60
53
- return _sqlExpressionFactory . Function ( "AVG" , arguments , false , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
61
+ return SqlExpressionFactory . Function ( "AVG" , arguments , false , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
54
62
55
63
case nameof ( RelationalWindowAggregateFunctionExtensions . Average )
56
64
when methodInfo == RelationalWindowAggregateMethods . AverageFilter :
57
65
58
- return _sqlExpressionFactory . Function ( "AVG" , BuildCaseExpression ( arguments ) , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
66
+ return SqlExpressionFactory . Function ( "AVG" , BuildCaseExpression ( arguments ) , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
59
67
60
68
case nameof ( RelationalWindowAggregateFunctionExtensions . Count )
61
69
when methodInfo == RelationalWindowAggregateMethods . CountAll :
62
70
63
- return _sqlExpressionFactory . Function ( "COUNT" , [ _sqlExpressionFactory . Fragment ( "*" ) ] , false , [ false ] , typeof ( int ) ) ;
71
+ return SqlExpressionFactory . Function ( "COUNT" , [ SqlExpressionFactory . Fragment ( "*" ) ] , false , [ false ] , typeof ( int ) ) ;
64
72
65
73
case nameof ( RelationalWindowAggregateFunctionExtensions . Count )
66
74
when methodInfo == RelationalWindowAggregateMethods . CountAllFilter :
67
75
68
- return _sqlExpressionFactory . Function ( "COUNT" , BuildCaseExpression ( arguments , _sqlExpressionFactory . Constant ( "1" ) ) , true , [ false ] , typeof ( int ) ) ;
76
+ return SqlExpressionFactory . Function ( "COUNT" , BuildCaseExpression ( arguments , SqlExpressionFactory . Constant ( "1" ) ) , true , [ false ] , typeof ( int ) ) ;
69
77
70
78
case nameof ( RelationalWindowAggregateFunctionExtensions . Count )
71
79
when methodInfo == RelationalWindowAggregateMethods . CountCol :
72
80
73
- return _sqlExpressionFactory . Function ( "COUNT" , arguments , false , [ false ] , typeof ( int ) ) ;
81
+ return SqlExpressionFactory . Function ( "COUNT" , arguments , false , [ false ] , typeof ( int ) ) ;
74
82
75
83
case nameof ( RelationalWindowAggregateFunctionExtensions . Count )
76
84
when methodInfo == RelationalWindowAggregateMethods . CountColFilter :
77
85
78
- return _sqlExpressionFactory . Function ( "COUNT" , BuildCaseExpression ( arguments ) , true , [ false ] , typeof ( int ) ) ;
86
+ return SqlExpressionFactory . Function ( "COUNT" , BuildCaseExpression ( arguments ) , true , [ false ] , typeof ( int ) ) ;
79
87
80
88
case nameof ( RelationalWindowAggregateFunctionExtensions . CumeDist )
81
89
when methodInfo == RelationalWindowAggregateMethods . CumeDist :
82
90
83
- return _sqlExpressionFactory . Function ( "CUME_DIST" , Enumerable . Empty < SqlExpression > ( ) , false , [ ] , typeof ( double ) ) ;
91
+ return SqlExpressionFactory . Function ( "CUME_DIST" , Enumerable . Empty < SqlExpression > ( ) , false , [ ] , typeof ( double ) ) ;
84
92
85
93
case nameof ( RelationalWindowAggregateFunctionExtensions . DenseRank )
86
94
when methodInfo == RelationalWindowAggregateMethods . DenseRank :
87
95
88
- return _sqlExpressionFactory . Function ( "DENSE_RANK" , Enumerable . Empty < SqlExpression > ( ) , false , [ ] , typeof ( long ) ) ;
96
+ return SqlExpressionFactory . Function ( "DENSE_RANK" , Enumerable . Empty < SqlExpression > ( ) , false , [ ] , typeof ( long ) ) ;
89
97
90
98
case nameof ( RelationalWindowAggregateFunctionExtensions . FirstValue )
91
99
when methodInfo == RelationalWindowAggregateMethods . FirstValueFrameResults :
92
100
93
101
case nameof ( RelationalWindowAggregateFunctionExtensions . FirstValue )
94
102
when methodInfo == RelationalWindowAggregateMethods . FirstValueOrderThen :
95
103
96
- return _sqlExpressionFactory . Function ( "FIRST_VALUE" , arguments , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
104
+ return SqlExpressionFactory . Function ( "FIRST_VALUE" , arguments , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
97
105
98
106
case nameof ( RelationalWindowAggregateFunctionExtensions . Lag )
99
107
when methodInfo == RelationalWindowAggregateMethods . Lag :
100
108
101
- return _sqlExpressionFactory . Function ( "LAG" , arguments , true , [ false , false , false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
109
+ return SqlExpressionFactory . Function ( "LAG" , arguments , true , [ false , false , false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
102
110
103
111
case nameof ( RelationalWindowAggregateFunctionExtensions . LastValue )
104
112
when methodInfo == RelationalWindowAggregateMethods . LastValueOrderThen :
105
113
106
114
case nameof ( RelationalWindowAggregateFunctionExtensions . LastValue )
107
115
when methodInfo == RelationalWindowAggregateMethods . LastValueFrameResults :
108
116
109
- return _sqlExpressionFactory . Function ( "LAST_VALUE" , arguments , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
117
+ return SqlExpressionFactory . Function ( "LAST_VALUE" , arguments , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
110
118
111
119
case nameof ( RelationalWindowAggregateFunctionExtensions . Lead )
112
120
when methodInfo == RelationalWindowAggregateMethods . Lead :
113
121
114
- return _sqlExpressionFactory . Function ( "LEAD" , arguments , true , [ false , false , false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
122
+ return SqlExpressionFactory . Function ( "LEAD" , arguments , true , [ false , false , false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
115
123
116
124
case nameof ( RelationalWindowAggregateFunctionExtensions . Max )
117
125
when methodInfo == RelationalWindowAggregateMethods . Max :
118
126
119
- return _sqlExpressionFactory . Function ( "MAX" , arguments , false , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
127
+ return SqlExpressionFactory . Function ( "MAX" , arguments , false , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
120
128
121
129
case nameof ( RelationalWindowAggregateFunctionExtensions . Max )
122
130
when methodInfo == RelationalWindowAggregateMethods . MaxFilter :
123
131
124
- return _sqlExpressionFactory . Function ( "MAX" , BuildCaseExpression ( arguments ) , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
132
+ return SqlExpressionFactory . Function ( "MAX" , BuildCaseExpression ( arguments ) , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
125
133
126
134
case nameof ( RelationalWindowAggregateFunctionExtensions . Min )
127
135
when methodInfo == RelationalWindowAggregateMethods . Min :
128
136
129
- return _sqlExpressionFactory . Function ( "MIN" , arguments , false , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
137
+ return SqlExpressionFactory . Function ( "MIN" , arguments , false , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
130
138
131
139
case nameof ( RelationalWindowAggregateFunctionExtensions . Min )
132
140
when methodInfo == RelationalWindowAggregateMethods . MinFilter :
133
141
134
- return _sqlExpressionFactory . Function ( "MIN" , BuildCaseExpression ( arguments ) , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
142
+ return SqlExpressionFactory . Function ( "MIN" , BuildCaseExpression ( arguments ) , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
135
143
136
144
case nameof ( RelationalWindowAggregateFunctionExtensions . NTile )
137
145
when methodInfo == RelationalWindowAggregateMethods . NTile :
138
146
139
- return _sqlExpressionFactory . Function ( "NTILE" , arguments , false , [ false ] , typeof ( long ) ) ;
147
+ return SqlExpressionFactory . Function ( "NTILE" , arguments , false , [ false ] , typeof ( long ) ) ;
140
148
141
149
case nameof ( RelationalWindowAggregateFunctionExtensions . PercentRank )
142
150
when methodInfo == RelationalWindowAggregateMethods . PercentRank :
143
151
144
- return _sqlExpressionFactory . Function ( "PERCENT_RANK" , Enumerable . Empty < SqlExpression > ( ) , false , [ ] , typeof ( double ) ) ;
152
+ return SqlExpressionFactory . Function ( "PERCENT_RANK" , Enumerable . Empty < SqlExpression > ( ) , false , [ ] , typeof ( double ) ) ;
145
153
146
154
case nameof ( RelationalWindowAggregateFunctionExtensions . Rank )
147
155
when methodInfo == RelationalWindowAggregateMethods . Rank :
148
156
149
- return _sqlExpressionFactory . Function ( "RANK" , Enumerable . Empty < SqlExpression > ( ) , false , [ ] , typeof ( long ) ) ;
157
+ return SqlExpressionFactory . Function ( "RANK" , Enumerable . Empty < SqlExpression > ( ) , false , [ ] , typeof ( long ) ) ;
150
158
151
159
case nameof ( RelationalWindowAggregateFunctionExtensions . RowNumber )
152
160
when methodInfo == RelationalWindowAggregateMethods . RowNumber :
153
161
154
- return _sqlExpressionFactory . Function ( "ROW_NUMBER" , Enumerable . Empty < SqlExpression > ( ) , false , [ ] , typeof ( long ) ) ;
162
+ return SqlExpressionFactory . Function ( "ROW_NUMBER" , Enumerable . Empty < SqlExpression > ( ) , false , [ ] , typeof ( long ) ) ;
155
163
156
164
case nameof ( RelationalWindowAggregateFunctionExtensions . Sum )
157
165
when methodInfo == RelationalWindowAggregateMethods . Sum :
158
166
159
- return _sqlExpressionFactory . Function ( "SUM" , arguments , false , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
167
+ return SqlExpressionFactory . Function ( "SUM" , arguments , false , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
160
168
161
169
case nameof ( RelationalWindowAggregateFunctionExtensions . Sum )
162
170
when methodInfo == RelationalWindowAggregateMethods . SumFilter :
163
171
164
- return _sqlExpressionFactory . Function ( "SUM" , BuildCaseExpression ( arguments ) , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
172
+ return SqlExpressionFactory . Function ( "SUM" , BuildCaseExpression ( arguments ) , true , [ false ] , arguments [ 0 ] . Type , arguments [ 0 ] . TypeMapping ) ;
165
173
}
166
174
167
175
return null ;
@@ -174,7 +182,7 @@ public RelationalWindowAggregateMethodTranslator(ISqlExpressionFactory sqlExpres
174
182
/// <param name="arguments">todo</param>
175
183
/// <returns>todo</returns>
176
184
protected virtual SqlExpression [ ] BuildCaseExpression ( IReadOnlyList < SqlExpression > arguments , SqlExpression ? result = null )
177
- => [ _sqlExpressionFactory . Case ( [ new CaseWhenClause ( ProcessCaseWhen ( arguments [ result == null ? 1 : 0 ] ) , result ?? arguments [ 0 ] ) ] , _sqlExpressionFactory . Constant ( null , typeof ( object ) ) ) ] ;
185
+ => [ SqlExpressionFactory . Case ( [ new CaseWhenClause ( ProcessCaseWhen ( arguments [ result == null ? 1 : 0 ] ) , result ?? arguments [ 0 ] ) ] , SqlExpressionFactory . Constant ( null , typeof ( object ) ) ) ] ;
178
186
179
187
180
188
/// <summary>
@@ -184,11 +192,11 @@ protected virtual SqlExpression[] BuildCaseExpression(IReadOnlyList<SqlExpressio
184
192
/// <returns>todo</returns>
185
193
protected virtual SqlExpression ProcessCaseWhen ( SqlExpression whenExpression )
186
194
{
187
- if ( whenExpression is SqlBinaryExpression { Left : InExpression inExpression , Right : SqlConstantExpression constantExpression } )
195
+ if ( whenExpression is SqlBinaryExpression { Left : InExpression inExpression , Right : SqlConstantExpression constantExpression } )
188
196
{
189
197
return constantExpression . Value as bool ? == true
190
198
? inExpression
191
- : _sqlExpressionFactory . Not ( inExpression ) ;
199
+ : SqlExpressionFactory . Not ( inExpression ) ;
192
200
}
193
201
194
202
return whenExpression ;
0 commit comments