public AggregateStatementToken(QueryToken expression, AggregationVerb withVerb, string alias) { ExceptionUtils.CheckArgumentNotNull(expression, "expression"); ExceptionUtils.CheckArgumentNotNull(alias, "alias"); this.expression = expression; this.withVerb = withVerb; this.alias = alias; }
/// <summary> /// Create a AggregateStatement. /// </summary> /// <param name="expression">The aggregation expression.</param> /// <param name="withVerb">The <see cref="AggregationVerb"/>.</param> /// <param name="from">The aggregation from <see cref="SingleValuePropertyAccessNode"/>.</param> /// <param name="alias">The aggregation alias.</param> /// <param name="typeReference">The <see cref="IEdmTypeReference"/> of this aggregate statement.</param> public AggregateStatement(SingleValueNode expression, AggregationVerb withVerb, SingleValuePropertyAccessNode from, string alias, IEdmTypeReference typeReference) { ExceptionUtils.CheckArgumentNotNull(expression, "expression"); ExceptionUtils.CheckArgumentNotNull(alias, "alias"); ExceptionUtils.CheckArgumentNotNull(typeReference, "typeReference"); this.expression = expression; this.withVerb = withVerb; this.from = from; this.alias = alias; this.typeReference = typeReference; }
private IEdmTypeReference CreateAggregateStatementTypeReference(SingleValueNode expression, AggregationVerb withVerb) { var expressionType = expression.TypeReference; if (expressionType == null && aggregateStatementsCache != null) { var openProperty = expression as SingleValueOpenPropertyAccessNode; if (openProperty != null) { expressionType = GetTypeReferenceByPropertyName(openProperty.Name); } } switch (withVerb) { case AggregationVerb.Average: var expressionPrimitiveKind = expressionType.PrimitiveKind(); switch (expressionPrimitiveKind) { case EdmPrimitiveTypeKind.Int32: case EdmPrimitiveTypeKind.Int64: case EdmPrimitiveTypeKind.Double: return EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, expressionType.IsNullable); case EdmPrimitiveTypeKind.Decimal: return EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Decimal, expressionType.IsNullable); default: throw new ODataException( ODataErrorStrings.ApplyBinder_AggregateStatementIncompatibleTypeForVerb(expression, expressionPrimitiveKind)); } case AggregationVerb.CountDistinct: return EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int64, false); case AggregationVerb.Max: case AggregationVerb.Min: case AggregationVerb.Sum: return expressionType; default: throw new ODataException(ODataErrorStrings.ApplyBinder_UnsupportedAggregateVerb(withVerb)); } }
private static void VerifyAggregateStatementToken(string expectedEndPathIdentifier, AggregationVerb expectedVerb, string expectedAlias, AggregateStatementToken actual) { actual.Expression.Should().NotBeNull(); var expression = actual.Expression as EndPathToken; expression.Should().NotBeNull(); expression.Identifier.Should().Be(expectedEndPathIdentifier); actual.WithVerb.Should().Be(expectedVerb); actual.AsAlias.Should().Be(expectedAlias); }
private IEdmTypeReference CreateAggregateStatementTypeReference(SingleValueNode expression, AggregationVerb withVerb) { var expressionType = expression.TypeReference; if (expressionType == null && aggregateStatementsCache != null) { var openProperty = expression as SingleValueOpenPropertyAccessNode; if (openProperty != null) { expressionType = GetTypeReferenceByPropertyName(openProperty.Name); } } switch (withVerb) { case AggregationVerb.Average: var expressionPrimitiveKind = expressionType.PrimitiveKind(); switch (expressionPrimitiveKind) { case EdmPrimitiveTypeKind.Int32: case EdmPrimitiveTypeKind.Int64: case EdmPrimitiveTypeKind.Double: return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, expressionType.IsNullable)); case EdmPrimitiveTypeKind.Decimal: return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Decimal, expressionType.IsNullable)); default: throw new ODataException( ODataErrorStrings.ApplyBinder_AggregateStatementIncompatibleTypeForVerb(expression, expressionPrimitiveKind)); } case AggregationVerb.CountDistinct: return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int64, false)); case AggregationVerb.Max: case AggregationVerb.Min: case AggregationVerb.Sum: return(expressionType); default: throw new ODataException(ODataErrorStrings.ApplyBinder_UnsupportedAggregateVerb(withVerb)); } }