Esempio n. 1
0
        public void Iterators_StreamAggregate_ComputeAggregates_WhenNotGrouped()
        {
            var rows     = new object[] { 1, 2, 3 };
            var expected = new object[, ]
            {
                { 3, 1 }
            };

            using (var input = new MockedIterator(rows))
            {
                var groupEntries = Enumerable.Empty <RowBufferEntry>();
                var comparers    = ImmutableArray <IComparer> .Empty;
                var aggregators  = new []
                {
                    new MaxAggregateDefinition().CreateAggregatable(typeof(int)).CreateAggregator(),
                    new MinAggregateDefinition().CreateAggregatable(typeof(int)).CreateAggregator()
                };

                var function = new IteratorFunction(() => input.RowBuffer[0]);

                var argumentFunctions = new[] { function, function };

                using (var iterator = new StreamAggregateIterator(input, groupEntries, comparers, aggregators, argumentFunctions))
                {
                    AssertProduces(iterator, expected);
                }
            }
        }
        public void Iterators_ComputeScalar_ComputesValues()
        {
            var rows = new object[]
            {
                4, 6, 8
            };

            var expected = new object[, ]
            {
                { 4, 12 },
                { 6, 18 },
                { 8, 24 }
            };

            using (var input = new MockedIterator(rows))
            {
                var values = new IteratorFunction[]
                {
                    () => (int)input.RowBuffer[0] * 3
                };

                using (var iterator = new ComputeScalarIterator(input, values))
                {
                    AssertProduces(iterator, expected);
                }
            }
        }
        public void Iterators_ComputeScalar_ReturnsEmpty_IfInputIsEmpty()
        {
            var rows   = new object[0];
            var values = new IteratorFunction[]
            {
                () => 1
            };

            using (var input = new MockedIterator(rows))
                using (var iterator = new ComputeScalarIterator(input, values))
                {
                    AssertEmpty(iterator);
                }
        }
Esempio n. 4
0
        /// <summary>
        /// Executes a function for every Property in this Configuration.
        /// </summary>
        /// <param name="func">The function to execute.</param>
        private void ForEach(IteratorFunction func)
        {
            // Check if the function does anything at all
            if (func == null || func.GetInvocationList().Length == 0)
            {
                return;
            }

            // Iterate over all properties
            foreach (Property p in properties)
            {
                func.Invoke(p.key, p.value);
            }
        }
Esempio n. 5
0
        public void Iterators_StreamAggregate_ComputeAggregates_WhenGrouped()
        {
            var rows = new object[, ]
            {
                { "One", 1 },
                { "One", 2 },
                { "Two", 3 }
            };

            var expected = new object[, ]
            {
                { "One", 2, 1 },
                { "Two", 3, 3 }
            };

            using (var input = new MockedIterator(rows))
            {
                var groupEntries = new []
                {
                    new RowBufferEntry(input.RowBuffer, 0)
                };
                var comparers   = ImmutableArray.Create <IComparer>(Comparer.Default);
                var aggregators = new []
                {
                    new MaxAggregateDefinition().CreateAggregatable(typeof(int)).CreateAggregator(),
                    new MinAggregateDefinition().CreateAggregatable(typeof(int)).CreateAggregator()
                };

                var function = new IteratorFunction(() => input.RowBuffer[1]);

                var argumentFunctions = new[] { function, function };

                using (var iterator = new StreamAggregateIterator(input, groupEntries, comparers, aggregators, argumentFunctions))
                {
                    AssertProduces(iterator, expected);
                }
            }
        }