Пример #1
0
        public override AlgebraNode VisitAggregateAlgebraNode(AggregateAlgebraNode node)
        {
            node.Input = VisitAlgebraNode(node.Input);

            if (node.Input is NullScanAlgebraNode)
            {
                if (node.Groups != null && node.Groups.Length > 0)
                {
                    // Grouped queries return nothing on empty input.
                    return(CreateNullScan(node.OutputList));
                }
                else
                {
                    // Non-grouped aggregation. We return the result value of the aggregates
                    // executed against an empty input as a single row.

                    List <RowBufferEntry>          outputList     = new List <RowBufferEntry>();
                    List <ComputedValueDefinition> emptyValueList = new List <ComputedValueDefinition>();
                    foreach (AggregatedValueDefinition definedValue in node.DefinedValues)
                    {
                        IAggregator aggregator = definedValue.Aggregator;
                        aggregator.Init();
                        object emptyValue = aggregator.Terminate();

                        ComputedValueDefinition computedBufferedValue = new ComputedValueDefinition();
                        computedBufferedValue.Target     = definedValue.Target;
                        computedBufferedValue.Expression = LiteralExpression.FromTypedValue(emptyValue, aggregator.ReturnType);
                        emptyValueList.Add(computedBufferedValue);
                        outputList.Add(computedBufferedValue.Target);
                    }

                    ConstantScanAlgebraNode constantScanAlgebraNode = new ConstantScanAlgebraNode();
                    constantScanAlgebraNode.DefinedValues = emptyValueList.ToArray();
                    constantScanAlgebraNode.OutputList    = outputList.ToArray();
                    return(constantScanAlgebraNode);
                }
            }

            return(node);
        }
Пример #2
0
 public void Init()
 {
     _sumAggregator.Init();
     _count = 0;
 }