public void Iterators_Projection_ForwardsProperly()
        {
            var rows     = new object[] { 1, 2 };
            var expected = rows;

            using (var input = new MockedIterator(rows))
            {
                var entries = new[]
                {
                    new RowBufferEntry(input.RowBuffer, 0)
                };

                using (var iterator = new ProjectionIterator(input, entries))
                {
                    for (var i = 0; i < 2; i++)
                    {
                        AssertProduces(iterator, expected);
                    }
                }

                Assert.Equal(2, input.TotalOpenCount);
                Assert.Equal(4, input.TotalReadCount);
                Assert.Equal(1, input.DisposalCount);
            }
        }
Example #2
0
        public void Iterators_InnerNestedLoops_ForwardsProperly()
        {
            var leftRows  = new object[] { 1, 2 };
            var rightRows = new object[] { 3, 4, 5 };
            var expected  = new object[, ]
            {
                { 1, 3 },
                { 1, 4 },
                { 1, 5 },
                { 2, 3 },
                { 2, 4 },
                { 2, 5 }
            };

            using (var left = new MockedIterator(leftRows))
                using (var right = new MockedIterator(rightRows))
                {
                    using (var iterator = new InnerNestedLoopsIterator(left, right, () => true, () => false))
                    {
                        for (var i = 0; i < 2; i++)
                        {
                            AssertProduces(iterator, expected);
                        }
                    }

                    Assert.Equal(2, left.TotalOpenCount);
                    Assert.Equal(4, left.TotalReadCount);
                    Assert.Equal(1, left.DisposalCount);

                    Assert.Equal(4, right.TotalOpenCount);
                    Assert.Equal(12, right.TotalReadCount);
                    Assert.Equal(1, right.DisposalCount);
                }
        }
Example #3
0
        public void Iterators_ProbingLeftSemiNestedLoops_MatchesRows()
        {
            var leftRows = new object[, ]
            {
                { 1, "1-Left" },
                { 2, "2-Left-A" },
                { 2, "2-Left-B" },
                { 3, "3-Left" },
                { 4, "4-Left" },
                { 5, "5-Left" }
            };

            var rightRows = new object[] { 2, 3, 3, 5 };

            var expected = new object[, ]
            {
                { 1, "1-Left", false },
                { 2, "2-Left-A", true },
                { 2, "2-Left-B", true },
                { 3, "3-Left", true },
                { 4, "4-Left", false },
                { 5, "5-Left", true }
            };

            using (var left = new MockedIterator(leftRows))
                using (var right = new MockedIterator(rightRows))
                {
                    var iteratorPredicate = new IteratorPredicate(() => Equals(left.RowBuffer[0], right.RowBuffer[0]));

                    using (var iterator = new ProbingLeftSemiNestedLoopsIterator(left, right, iteratorPredicate))
                    {
                        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);
                }
            }
        }
Example #5
0
        public void Iterators_TableSpool_ReturnsInput_AndPushes()
        {
            var rows = new object[, ]
            {
                { 1, "One" },
                { 2, "Two" }
            };

            var expected = rows;

            var tableSpoolStack = new TableSpoolStack(1);

            using (var input = new MockedIterator(rows))
                using (var iterator = new TableSpoolIterator(input, tableSpoolStack))
                {
                    AssertProduces(iterator, expected);

                    var stackRows = new List <RowBuffer>();
                    while (!tableSpoolStack.IsEmpty)
                    {
                        stackRows.Add(tableSpoolStack.Pop());
                    }

                    for (var i = 0; i < rows.GetLength(0); i++)
                    {
                        var originalLine = rows.GetLength(0) - i - 1;
                        for (var j = 0; j < rows.GetLength(1); j++)
                        {
                            Assert.Equal(rows[originalLine, j], stackRows[i][j]);
                        }
                    }
                }
        }
        internal void Iterators_HashMatch_MatchesDuplicates(BoundHashMatchOperator logicalOperator)
        {
            var buildRows = new object[] { 1, 2, 3 };
            var probeRows = new object[, ]
            {
                { 1, "First" },
                { 2, "Second1" },
                { 2, "Second2" },
                { 3, "Third" }
            };
            var expected = new object[, ]
            {
                { 1, 1, "First" },
                { 2, 2, "Second1" },
                { 2, 2, "Second2" },
                { 3, 3, "Third" }
            };

            using (var build = new MockedIterator(buildRows))
                using (var probe = new MockedIterator(probeRows))
                {
                    var rowBuffer = new HashMatchRowBuffer(build.RowBuffer.Count, probe.RowBuffer.Count);
                    var remainder = new IteratorPredicate(() => true);

                    using (var iterator = new HashMatchIterator(logicalOperator, build, probe, 0, 0, remainder, rowBuffer))
                    {
                        AssertProduces(iterator, expected);
                    }
                }
        }
