PageRenderTime 566ms CodeModel.GetById 161ms app.highlight 14ms RepoModel.GetById 267ms app.codeStats 1ms

/Rhino.Etl.Tests/Joins/JoinFixture.cs

http://github.com/ayende/rhino-etl
C# | 208 lines | 176 code | 32 blank | 0 comment | 0 complexity | 12a12fe8abc8c188dffadd406db46bed MD5 | raw file
  1namespace Rhino.Etl.Tests.Joins
  2{
  3    using System.Collections.Generic;
  4    using Core;
  5    using Xunit;
  6    using Rhino.Etl.Core.Pipelines;
  7
  8    
  9    public class JoinFixture : BaseJoinFixture
 10    {
 11      
 12        [Fact]
 13        public void InnerJoin()
 14        {
 15            using (InnerJoinUsersToPeopleByEmail join = new InnerJoinUsersToPeopleByEmail())
 16            {
 17                join.Left(new GenericEnumerableOperation(left))
 18                    .Right(new GenericEnumerableOperation(right));
 19                join.PrepareForExecution(new SingleThreadedPipelineExecuter());
 20                IEnumerable<Row> result = join.Execute(null);
 21                List<Row> items = new List<Row>(result);
 22
 23                Assert.Equal(1, items.Count);
 24                Assert.Equal(3, items[0]["person_id"]);
 25            }
 26        }
 27
 28        [Fact]
 29        public void RightJoin()
 30        {
 31            using (RightJoinUsersToPeopleByEmail join = new RightJoinUsersToPeopleByEmail())
 32            {
 33                join.Left(new GenericEnumerableOperation(left))
 34                    .Right(new GenericEnumerableOperation(right));
 35                join.PrepareForExecution(new SingleThreadedPipelineExecuter());
 36                IEnumerable<Row> result = join.Execute(null);
 37                List<Row> items = new List<Row>(result);
 38
 39                Assert.Equal(2, items.Count);
 40                Assert.Equal(3, items[0]["person_id"]);
 41                Assert.Null(items[1]["name"]);
 42                Assert.Equal(5, items[1]["person_id"]);
 43            }
 44        }
 45
 46        [Fact]
 47        public void LeftJoin()
 48        {
 49            using (LeftJoinUsersToPeopleByEmail join = new LeftJoinUsersToPeopleByEmail())
 50            {
 51                join.Left(new GenericEnumerableOperation(left))
 52                    .Right(new GenericEnumerableOperation(right));
 53                join.PrepareForExecution(new SingleThreadedPipelineExecuter());
 54                IEnumerable<Row> result = join.Execute(null);
 55                List<Row> items = new List<Row>(result);
 56
 57                Assert.Equal(2, items.Count);
 58                Assert.Equal(3, items[0]["person_id"]);
 59                Assert.Null(items[1]["person_id"]);
 60                Assert.Equal("bar", items[1]["name"]);
 61            }
 62        }
 63
 64        [Fact]
 65        public void FullJoin()
 66        {
 67            using (FullJoinUsersToPeopleByEmail join = new FullJoinUsersToPeopleByEmail())
 68            {
 69                join.Left(new GenericEnumerableOperation(left))
 70                    .Right(new GenericEnumerableOperation(right));
 71                join.PrepareForExecution(new SingleThreadedPipelineExecuter());
 72                IEnumerable<Row> result = join.Execute(null);
 73                List<Row> items = new List<Row>(result);
 74
 75                Assert.Equal(3, items.Count);
 76
 77                Assert.Equal(3, items[0]["person_id"]);
 78
 79                Assert.Null(items[1]["person_id"]);
 80                Assert.Equal("bar", items[1]["name"]);
 81
 82                Assert.Null(items[2]["name"]);
 83                Assert.Equal(5, items[2]["person_id"]);
 84            }
 85        }
 86
 87        [Fact]
 88        public void SortMergeInnerJoin()
 89        {
 90            using (InnerMergeJoinUsersToPeopleByEmail join = new InnerMergeJoinUsersToPeopleByEmail())
 91            {
 92                join.Left(new GenericEnumerableOperation(left))
 93                    .Right(new GenericEnumerableOperation(right));
 94                join.PrepareForExecution(new SingleThreadedPipelineExecuter());
 95                IEnumerable<Row> result = join.Execute(null);
 96                List<Row> items = new List<Row>(result);
 97
 98                Assert.Equal(1, items.Count);
 99                Assert.Equal(3, items[0]["person_id"]);
100            }
101        }
102
103        [Fact]
104        public void SortMergeLeftJoin()
105        {
106            using (LeftMergeJoinUsersToPeopleByEmail join = new LeftMergeJoinUsersToPeopleByEmail())
107            {
108                join.Left(new GenericEnumerableOperation(left))
109                    .Right(new GenericEnumerableOperation(right));
110                join.PrepareForExecution(new SingleThreadedPipelineExecuter());
111                IEnumerable<Row> result = join.Execute(null);
112                List<Row> items = new List<Row>(result);
113
114                Assert.Equal(2, items.Count);
115                Assert.Equal(3, items[0]["person_id"]);
116                Assert.Null(items[1]["person_id"]);
117                Assert.Equal("bar", items[1]["name"]);
118            }
119        }
120
121        [Fact]
122        public void SortMergeRightJoin()
123        {
124            using (RightMergeJoinUsersToPeopleByEmail join = new RightMergeJoinUsersToPeopleByEmail())
125            {
126                join.Left(new GenericEnumerableOperation(left))
127                    .Right(new GenericEnumerableOperation(right));
128                join.PrepareForExecution(new SingleThreadedPipelineExecuter());
129                IEnumerable<Row> result = join.Execute(null);
130                List<Row> items = new List<Row>(result);
131
132                Assert.Equal(2, items.Count);
133                Assert.Equal(3, items[0]["person_id"]);
134                Assert.Null(items[1]["name"]);
135                Assert.Equal(5, items[1]["person_id"]);
136            }
137        }
138
139        [Fact]
140        public void SortMergeFullJoin()
141        {
142            using (FullMergeJoinUsersToPeopleByEmail join = new FullMergeJoinUsersToPeopleByEmail())
143            {
144                join.Left(new GenericEnumerableOperation(left))
145                    .Right(new GenericEnumerableOperation(right));
146                join.PrepareForExecution(new SingleThreadedPipelineExecuter());
147                IEnumerable<Row> result = join.Execute(null);
148                List<Row> items = new List<Row>(result);
149
150                Assert.Equal(3, items.Count);
151
152                Assert.Equal(3, items[0]["person_id"]);
153
154                Assert.Null(items[1]["person_id"]);
155                Assert.Equal("bar", items[1]["name"]);
156
157                Assert.Null(items[2]["name"]);
158                Assert.Equal(5, items[2]["person_id"]);
159            }
160        }
161
162        [Fact]
163        public void SortMergeFullJoinMergesMultipleNonMatchingLeftRowsAtEnd()
164        {
165            AddUser("toby", "toby@test.org");
166            AddUser("tom", "tom@test.org");
167
168            using (FullMergeJoinUsersToPeopleByEmail join = new FullMergeJoinUsersToPeopleByEmail())
169            {
170                join.Left(new GenericEnumerableOperation(left))
171                    .Right(new GenericEnumerableOperation(right));
172                join.PrepareForExecution(new SingleThreadedPipelineExecuter());
173                IEnumerable<Row> result = join.Execute(null);
174                List<Row> items = new List<Row>(result);
175
176                Assert.Equal(5, items.Count);
177                Assert.Null(items[3]["person_id"]);
178                Assert.Equal("toby", items[3]["name"]);
179
180                Assert.Null(items[4]["person_id"]);
181                Assert.Equal("tom", items[4]["name"]);
182            }
183        }
184
185        [Fact]
186        public void SortMergeFullJoinMergesMultipleNonMatchingRightRowsAtEnd()
187        {
188            AddPerson(8, "toby@test.org");
189            AddPerson(10, "tom@test.org");
190
191            using (FullMergeJoinUsersToPeopleByEmail join = new FullMergeJoinUsersToPeopleByEmail())
192            {
193                join.Left(new GenericEnumerableOperation(left))
194                    .Right(new GenericEnumerableOperation(right));
195                join.PrepareForExecution(new SingleThreadedPipelineExecuter());
196                IEnumerable<Row> result = join.Execute(null);
197                List<Row> items = new List<Row>(result);
198
199                Assert.Equal(5, items.Count);
200                Assert.Equal(8, items[3]["person_id"]);
201                Assert.Null(items[3]["name"]);
202
203                Assert.Equal(10, items[4]["person_id"]);
204                Assert.Null(items[4]["name"]);
205            }
206        }
207    }
208}