Example #1
0
        /// <inheritdoc cref="ResultOperatorBase.ExecuteInMemory" />
        public override StreamedValue ExecuteInMemory <T>(StreamedSequence input)
        {
            var sequence   = input.GetTypedSequence <T>();
            var funcLambda = ReverseResolvingExpressionTreeVisitor.ReverseResolveLambda(input.DataInfo.ItemExpression, Func, 1);
            var func       = (Func <T, T, T>)funcLambda.Compile();
            var result     = sequence.Aggregate(func);

            return(new StreamedValue(result, (StreamedValueInfo)GetOutputDataInfo(input.DataInfo)));
        }
        public void ReverseResolveLambda_InvalidPosition_TooSmall()
        {
            // itemExpression: new AnonymousType<Cook, Cook> ( a = [s1], b = [s2] )
            // resolvedExpression: (x, y) => 0
            // expected result: (x, input, y) => 0

            var parameter1         = Expression.Parameter(typeof(int), "x");
            var parameter2         = Expression.Parameter(typeof(string), "y");
            var resolvedExpression = Expression.Lambda(Expression.Constant(0), parameter1, parameter2);

            ReverseResolvingExpressionTreeVisitor.ReverseResolveLambda(_itemExpression, resolvedExpression, -1);
        }
        public void ReverseResolveLambda()
        {
            // itemExpression: new AnonymousType<Cook, Cook> ( a = [s1], b = [s2] )
            // resolvedExpression: (x, y) => 0
            // expected result: (x, input, y) => 0

            var parameter1         = Expression.Parameter(typeof(int), "x");
            var parameter2         = Expression.Parameter(typeof(string), "y");
            var resolvedExpression = Expression.Lambda(Expression.Constant(0), parameter1, parameter2);

            var lambdaExpression = ReverseResolvingExpressionTreeVisitor.ReverseResolveLambda(_itemExpression, resolvedExpression, 1);

            var expectedExpression = ExpressionHelper.CreateLambdaExpression <int, AnonymousType <Cook, Cook>, string, int> ((x, input, y) => 0);

            ExpressionTreeComparer.CheckAreEqualTrees(expectedExpression, lambdaExpression);
        }
        /// <summary>
        /// Executes the aggregating operation in memory.
        /// </summary>
        /// <typeparam name="TInput">The type of the source items.</typeparam>
        /// <typeparam name="TAggregate">The type of the aggregated items.</typeparam>
        /// <typeparam name="TResult">The type of the result items.</typeparam>
        /// <param name="input">The input sequence.</param>
        /// <returns>A <see cref="StreamedValue"/> object holding the aggregated value.</returns>
        public StreamedValue ExecuteAggregateInMemory <TInput, TAggregate, TResult>(StreamedSequence input)
        {
            var sequence   = input.GetTypedSequence <TInput>();
            var seed       = GetConstantSeed <TAggregate>();
            var funcLambda = ReverseResolvingExpressionTreeVisitor.ReverseResolveLambda(input.DataInfo.ItemExpression, Func, 1);
            var func       = (Func <TAggregate, TInput, TAggregate>)funcLambda.Compile();

            var aggregated     = sequence.Aggregate(seed, func);
            var outputDataInfo = (StreamedValueInfo)GetOutputDataInfo(input.DataInfo);

            if (OptionalResultSelector == null)
            {
                return(new StreamedValue(aggregated, outputDataInfo));
            }
            else
            {
                var resultSelector = (Func <TAggregate, TResult>)OptionalResultSelector.Compile();
                var result         = resultSelector(aggregated);
                return(new StreamedValue(result, outputDataInfo));
            }
        }