Example #7
0
        public void Iterators_LeftAntiSemiNestedLoops_ForwardsProperly()
        {
            var leftRows  = new object[] { 1, 2 };
            var rightRows = new object[] { 3, 4 };

            using (var left = new MockedIterator(leftRows))
                using (var right = new MockedIterator(rightRows))
                {
                    using (var iterator = new LeftAntiSemiNestedLoopsIterator(left, right, () => true, () => false))
                    {
                        for (var i = 0; i < 2; i++)
                        {
                            AssertEmpty(iterator);
                        }
                    }

                    Assert.Equal(2, left.TotalOpenCount);
                    Assert.Equal(4, left.TotalReadCount);
                    Assert.Equal(1, left.DisposalCount);

                    Assert.Equal(4, right.TotalOpenCount);
                    Assert.Equal(4, right.TotalReadCount);
                    Assert.Equal(1, right.DisposalCount);
                }
        }
Example #8
0
        public void Iterators_LeftAntiSemiNestedLoops_NoReadsOnRight_WhenPassthruIsTrue()
        {
            var leftRows  = new object[] { 1, 2, 3, 4, 5 };
            var rightRows = new object[] { 1, 2, 3 };
            var expected  = new object[] { 2, 4, 5 };

            using (var left = new MockedIterator(leftRows))
                using (var right = new MockedIterator(rightRows))
                {
                    var iteratorPredicate = new IteratorPredicate(() => Equals(left.RowBuffer[0], right.RowBuffer[0]));
                    var passthru          = new IteratorPredicate(() => (int)left.RowBuffer[0] % 2 == 0);

                    using (var iterator = new LeftAntiSemiNestedLoopsIterator(left, right, iteratorPredicate, passthru))
                    {
                        AssertProduces(iterator, expected);
                    }

                    Assert.Equal(1, left.TotalOpenCount);
                    Assert.Equal(5, left.TotalReadCount);
                    Assert.Equal(1, left.DisposalCount);

                    Assert.Equal(3, right.TotalOpenCount);
                    Assert.Equal(7, right.TotalReadCount);
                    Assert.Equal(1, right.DisposalCount);
                }
        }
Example #9
0
        public void Iterators_StreamAggregate_ForwardsProperly()
        {
            var rows     = new object[] { 1, 2 };
            var expected = new object[1, 0];

            using (var input = new MockedIterator(rows))
            {
                var groupEntries      = Enumerable.Empty <RowBufferEntry>();
                var comparers         = ImmutableArray <IComparer> .Empty;
                var aggregators       = Enumerable.Empty <IAggregator>();
                var argumentFunctions = Enumerable.Empty <IteratorFunction>();

                using (var iterator = new StreamAggregateIterator(input, groupEntries, comparers, aggregators, argumentFunctions))
                {
                    for (var i = 0; i < 2; i++)
                    {
                        AssertProduces(iterator, expected);
                    }
                }

                Assert.Equal(2, input.TotalOpenCount);
                Assert.Equal(4, input.TotalReadCount);
                Assert.Equal(1, input.DisposalCount);
            }
        }
Example #10
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);
                }
            }
        }
Example #11
0
        public void Iterators_Sort_Sorts_WithOuterEntries()
        {
            var rows     = new object[] { null, 1, 2, 1 };
            var expected = new object[] { null, 1, 1, 2 };

            var outerRowBuffer = new MockedRowBuffer(new object[] { "Outer Reference" });

            using (var input = new MockedIterator(rows))
            {
                var sortEntries = new[]
                {
                    new RowBufferEntry(outerRowBuffer, 0),
                    new RowBufferEntry(input.RowBuffer, 0)
                };

                var comparers = new[]
                {
                    Comparer.Default,
                    Comparer.Default
                };

                using (var iterator = new SortIterator(input, sortEntries, comparers))
                {
                    AssertProduces(iterator, expected);
                }
            }
        }
        public void Iterators_Projection_SwapsEntries()
        {
            var rows = new object[, ]
            {
                { 1, "One" },
                { 2, "Two" }
            };

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

            using (var input = new MockedIterator(rows))
            {
                var entries = new[]
                {
                    new RowBufferEntry(input.RowBuffer, 1),
                    new RowBufferEntry(input.RowBuffer, 0)
                };

                using (var iterator = new ProjectionIterator(input, entries))
                {
                    AssertProduces(iterator, expected);
                }
            }
        }
        public void Iterators_Projection_ReturnsEmpty_IfInputEmpty()
        {
            var rows = new object[0];

            using (var input = new MockedIterator(rows))
                using (var iterator = new ProjectionIterator(input, Enumerable.Empty <RowBufferEntry>()))
                {
                    AssertEmpty(iterator);
                }
        }
