public void NestedGroupbyTransformationsIsAllowed() { var result = this.ParseExpandOptions("($apply=groupby((Customer/CountryRegion,Product/Name),aggregate(Amount with sum as Total)))"); result.Should().NotBeNull(); QueryToken token = result.ApplyOptions.Single(); token.Should().BeOfType <GroupByToken>(); GroupByToken groupBy = token as GroupByToken; groupBy.Properties.Should().HaveCount(2); QueryToken queryToken = groupBy.Properties.ElementAt(0); EndPathToken pathToken = queryToken.ShouldBeEndPathToken("CountryRegion"); pathToken.NextToken.ShouldBeInnerPathToken("Customer"); queryToken = groupBy.Properties.ElementAt(1); pathToken = queryToken.ShouldBeEndPathToken("Name"); pathToken.NextToken.ShouldBeInnerPathToken("Product"); groupBy.Child.Should().NotBeNull(); groupBy.Child.Should().BeOfType <AggregateToken>(); AggregateToken aggregate = groupBy.Child as AggregateToken; AggregateExpressionToken aggregateExpressionToken = aggregate.Expressions.Single(); aggregateExpressionToken.Alias.Should().Equals("Total"); aggregateExpressionToken.Method.Should().Equals(AggregationMethod.Sum); aggregateExpressionToken.Expression.ShouldBeEndPathToken("Amount"); }
public void NestedGroupbyTransformationsInExpandIsAllowed() { // Arrange & Act ExpandTermToken expandTerm = this.ParseExpandOptions("($apply=groupby((Customer/CountryRegion,Product/Name),aggregate(Amount with sum as Total)))"); // Assert Assert.NotNull(expandTerm); Assert.NotNull(expandTerm.ApplyOptions); QueryToken token = Assert.Single(expandTerm.ApplyOptions); GroupByToken groupBy = Assert.IsType <GroupByToken>(token); Assert.Equal(2, groupBy.Properties.Count()); QueryToken queryToken = groupBy.Properties.ElementAt(0); EndPathToken pathToken = queryToken.ShouldBeEndPathToken("CountryRegion"); pathToken.NextToken.ShouldBeInnerPathToken("Customer"); queryToken = groupBy.Properties.ElementAt(1); pathToken = queryToken.ShouldBeEndPathToken("Name"); pathToken.NextToken.ShouldBeInnerPathToken("Product"); Assert.NotNull(groupBy.Child); AggregateToken aggregate = Assert.IsType <AggregateToken>(groupBy.Child); AggregateExpressionToken aggregateExpressionToken = Assert.Single(aggregate.Expressions); Assert.Equal("Total", aggregateExpressionToken.Alias); Assert.Equal(AggregationMethod.Sum, aggregateExpressionToken.Method); aggregateExpressionToken.Expression.ShouldBeEndPathToken("Amount"); }
private AggregateExpression BindAggregateExpressionToken(AggregateExpressionToken token) { var expression = this.bindMethod(token.Expression) as SingleValueNode; if (expression == null) { throw new ODataException(ODataErrorStrings.ApplyBinder_AggregateExpressionNotSingleValue(token.Expression)); } var typeReference = CreateAggregateExpressionTypeReference(expression, token.Method); // TODO: Determine source return new AggregateExpression(expression, token.Method, token.Alias, typeReference); }
public void NestedAggregateTransformationIsAllowed() { var result = this.ParseExpandOptions("($apply=aggregate(Amount with sum as Total))"); result.Should().NotBeNull(); QueryToken token = result.ApplyOptions.Single(); token.Should().BeOfType <AggregateToken>(); AggregateToken aggregate = token as AggregateToken; AggregateExpressionToken aggregateExpressionToken = aggregate.Expressions.Single(); aggregateExpressionToken.Alias.Should().Equals("Total"); aggregateExpressionToken.Method.Should().Equals(AggregationMethod.Sum); aggregateExpressionToken.Expression.ShouldBeEndPathToken("Amount"); }
public void NestedAggregateTransformationInExpandIsAllowed() { // Arrange & Act ExpandTermToken expandTerm = this.ParseExpandOptions("($apply=aggregate(Amount with sum as Total))"); // Assert Assert.NotNull(expandTerm); Assert.NotNull(expandTerm.ApplyOptions); QueryToken token = Assert.Single(expandTerm.ApplyOptions); AggregateToken aggregate = Assert.IsType <AggregateToken>(token); AggregateExpressionToken aggregateExpressionToken = Assert.Single(aggregate.Expressions); Assert.Equal("Total", aggregateExpressionToken.Alias); Assert.Equal(AggregationMethod.Sum, aggregateExpressionToken.Method); aggregateExpressionToken.Expression.ShouldBeEndPathToken("Amount"); }
public void ParseApplyWithNestedFunctionAggregation() { string apply = "groupby((UnitPrice), aggregate(Sales($count as Count, cast(SalesPrice, Edm.Decimal) with average as RetailPrice)))"; IEnumerable <QueryToken> actual = this.testSubject.ParseApply(apply); actual.Should().NotBeNull(); actual.Should().HaveCount(1); List <QueryToken> transformations = actual.ToList(); // verify groupby GroupByToken groupBy = transformations[0] as GroupByToken; groupBy.Should().NotBeNull(); VerifyGroupByTokenProperties(new string[] { "UnitPrice" }, groupBy); groupBy.Properties.Should().HaveCount(1); groupBy.Child.Should().NotBeNull(); AggregateToken groupByAggregate = groupBy.Child as AggregateToken; groupByAggregate.AggregateExpressions.Should().HaveCount(1); EntitySetAggregateToken entitySetAggregate = groupByAggregate.AggregateExpressions.First() as EntitySetAggregateToken; entitySetAggregate.Should().NotBeNull(); entitySetAggregate.EntitySet.ShouldBeEndPathToken("Sales"); entitySetAggregate.Expressions.Should().HaveCount(2); VerifyAggregateExpressionToken("$count", AggregationMethodDefinition.VirtualPropertyCount, "Count", entitySetAggregate.Expressions.First() as AggregateExpressionToken); AggregateExpressionToken funcAggregate = entitySetAggregate.Expressions.Last() as AggregateExpressionToken; funcAggregate.Should().NotBeNull(); funcAggregate.Alias.ShouldBeEquivalentTo("RetailPrice"); funcAggregate.Method.Should().Equals(AggregationMethodDefinition.Average); FunctionCallToken funcToken = funcAggregate.Expression as FunctionCallToken; funcToken.Should().NotBeNull(); funcToken.Name.ShouldBeEquivalentTo("cast"); }
public void ParseApplyWithNestedAggregationAndFunction() { string apply = "groupby((UnitPrice), aggregate(Sales($count as Count), cast(SalesPrice, Edm.Decimal) with average as RetailPrice))"; IEnumerable <QueryToken> actual = this.testSubject.ParseApply(apply); Assert.NotNull(actual); Assert.Single(actual); List <QueryToken> transformations = actual.ToList(); // verify groupby GroupByToken groupBy = transformations[0] as GroupByToken; Assert.NotNull(groupBy); VerifyGroupByTokenProperties(new string[] { "UnitPrice" }, groupBy); Assert.Single(groupBy.Properties); Assert.NotNull(groupBy.Child); AggregateToken groupByAggregate = groupBy.Child as AggregateToken; Assert.Equal(2, groupByAggregate.AggregateExpressions.Count()); EntitySetAggregateToken entitySetAggregate = groupByAggregate.AggregateExpressions.First() as EntitySetAggregateToken; Assert.NotNull(entitySetAggregate); entitySetAggregate.EntitySet.ShouldBeEndPathToken("Sales"); VerifyAggregateExpressionToken("$count", AggregationMethodDefinition.VirtualPropertyCount, "Count", entitySetAggregate.Expressions.First() as AggregateExpressionToken); AggregateExpressionToken funcAggregate = groupByAggregate.AggregateExpressions.Last() as AggregateExpressionToken; Assert.NotNull(funcAggregate); Assert.Equal("RetailPrice", funcAggregate.Alias); Assert.Equal(AggregationMethod.Average, funcAggregate.Method); FunctionCallToken funcToken = funcAggregate.Expression as FunctionCallToken; Assert.NotNull(funcToken); Assert.Equal("cast", funcToken.Name); }
public void KindIsSetCorrectly() { AggregateExpressionToken token = new AggregateExpressionToken(expressionToken, AggregationMethod.CountDistinct, "Alias"); Assert.Equal(QueryTokenKind.AggregateExpression, token.Kind); }
/// <summary> /// Visits an AggregateExpressionToken /// </summary> /// <param name="tokenIn">The AggregateExpressionToken to visit</param> /// <returns>A T bound to this AggregateExpressionToken</returns> public virtual T Visit(AggregateExpressionToken tokenIn) { throw new NotImplementedException(); }
public void ExpressionSetCorrectly() { var token = new AggregateExpressionToken(expressionToken, AggregationMethod.Sum, "Alias"); token.Expression.Should().Be(expressionToken); }
public bool Visit(AggregateExpressionToken tokenIn) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "QueryToken of type '{0}' is not supported.", tokenIn.Kind)); }
public void KindIsSetCorrectly() { var token = new AggregateExpressionToken(expressionToken, AggregationMethod.CountDistinct, "Alias"); token.Kind.Should().Be(QueryTokenKind.AggregateExpression); }
public void WithVerbSetCorrectly() { var token = new AggregateExpressionToken(expressionToken, AggregationMethod.CountDistinct, "Alias"); token.Method.Should().Be(AggregationMethod.CountDistinct); }
public void AliasSetCorrectly() { var token = new AggregateExpressionToken(expressionToken, AggregationMethod.CountDistinct, "Alias"); token.Alias.Should().BeEquivalentTo("Alias"); }
public void AliasSetCorrectly() { AggregateExpressionToken token = new AggregateExpressionToken(expressionToken, AggregationMethod.CountDistinct, "Alias"); Assert.Equal("Alias", token.Alias); }
private static void VerifyAggregateExpressionToken(string expectedEndPathIdentifier, AggregationMethodDefinition expectedVerb, string expectedAlias, AggregateExpressionToken actual) { actual.Expression.Should().NotBeNull(); EndPathToken expression = actual.Expression as EndPathToken; expression.Should().NotBeNull(); expression.Identifier.Should().Be(expectedEndPathIdentifier); actual.MethodDefinition.MethodLabel.Should().Be(expectedVerb.MethodLabel); actual.MethodDefinition.MethodKind.Should().Be(expectedVerb.MethodKind); actual.Alias.Should().Be(expectedAlias); }
private static void VerifyAggregateExpressionToken(string expectedEndPathIdentifier, AggregationMethodDefinition expectedVerb, string expectedAlias, AggregateExpressionToken actual) { Assert.NotNull(actual.Expression); EndPathToken expression = actual.Expression as EndPathToken; Assert.NotNull(expression); Assert.Equal(expectedEndPathIdentifier, expression.Identifier); Assert.Equal(expectedVerb.MethodLabel, actual.MethodDefinition.MethodLabel); Assert.Equal(expectedVerb.MethodKind, actual.MethodDefinition.MethodKind); Assert.Equal(expectedAlias, actual.Alias); }
public void ExpressionSetCorrectly() { AggregateExpressionToken token = new AggregateExpressionToken(expressionToken, AggregationMethod.Sum, "Alias"); Assert.Same(expressionToken, token.Expression); }