Skip to content

Commit

Permalink
address pr comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Minh Le (from Dev Box) committed Apr 1, 2024
1 parent d1ec2c5 commit fc32e3a
Show file tree
Hide file tree
Showing 3 changed files with 484 additions and 458 deletions.
58 changes: 35 additions & 23 deletions Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1734,33 +1734,45 @@ private static Collection VisitGroupBy(Type returnElementType, ReadOnlyCollectio
// The value selector function needs to be either a MethodCall or an AnonymousType
switch (valueSelectorExpression.NodeType)
{
case ExpressionType.Parameter:
ParameterExpression parameterValueExpression = (ParameterExpression)valueSelectorExpression;
SqlScalarExpression selectExpression = ExpressionToSql.VisitParameter(parameterValueExpression, context);
case ExpressionType.Constant:
{
ConstantExpression constantExpression = (ConstantExpression)valueSelectorExpression;
SqlScalarExpression selectExpression = ExpressionToSql.VisitConstant(constantExpression, context);

SqlSelectSpec sqlSpec = SqlSelectValueSpec.Create(selectExpression);
SqlSelectClause select = SqlSelectClause.Create(sqlSpec, null);
context.CurrentQuery = context.CurrentQuery.AddSelectClause(select, context);
break;

case ExpressionType.Call:
// Single Value Selector
MethodCallExpression methodCallExpression = (MethodCallExpression)valueSelectorExpression;
switch (methodCallExpression.Method.Name)
{
case LinqMethods.Max:
case LinqMethods.Min:
case LinqMethods.Average:
case LinqMethods.Count:
case LinqMethods.Sum:
ExpressionToSql.VisitMethodCall(methodCallExpression, context);
break;
default:
throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.MethodNotSupported, methodCallExpression.Method.Name ));
}

break;

break;
}
case ExpressionType.Parameter:
{
ParameterExpression parameterValueExpression = (ParameterExpression)valueSelectorExpression;
SqlScalarExpression selectExpression = ExpressionToSql.VisitParameter(parameterValueExpression, context);

SqlSelectSpec sqlSpec = SqlSelectValueSpec.Create(selectExpression);
SqlSelectClause select = SqlSelectClause.Create(sqlSpec, null);
context.CurrentQuery = context.CurrentQuery.AddSelectClause(select, context);
break;
}
case ExpressionType.Call:
{
// Single Value Selector
MethodCallExpression methodCallExpression = (MethodCallExpression)valueSelectorExpression;
switch (methodCallExpression.Method.Name)
{
case LinqMethods.Max:
case LinqMethods.Min:
case LinqMethods.Average:
case LinqMethods.Count:
case LinqMethods.Sum:
ExpressionToSql.VisitMethodCall(methodCallExpression, context);
break;
default:
throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.MethodNotSupported, methodCallExpression.Method.Name));
}

break;
}
case ExpressionType.New:
// TODO: Multi Value Selector
throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.ExpressionTypeIsNotSupported, ExpressionType.New));
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Linq/QueryUnderConstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ParameterExpression Alias
private Lazy<ParameterExpression> alias;

/// <summary>
/// Input subquery/ query to the left of the current query.
/// Input subquery / query to the left of the current query.
/// </summary>
private QueryUnderConstruction inputQuery;

Expand Down
Loading

0 comments on commit fc32e3a

Please sign in to comment.