Example #14
0
        public void Iterators_Filter_ReturnsEmpty_IfInputIsEmpty()
        {
            var rows = new object[0];

            using (var input = new MockedIterator(rows))
                using (var iterator = new FilterIterator(input, () => true))
                {
                    AssertEmpty(iterator);
                }
        }
        public void Iterators_TopWithTies_ReturnsEmpty_IfLimitIsZero()
        {
            var rows = new object[] { 1 };

            using (var input = new MockedIterator(rows))
                using (var iterator = CreateIterator(input, 0))
                {
                    AssertEmpty(iterator);
                }
        }
        public void Iterators_TopWithTies_ReturnsEmpty_IfInputIsEmpty()
        {
            var rows = new object[0];

            using (var input = new MockedIterator(rows))
                using (var iterator = CreateIterator(input, 1))
                {
                    AssertEmpty(iterator);
                }
        }
Example #17
0
        public void Iterators_Assert_DoesNotTriggerAssert_WhenFalseAndInputEmpty()
        {
            var rows     = new object[0];
            var expected = rows;

            using (var input = new MockedIterator(rows))
                using (var iterator = new AssertIterator(input, () => false, string.Empty))
                {
                    AssertProduces(iterator, expected);
                }
        }
Example #18
0
        public void Iterators_Assert_DoesNotTriggerAssert_WhenTrue()
        {
            var rows     = new object[] { 1 };
            var expected = rows;

            using (var input = new MockedIterator(rows))
                using (var iterator = new AssertIterator(input, () => true, string.Empty))
                {
                    AssertProduces(iterator, expected);
                }
        }
Example #19
0
        public void Iterators_Filter_Filters()
        {
            var rows     = new object[] { 1, 2, 3, 4 };
            var expected = new object[] { 2, 4 };

            using (var input = new MockedIterator(rows))
                using (var iterator = new FilterIterator(input, () => (int)input.RowBuffer[0] % 2 == 0))
                {
                    AssertProduces(iterator, expected);
                }
        }
        public void Iterators_TopWithTies_ReturnsAllRows_IfLimitIsLarger()
        {
            var rows     = new object[] { 1, 2, 3 };
            var expected = rows;
            var limit    = expected.Length + 1;

            using (var input = new MockedIterator(rows))
                using (var iterator = CreateIterator(input, limit))
                {
                    AssertProduces(iterator, expected);
                }
        }
        public void Iterators_TopWithTies_LimitsRows_AndBreaksTies()
        {
            var       rows     = new object[] { 1, 2, 3, 3, 4 };
            var       expected = new object[] { 1, 2, 3, 3 };
            const int limit    = 3;

            using (var input = new MockedIterator(rows))
                using (var iterator = CreateIterator(input, limit))
                {
                    AssertProduces(iterator, expected);
                }
        }
        internal void Iterators_HashMatch_ForwardsProperly(BoundHashMatchOperator logicalOperator)
        {
            var buildRows = new object[] { 1, 2 };
            var probeRows = new object[] { 2, 3 };

            using (var build = new MockedIterator(buildRows))
                using (var probe = new MockedIterator(probeRows))
                {
                    const int passCount = 2;

                    var rowBuffer = new HashMatchRowBuffer(build.RowBuffer.Count, probe.RowBuffer.Count);
                    var remainder = new IteratorPredicate(() => true);

                    using (var iterator = new HashMatchIterator(logicalOperator, build, probe, 0, 0, remainder, rowBuffer))
                    {
                        for (var i = 0; i < passCount; i++)
                        {
                            iterator.Open();

                            Assert.True(iterator.Read());
                            Assert.Equal(2, iterator.RowBuffer[0]);
                            Assert.Equal(2, iterator.RowBuffer[1]);

                            if (logicalOperator == BoundHashMatchOperator.RightOuter ||
                                logicalOperator == BoundHashMatchOperator.FullOuter)
                            {
                                Assert.True(iterator.Read());
                                Assert.Equal(null, iterator.RowBuffer[0]);
                                Assert.Equal(3, iterator.RowBuffer[1]);
                            }

                            if (logicalOperator == BoundHashMatchOperator.LeftOuter ||
                                logicalOperator == BoundHashMatchOperator.FullOuter)
                            {
                                Assert.True(iterator.Read());
                                Assert.Equal(1, iterator.RowBuffer[0]);
                                Assert.Equal(null, iterator.RowBuffer[1]);
                            }

                            Assert.False(iterator.Read());
                        }
                    }

                    var inputs = new[] { build, probe };

                    foreach (var input in inputs)
                    {
                        Assert.Equal(passCount, input.TotalOpenCount);
                        Assert.Equal(passCount * 2, input.TotalReadCount);
                        Assert.Equal(1, input.DisposalCount);
                    }
                }
        }
