private AggregationMethodDefinition ParseAggregateWith() { if (!TokenIdentifierIs(ExpressionConstants.KeywordWith)) { throw ParseError(ODataErrorStrings.UriQueryExpressionParser_WithExpected(this.lexer.CurrentToken.Position, this.lexer.ExpressionText)); } lexer.NextToken(); AggregationMethodDefinition verb; int identifierStartPosition = lexer.CurrentToken.Position; string methodLabel = lexer.ReadDottedIdentifier(false /* acceptStar */); switch (methodLabel) { case ExpressionConstants.KeywordAverage: verb = AggregationMethodDefinition.Average; break; case ExpressionConstants.KeywordCountDistinct: verb = AggregationMethodDefinition.CountDistinct; break; case ExpressionConstants.KeywordMax: verb = AggregationMethodDefinition.Max; break; case ExpressionConstants.KeywordMin: verb = AggregationMethodDefinition.Min; break; case ExpressionConstants.KeywordSum: verb = AggregationMethodDefinition.Sum; break; default: if (!methodLabel.Contains(OData.ExpressionConstants.SymbolDot)) { throw ParseError( ODataErrorStrings.UriQueryExpressionParser_UnrecognizedWithMethod( methodLabel, identifierStartPosition, this.lexer.ExpressionText)); } verb = AggregationMethodDefinition.Custom(methodLabel); break; } return(verb); }
public void ParseApplyWithDottedUnkownExpressionShouldReturnCustomAggregateToken() { string apply = "aggregate(UnitPrice with Custom.Aggregate as CustomAggregate)"; IEnumerable <QueryToken> actual = this.testSubject.ParseApply(apply); actual.Should().NotBeNull(); actual.Should().HaveCount(1); AggregateToken aggregate = actual.First() as AggregateToken; aggregate.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); VerifyAggregateExpressionToken("UnitPrice", AggregationMethodDefinition.Custom("Custom.Aggregate"), "CustomAggregate", aggregate.AggregateExpressions.First() as AggregateExpressionToken); }
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); }
/// <summary> /// Create an AggregateExpressionToken. /// </summary> /// <param name="expression">The aggregate expression.</param> /// <param name="methodDefinition">The aggregate method definition.</param> /// <param name="alias">The alias for this query token.</param> public AggregateExpressionToken(QueryToken expression, AggregationMethodDefinition methodDefinition, string alias) : this(expression, methodDefinition.MethodKind, alias) { this.methodDefinition = methodDefinition; }