Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        /// <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;
        }
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 4
0
        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));
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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));
            }
        }