Ejemplo n.º 1
0
 public AccumulatorExpression(Type type, string fieldName, IBsonSerializer serializer, AccumulatorType accumulatorType, Expression argument)
 {
     _type = Ensure.IsNotNull(type, nameof(type));
     _fieldName = Ensure.IsNotNull(fieldName, nameof(fieldName));
     _serializer = Ensure.IsNotNull(serializer, nameof(serializer));
     _accumulatorType = accumulatorType;
     _argument = Ensure.IsNotNull(argument, nameof(argument));
 }
Ejemplo n.º 2
0
 public AccumulatorExpression(Type type, string fieldName, IBsonSerializer serializer, AccumulatorType accumulatorType, Expression argument)
 {
     _type            = Ensure.IsNotNull(type, nameof(type));
     _fieldName       = Ensure.IsNotNull(fieldName, nameof(fieldName));
     _serializer      = Ensure.IsNotNull(serializer, nameof(serializer));
     _accumulatorType = accumulatorType;
     _argument        = Ensure.IsNotNull(argument, nameof(argument));
 }
Ejemplo n.º 3
0
        private bool TryGetAccumulatorType(string methodName, out AccumulatorType accumulatorType)
        {
            switch (methodName)
            {
            case "Average":
                accumulatorType = AccumulatorType.Average;
                return(true);

            case "Count":
            case "LongCount":
            case "Sum":
                accumulatorType = AccumulatorType.Sum;
                return(true);

            case "Distinct":
                accumulatorType = AccumulatorType.AddToSet;
                return(true);

            case "First":
                accumulatorType = AccumulatorType.First;
                return(true);

            case "Last":
                accumulatorType = AccumulatorType.Last;
                return(true);

            case "Max":
                accumulatorType = AccumulatorType.Max;
                return(true);

            case "Min":
                accumulatorType = AccumulatorType.Min;
                return(true);

            case "Select":
            case "ToArray":
            case "ToList":
                accumulatorType = AccumulatorType.Push;
                return(true);
            }

            accumulatorType = 0; // dummy assignment to appease compiler
            return(false);
        }
Ejemplo n.º 4
0
        private bool TryGetAccumulatorTypeAndArgument(PipelineExpression node, out AccumulatorType accumulatorType, out Expression argument)
        {
            if (node.ResultOperator == null)
            {
                var distinct = node.Source as DistinctExpression;
                if (distinct != null)
                {
                    accumulatorType = AccumulatorType.AddToSet;
                    argument        = GetAccumulatorArgument(distinct.Source);
                    return(true);
                }

                accumulatorType = AccumulatorType.Push;
                argument        = GetAccumulatorArgument(node.Source);
                return(true);
            }

            var resultOperator = node.ResultOperator;

            if (resultOperator is AverageResultOperator)
            {
                accumulatorType = AccumulatorType.Average;
                argument        = GetAccumulatorArgument(node.Source);
                return(true);
            }
            if (resultOperator is CountResultOperator)
            {
                accumulatorType = AccumulatorType.Sum;
                argument        = Expression.Constant(1);
                return(true);
            }
            if (resultOperator is FirstResultOperator)
            {
                accumulatorType = AccumulatorType.First;
                argument        = GetAccumulatorArgument(node.Source);
                return(true);
            }
            if (resultOperator is LastResultOperator)
            {
                accumulatorType = AccumulatorType.Last;
                argument        = GetAccumulatorArgument(node.Source);
                return(true);
            }
            if (resultOperator is MaxResultOperator)
            {
                accumulatorType = AccumulatorType.Max;
                argument        = GetAccumulatorArgument(node.Source);
                return(true);
            }
            if (resultOperator is MinResultOperator)
            {
                accumulatorType = AccumulatorType.Min;
                argument        = GetAccumulatorArgument(node.Source);
                return(true);
            }
            if (resultOperator is SumResultOperator)
            {
                accumulatorType = AccumulatorType.Sum;
                argument        = GetAccumulatorArgument(node.Source);
                return(true);
            }
            if (resultOperator is ArrayResultOperator)
            {
                accumulatorType = AccumulatorType.Push;
                argument        = GetAccumulatorArgument(node.Source);
                return(true);
            }
            if (resultOperator is HashSetResultOperator)
            {
                accumulatorType = AccumulatorType.AddToSet;
                argument        = GetAccumulatorArgument(node.Source);
                return(true);
            }
            if (resultOperator is ListResultOperator)
            {
                accumulatorType = AccumulatorType.Push;
                argument        = GetAccumulatorArgument(node.Source);
                return(true);
            }

            accumulatorType = 0;
            argument        = null;
            return(false);
        }
 public AccumulatorExpression(Type type, AccumulatorType accumulatorType, Expression argument)
 {
     _type = Ensure.IsNotNull(type, "type");
     _accumulatorType = accumulatorType;
     _argument = argument;
 }
