Ejemplo n.º 1
0
        public void LOJ1Row()
        {
            var container = new QueryContainer(null);

            var left = new StreamEvent <MyData>[]
            {
                StreamEvent.CreatePoint(10, new MyData {
                    field1 = 1, field2 = "A"
                }),
                StreamEvent.CreatePoint(10, new MyData {
                    field1 = 1, field2 = "B"
                }),
                StreamEvent.CreatePoint(10, new MyData {
                    field1 = 2, field2 = "D"
                }),
                StreamEvent.CreatePoint(10, new MyData {
                    field1 = 2, field2 = "E"
                })
            };

            var right = new StreamEvent <MyData2>[]
            {
                StreamEvent.CreatePoint(10, new MyData2 {
                    field3 = 1, field4 = "W"
                }),
                StreamEvent.CreatePoint(10, new MyData2 {
                    field3 = 1, field4 = "X"
                }),
                StreamEvent.CreatePoint(10, new MyData2 {
                    field3 = 2, field4 = "Y"
                })
            };

            var output   = new List <StreamEvent <MyData3> >();
            var expected = new StreamEvent <MyData3>[]
            {
                StreamEvent.CreatePoint(10, new MyData3 {
                    field1 = 2, field2 = "E", field3 = -1, field4 = "null"
                }),
                StreamEvent.CreatePoint(10, new MyData3 {
                    field1 = 1, field2 = "B", field3 = 1, field4 = "W"
                }),
                StreamEvent.CreatePoint(10, new MyData3 {
                    field1 = 1, field2 = "A", field3 = 1, field4 = "W"
                }),
                StreamEvent.CreatePoint(10, new MyData3 {
                    field1 = 1, field2 = "B", field3 = 1, field4 = "X"
                }),
                StreamEvent.CreatePoint(10, new MyData3 {
                    field1 = 1, field2 = "A", field3 = 1, field4 = "X"
                }),
                StreamEvent.CreatePoint(10, new MyData3 {
                    field1 = 2, field2 = "D", field3 = 2, field4 = "Y"
                }),
            };

            var leftStream  = container.RegisterInput(left.ToObservable());
            var rightStream = container.RegisterInput(right.ToObservable());

            int    tmp1 = -1;
            string tmp2 = "null";

            var query =
                leftStream.LeftOuterJoin(rightStream, e => e.field1, e => e.field3,
                                         (l, r) => l.field2 != "E",
                                         (l) => new MyData3 {
                field1 = l.field1, field2 = l.field2, field3 = tmp1, field4 = tmp2
            },
                                         (l, r) => new MyData3 {
                field1 = l.field1, field2 = l.field2, field3 = r.field3, field4 = r.field4
            });

            var result      = container.RegisterOutput(query, ReshapingPolicy.CoalesceEndEdges).Where(e => e.IsData);
            var resultAsync = result.ForEachAsync(o => output.Add(o));

            container.Restore(null); // start the query

            Assert.IsTrue(output.ToArray().SequenceEqual(expected));
        }