Skip to content

Commit d1ec2c5

Browse files
author
Minh Le (from Dev Box)
committed
update comments
1 parent 430f96a commit d1ec2c5

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ private static Collection VisitGroupBy(Type returnElementType, ReadOnlyCollectio
17631763

17641764
case ExpressionType.New:
17651765
// TODO: Multi Value Selector
1766-
throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.ExpressionTypeIsNotSupported, "Multiple value selector"));
1766+
throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.ExpressionTypeIsNotSupported, ExpressionType.New));
17671767

17681768
default:
17691769
throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.ExpressionTypeIsNotSupported, valueSelectorExpression.NodeType));
@@ -1963,17 +1963,12 @@ private static SqlSelectClause VisitAggregateFunction(
19631963
context.PopParameter();
19641964
}
19651965
else if (arguments.Count == 2)
1966-
{
1967-
if (context.CurrentQuery.GroupByParameter != null)
1968-
{
1969-
LambdaExpression lambda = Utilities.GetLambda(arguments[1]);
1970-
aggregateExpression = ExpressionToSql.VisitNonSubqueryScalarLambda(lambda, context);
1971-
}
1972-
else
1973-
{
1974-
LambdaExpression lambda = Utilities.GetLambda(arguments[1]);
1975-
aggregateExpression = ExpressionToSql.VisitScalarExpression(lambda, context);
1976-
}
1966+
{
1967+
LambdaExpression lambda = Utilities.GetLambda(arguments[1]);
1968+
1969+
aggregateExpression = context.CurrentQuery.GroupByParameter != null
1970+
? ExpressionToSql.VisitNonSubqueryScalarLambda(lambda, context)
1971+
: ExpressionToSql.VisitScalarExpression(lambda, context);
19771972
}
19781973
else
19791974
{

Microsoft.Azure.Cosmos/src/Linq/QueryUnderConstruction.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public QueryUnderConstruction FlattenAsPossible()
251251
}
252252

253253
// In case of Select -> Group by cases, the Select query should not be flattened and kept as a subquery
254-
if (query.inputQuery != null && query.inputQuery.selectClause != null && query.groupByClause != null)
254+
if ((query.inputQuery?.selectClause != null) && (query.groupByClause != null))
255255
{
256256
flattenQuery = this;
257257
break;
@@ -302,7 +302,7 @@ private QueryUnderConstruction Flatten()
302302
{
303303
// If selectClause doesn't exists, use SELECT v0 where v0 is the input parameter, instead of SELECT *.
304304
// If there is a groupby clause, the input parameter comes from the groupBy binding instead of the from clause binding
305-
string parameterName = this.GroupByParameter != null ? this.GroupByParameter.GetInputParameter().Name : this.FromParameters.GetInputParameter().Name;
305+
string parameterName = (this.GroupByParameter ?? this.FromParameters).GetInputParameter().Name;
306306
SqlScalarExpression parameterExpression = SqlPropertyRefScalarExpression.Create(null, SqlIdentifier.Create(parameterName));
307307
this.selectClause = SqlSelectClause.Create(SqlSelectValueSpec.Create(parameterExpression));
308308
}
@@ -559,14 +559,16 @@ public bool ShouldBeOnNewQuery(string methodName, int argumentCount)
559559
// New query is needed when there is already a Take or a non-distinct Select
560560
shouldPackage = (this.topSpec != null) ||
561561
(this.offsetSpec != null) ||
562-
(this.selectClause != null && !this.selectClause.HasDistinct) || this.groupByClause != null;
562+
(this.selectClause != null && !this.selectClause.HasDistinct) ||
563+
(this.groupByClause != null);
563564
break;
564565

565566
case LinqMethods.GroupBy:
566567
// New query is needed when there is already a Take or a Select or a Group by clause
567568
shouldPackage = (this.topSpec != null) ||
568569
(this.offsetSpec != null) ||
569-
(this.selectClause != null) || this.groupByClause != null;
570+
(this.selectClause != null) ||
571+
(this.groupByClause != null);
570572
break;
571573

572574
case LinqMethods.Skip:

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqGeneralBaselineTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,9 @@ public void TestSubquery()
700700
[TestMethod]
701701
public void TestGroupByTranslation()
702702
{
703-
List<LinqTestInput> inputs = new List<LinqTestInput>();
703+
List<LinqTestInput> inputs = new List<LinqTestInput>();
704+
inputs.Add(new LinqTestInput("GroupBy Single Value Select Key", b => getQuery(b).GroupBy(k => k /*keySelector*/,
705+
(key, values) => key /*return the group by key */)));
704706
inputs.Add(new LinqTestInput("GroupBy Single Value Select Key", b => getQuery(b).GroupBy(k => k.Id /*keySelector*/,
705707
(key, values) => key /*return the group by key */)));
706708
inputs.Add(new LinqTestInput("GroupBy Single Value Select Key Alias", b => getQuery(b).GroupBy(k => k.Id /*keySelector*/,
@@ -713,7 +715,7 @@ public void TestGroupByTranslation()
713715
(key, values) => values.Max(value => value.Int) /*return the Max of each group */)));
714716
inputs.Add(new LinqTestInput("GroupBy Single Value With Count", b => getQuery(b).GroupBy(k => k.Id /*keySelector*/,
715717
(key, values) => values.Count() /*return the Count of each group */)));
716-
inputs.Add(new LinqTestInput("GroupBy Single Value With Count", b => getQuery(b).GroupBy(k => k.Id /*keySelector*/,
718+
inputs.Add(new LinqTestInput("GroupBy Single Value With Average", b => getQuery(b).GroupBy(k => k.Id /*keySelector*/,
717719
(key, values) => values.Average(value => value.Int) /*return the Count of each group */)));
718720

719721
// Negative cases

0 commit comments

Comments
 (0)