Example #23
0
        public void Iterators_TableSpool_ReturnsEmpty_IfInputEmpty()
        {
            var rows            = new object[0];
            var tableSpoolStack = new TableSpoolStack(1);

            using (var input = new MockedIterator(rows))
                using (var iterator = new TableSpoolIterator(input, tableSpoolStack))
                {
                    AssertEmpty(iterator);
                    Assert.True(tableSpoolStack.IsEmpty);
                }
        }
        public void Iterators_TopWithTies_LimitsRows_WhenNoTies()
        {
            var rows     = new object[] { 1, 2, 3 };
            var expected = new object[] { 1, 2 };
            var limit    = expected.Length;

            using (var input = new MockedIterator(rows))
                using (var iterator = CreateIterator(input, limit))
                {
                    AssertProduces(iterator, expected);
                }
        }
Example #25
0
        public void Iterators_Sort_Sorts_TwoEntries()
        {
            var rows = new object[, ]
            {
                { "Kirkland", "USA" },
                { "London", "UK" },
                { "London", null },
                { "Redmond", "USA" },
                { "Seattle", "USA" },
                { "London", "UK" },
                { "Seattle", "USA" },
                { "Tacoma", "USA" },
                { "London", "UK" },
                { null, "USA" },
                { null, null }
            };

            var expected = new object[, ]
            {
                { null, null },
                { "London", null },
                { null, "USA" },
                { "Kirkland", "USA" },
                { "Redmond", "USA" },
                { "Seattle", "USA" },
                { "Seattle", "USA" },
                { "Tacoma", "USA" },
                { "London", "UK" },
                { "London", "UK" },
                { "London", "UK" }
            };

            using (var input = new MockedIterator(rows))
            {
                var sortEntries = new[]
                {
                    new RowBufferEntry(input.RowBuffer, 1),
                    new RowBufferEntry(input.RowBuffer, 0)
                };

                var comparers = new[]
                {
                    Comparer <string> .Create((x, y) => y.CompareTo(x)),
                    Comparer <string> .Create((x, y) => x.CompareTo(y))
                };

                using (var iterator = new SortIterator(input, sortEntries, comparers))
                {
                    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);
                }
        }
Example #27
0
        public void Iterators_Assert_TriggersAssert_WhenFalseAndInputNonEmpty()
        {
            const string message = "This should be detected";

            var rows = new object[] { 1 };

            using (var input = new MockedIterator(rows))
                using (var iterator = new AssertIterator(input, () => false, message))
                {
                    iterator.Open();

                    var exception = Assert.Throws <InvalidOperationException>(() => iterator.Read());
                    Assert.Equal(exception.Message, message);
                }
        }
Example #28
0
        public void Iterators_Sort_ReturnsEmpty_IfInputIsEmpty()
        {
            var rows = new object[0];

            using (var input = new MockedIterator(rows))
            {
                var sortEntries = new[] { new RowBufferEntry(input.RowBuffer, 0) };
                var comparers   = new[] { Comparer.Default };

                using (var iterator = new SortIterator(input, sortEntries, comparers))
                {
                    AssertEmpty(iterator);
                }
            }
        }
Example #29
0
        public void Iterators_ProbingLeftSemiNestedLoops_ReturnsEmpty_WhenLeftIsEmpty()
        {
            var leftRows  = new object[0];
            var rightRows = new object[0];

            using (var left = new MockedIterator(leftRows))
                using (var right = new MockedIterator(rightRows))
                {
                    var iteratorPredicate = new IteratorPredicate(() => true);

                    using (var iterator = new ProbingLeftSemiNestedLoopsIterator(left, right, iteratorPredicate))
                    {
                        AssertEmpty(iterator);
                    }
                }
        }
Example #30
0
        public void Iterators_StreamAggregate_ReturnsEmpty_IfInputEmptyAndGrouped()
        {
            var rows = new object[0];

            using (var input = new MockedIterator(rows))
            {
                var groupEntries      = new [] { new RowBufferEntry(input.RowBuffer, 0) };
                var comparers         = ImmutableArray.Create <IComparer>(Comparer.Default);
                var aggregators       = Enumerable.Empty <IAggregator>();
                var argumentFunctions = Enumerable.Empty <IteratorFunction>();

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