Beispiel #1
0
        public void TestGetNavigableStreams()
        {
            ExprIdentNode fake = supportExprNodeFactory.MakeIdentNode("TheString", "s0");

            queryGraph = new QueryGraphForge(5, null, false);
            queryGraph.AddStrictEquals(3, "p3", fake, 4, "p4", fake);
            queryGraph.AddStrictEquals(2, "P2", fake, 3, "p3", fake);
            queryGraph.AddStrictEquals(1, "P1", fake, 2, "P2", fake);

            Assert.AreEqual(0, queryGraph.GetNavigableStreams(0).Count);
            EPAssertionUtil.AssertEqualsAnyOrder(new int[] { 2 }, queryGraph.GetNavigableStreams(1));
            EPAssertionUtil.AssertEqualsAnyOrder(new int[] { 1, 3 }, queryGraph.GetNavigableStreams(2));
            EPAssertionUtil.AssertEqualsAnyOrder(new int[] { 2, 4 }, queryGraph.GetNavigableStreams(3));
            EPAssertionUtil.AssertEqualsAnyOrder(new int[] { 3 }, queryGraph.GetNavigableStreams(4));
        }
Beispiel #2
0
        /// <summary>
        ///     Looks at the key and index(aka.left and right) properties of the 2 streams and checks
        ///     for each property if any equivalent index properties exist for other streams.
        ///     Example:  s0.p0 = s1.p1  and s1.p1 = s2.p2 ==> therefore s0.p0 = s2.p2
        ///     ==> look stream s0, property p0; indexed stream s1, property p1
        ///     Is there any other lookup stream that has stream 1 and property p1 as index property? ==> this is stream s2, p2
        ///     Add navigation entry between stream s0 and property p0 to stream s2, property p2
        /// </summary>
        private static bool FillEquivalentNav(
            EventType[] typesPerStream,
            QueryGraphForge queryGraph,
            int lookupStream,
            string keyProp,
            int indexedStream,
            string indexProp)
        {
            var addedEquivalency = false;

            for (var otherStream = 0; otherStream < queryGraph.NumStreams; otherStream++) {
                if (otherStream == lookupStream || otherStream == indexedStream) {
                    continue;
                }

                var value = queryGraph.GetGraphValue(otherStream, indexedStream);
                QueryGraphValuePairHashKeyIndexForge hashKeys = value.HashKeyProps;

                var otherStrictKeyProps = hashKeys.StrictKeys;
                var otherIndexProps = hashKeys.Indexed;
                var otherPropertyNum = -1;

                if (otherIndexProps == null) {
                    continue;
                }

                for (var i = 0; i < otherIndexProps.Length; i++) {
                    if (otherIndexProps[i].Equals(indexProp)) {
                        otherPropertyNum = i;
                        break;
                    }
                }

                if (otherPropertyNum != -1) {
                    if (otherStrictKeyProps[otherPropertyNum] != null) {
                        ExprIdentNode identNodeLookup = new ExprIdentNodeImpl(
                            typesPerStream[lookupStream],
                            keyProp,
                            lookupStream);
                        ExprIdentNode identNodeOther = new ExprIdentNodeImpl(
                            typesPerStream[otherStream],
                            otherStrictKeyProps[otherPropertyNum],
                            otherStream);
                        var added = queryGraph.AddStrictEquals(
                            lookupStream,
                            keyProp,
                            identNodeLookup,
                            otherStream,
                            otherStrictKeyProps[otherPropertyNum],
                            identNodeOther);
                        if (added) {
                            addedEquivalency = true;
                        }
                    }
                }
            }

            return addedEquivalency;
        }
Beispiel #3
0
        public void TestFillEquivalency()
        {
            // test with just 3 streams
            queryGraph.AddStrictEquals(0, "P00", Make(0, "P00"), 1, "P10", Make(1, "P10"));
            queryGraph.AddStrictEquals(1, "P10", Make(1, "P10"), 2, "P20", Make(2, "P20"));

            Assert.IsFalse(queryGraph.IsNavigableAtAll(0, 2));
            Assert.AreEqual(0, SupportQueryGraphTestUtil.GetStrictKeyProperties(queryGraph, 0, 2).Length);
            Assert.AreEqual(0, SupportQueryGraphTestUtil.GetIndexProperties(queryGraph, 0, 2).Length);

            QueryGraphForge.FillEquivalentNav(types, queryGraph);

            Assert.IsTrue(queryGraph.IsNavigableAtAll(0, 2));
            string[] expectedOne = new string[] { "P00" };
            string[] expectedTwo = new string[] { "P20" };
            Assert.IsTrue(Arrays.AreEqual(expectedOne, SupportQueryGraphTestUtil.GetStrictKeyProperties(queryGraph, 0, 2)));
            Assert.IsTrue(Arrays.AreEqual(expectedTwo, SupportQueryGraphTestUtil.GetIndexProperties(queryGraph, 0, 2)));

            // test with 5 streams, connect all streams to all streams
            queryGraph = new QueryGraphForge(5, null, false);
            queryGraph.AddStrictEquals(0, "P0", Make(0, "P0"), 1, "P1", Make(1, "P1"));
            queryGraph.AddStrictEquals(3, "P3", Make(3, "P3"), 4, "P4", Make(4, "P4"));
            queryGraph.AddStrictEquals(2, "P2", Make(2, "P2"), 3, "P3", Make(3, "P3"));
            queryGraph.AddStrictEquals(1, "P1", Make(1, "P1"), 2, "P2", Make(2, "P2"));

            QueryGraphForge.FillEquivalentNav(types, queryGraph);

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    Assert.IsTrue(queryGraph.IsNavigableAtAll(i, j), "Not navigable: i=" + i + " j=" + j);
                }
            }
        }