private async Task <SqlObject> IterateReference(MethodContext context, ObjectName refName, IGroupResolver groupResolver)
        {
            SqlObject result = null;

            for (long i = 0; i < groupResolver.Size; i++)
            {
                var rowValue = await groupResolver.ResolveReferenceAsync(refName, i);

                var current = rowValue;

                using (var accumulate = new IterateContext(context, i, result, current)) {
                    await IterateAsync(accumulate);

                    if (accumulate.Result == null)
                    {
                        throw new MethodAccessException("No result value was provided by the iteration");
                    }

                    result = accumulate.Result;

                    if (!accumulate.Iterate)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
        private async Task <SqlObject> IterateValues(MethodContext context, SqlExpression input, IGroupResolver groupResolver)
        {
            SqlObject result = null;

            for (long i = 0; i < groupResolver.Size; i++)
            {
                SqlObject value;
                var       resolver = groupResolver.GetResolver(i);

                using (var reduce = context.Create("reduce", scope => scope.AddReferenceResolver(resolver))) {
                    var reduced = await input.ReduceAsync(reduce);

                    if (reduced.ExpressionType != SqlExpressionType.Constant)
                    {
                        throw new InvalidOperationException();
                    }

                    value = ((SqlConstantExpression)reduced).Value;
                }

                using (var accumulate = new IterateContext(context, i, result, value)) {
                    await IterateAsync(accumulate);

                    if (accumulate.Result == null)
                    {
                        throw new MethodAccessException("No result value was provided by the iteration");
                    }

                    result = accumulate.Result;

                    if (!accumulate.Iterate)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
Esempio n. 3
0
 protected override Task IterateAsync(IterateContext context)
 {
     return(iterate(context));
 }
 protected abstract Task IterateAsync(IterateContext context);