Ejemplo n.º 6
0
        private bool TryGetAccumulatorTypeAndArgument(PipelineExpression node, out AccumulatorType accumulatorType, out Expression argument)
        {
            if (node.ResultOperator == null)
            {
                var distinct = node.Source as DistinctExpression;
                if (distinct != null)
                {
                    accumulatorType = AccumulatorType.AddToSet;
                    argument = GetAccumulatorArgument(distinct.Source);
                    return true;
                }

                accumulatorType = AccumulatorType.Push;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }

            var resultOperator = node.ResultOperator;
            if (resultOperator is AverageResultOperator)
            {
                accumulatorType = AccumulatorType.Average;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }
            if (resultOperator is CountResultOperator)
            {
                accumulatorType = AccumulatorType.Sum;
                argument = Expression.Constant(1);
                return true;
            }
            if (resultOperator is FirstResultOperator)
            {
                accumulatorType = AccumulatorType.First;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }
            if (resultOperator is LastResultOperator)
            {
                accumulatorType = AccumulatorType.Last;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }
            if (resultOperator is MaxResultOperator)
            {
                accumulatorType = AccumulatorType.Max;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }
            if (resultOperator is MinResultOperator)
            {
                accumulatorType = AccumulatorType.Min;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }
            if (resultOperator is StandardDeviationResultOperator)
            {
                var isSample = ((StandardDeviationResultOperator)resultOperator).IsSample;
                accumulatorType = isSample ? AccumulatorType.StandardDeviationSample : AccumulatorType.StandardDeviationPopulation;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }
            if (resultOperator is SumResultOperator)
            {
                accumulatorType = AccumulatorType.Sum;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }
            if (resultOperator is ArrayResultOperator)
            {
                accumulatorType = AccumulatorType.Push;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }
            if (resultOperator is HashSetResultOperator)
            {
                accumulatorType = AccumulatorType.AddToSet;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }
            if (resultOperator is ListResultOperator)
            {
                accumulatorType = AccumulatorType.Push;
                argument = GetAccumulatorArgument(node.Source);
                return true;
            }

            accumulatorType = 0;
            argument = null;
            return false;
        }
 public AccumulatorExpression(Type type, AccumulatorType accumulatorType, Expression argument)
 {
     _type            = Ensure.IsNotNull(type, "type");
     _accumulatorType = accumulatorType;
     _argument        = argument;
 }
        private bool TryGetAccumulatorType(string methodName, out AccumulatorType accumulatorType)
        {
            switch (methodName)
            {
                case "Average":
                    accumulatorType = AccumulatorType.Average;
                    return true;
                case "Count":
                case "LongCount":
                case "Sum":
                    accumulatorType = AccumulatorType.Sum;
                    return true;
                case "Distinct":
                    accumulatorType = AccumulatorType.AddToSet;
                    return true;
                case "First":
                    accumulatorType = AccumulatorType.First;
                    return true;
                case "Last":
                    accumulatorType = AccumulatorType.Last;
                    return true;
                case "Max":
                    accumulatorType = AccumulatorType.Max;
                    return true;
                case "Min":
                    accumulatorType = AccumulatorType.Min;
                    return true;
                case "Select":
                case "ToArray":
                case "ToList":
                    accumulatorType = AccumulatorType.Push;
                    return true;
            }

            accumulatorType = 0; // dummy assignment to appease compiler
            return false;
        }