Skip to content

Commit

Permalink
Removing compiler warnings, adding negative test case, removing redun…
Browse files Browse the repository at this point in the history
…dant code and adding comments referencing issue OData#758.
  • Loading branch information
shinlges authored and robward-ms committed Feb 13, 2017
1 parent 08d9de2 commit 729e322
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ private IEdmTypeReference CreateAggregateExpressionTypeReference(SingleValueNode

case AggregationMethod.VirtualPropertyCount:
case AggregationMethod.CountDistinct:
// Issue #758: CountDistinct and $Count should return type Edm.Decimal with Scale="0" and sufficient Precision.
return EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int64, false);
case AggregationMethod.Max:
case AggregationMethod.Min:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,12 @@ internal AggregateExpressionToken ParseAggregateExpression()
var endPathExpression = expression as EndPathToken;
AggregationMethod verb;

// e.g. aggregate($count as Count)
if (endPathExpression != null && endPathExpression.Identifier == ExpressionConstants.QueryOptionCount)
{
expression = new EndPathToken("$count", endPathExpression.NextToken);
verb = AggregationMethod.VirtualPropertyCount;
}
// e.g. aggregate(UnitPrice with sum as Total)
else
{
// "with" verb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
using Microsoft.OData.Edm;
//---------------------------------------------------------------------
// <copyright file="CountVirtualPropertyNode.cs" company="Microsoft">
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
// </copyright>
//---------------------------------------------------------------------
using Microsoft.OData.Edm;

namespace Microsoft.OData.UriParser
{
/// <summary>
/// Dummy class that allows virtual property $count
/// Dummy class that allows virtual property $count
/// to work like any other aggregation method.
/// </summary>
public sealed class CountVirtualPropertyNode : SingleValueNode
{
public CountVirtualPropertyNode() { }
/// <summary>Constructor.</summary>
public CountVirtualPropertyNode()
{
}

/// <summary>Kind of the single value node.</summary>
public override QueryNodeKind Kind
{
get
{
return QueryNodeKind.None;
return QueryNodeKind.Count;
}
}

public override IEdmTypeReference TypeReference {
get {
/// <summary>Type returned by the $count virtual property.</summary>
public override IEdmTypeReference TypeReference
{
get
{
// Issue #758: CountDistinct and $Count should return type Edm.Decimal with Scale="0" and sufficient Precision.
return EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int64, false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ public void ParseApplyWithSingleCountExpressionShouldReturnAggregateToken()
VerifyAggregateExpressionToken("$count", AggregationMethod.VirtualPropertyCount, "Count", aggregate.Expressions.First());
}

[Fact]
public void ParseApplyWithSingleCountExpressionCannotHaveWithKeyWord()
{
var apply = "aggregate($count with sum as Count)";

Action parse = () => this.testSubject.ParseApply(apply);
parse.ShouldThrow<ODataException>().Where(e => e.Message == ErrorStrings.UriQueryExpressionParser_AsExpected(17, apply));
}

[Fact]
public void ParseApplyWithCountAndOtherAggregationExpressionShouldReturnAggregateToken()
{
Expand Down

0 comments on commit 729e322

Please sign in to comment.