예제 #1
0
        public void SetUp()
        {
            _typesPerStream = new EventType[]
            {
                SupportEventAdapterService.Service.AddBeanType(typeof(SupportBean_S0).FullName, typeof(SupportBean_S0),
                                                               true, true, true),
                SupportEventAdapterService.Service.AddBeanType(typeof(SupportBean_S1).FullName, typeof(SupportBean_S1),
                                                               true, true, true),
                SupportEventAdapterService.Service.AddBeanType(typeof(SupportBean_S2).FullName, typeof(SupportBean_S2),
                                                               true, true, true),
                SupportEventAdapterService.Service.AddBeanType(typeof(SupportBean_S3).FullName, typeof(SupportBean_S3),
                                                               true, true, true),
                SupportEventAdapterService.Service.AddBeanType(typeof(SupportBean_S4).FullName, typeof(SupportBean_S4),
                                                               true, true, true)
            };

            _queryGraph = new QueryGraph(5, null, false);
            _queryGraph.AddStrictEquals(0, "P00", Make(0, "P00"), 1, "P10", Make(1, "P10"));
            _queryGraph.AddStrictEquals(0, "P01", Make(0, "P01"), 2, "P20", Make(2, "P20"));
            _queryGraph.AddStrictEquals(4, "P40", Make(4, "P40"), 3, "P30", Make(3, "P30"));
            _queryGraph.AddStrictEquals(4, "P41", Make(4, "P41"), 3, "P31", Make(3, "P31"));
            _queryGraph.AddStrictEquals(4, "P42", Make(4, "P42"), 2, "P21", Make(2, "P21"));

            _dependencyGraph = new DependencyGraph(5, false);
        }
예제 #2
0
        public void TestRecursiveBuild()
        {
            var streamNum           = 2;
            var queryGraph          = new QueryGraph(6, null, false);
            var outerInnerGraph     = new OuterInnerDirectionalGraph(6);
            var completedStreams    = new HashSet <int>();
            var substreamsPerStream = new LinkedHashMap <int, int[]>();
            var requiredPerStream   = new bool[6];

            outerInnerGraph.Add(3, 2).Add(2, 1).Add(4, 3).Add(1, 0).Add(3, 5);
            queryGraph.AddStrictEquals(2, "", null, 3, "", null);
            queryGraph.AddStrictEquals(3, "", null, 4, "", null);
            queryGraph.AddStrictEquals(3, "", null, 5, "", null);
            queryGraph.AddStrictEquals(2, "", null, 1, "", null);
            queryGraph.AddStrictEquals(1, "", null, 0, "", null);

            ICollection <InterchangeablePair <int, int> > innerJoins = new HashSet <InterchangeablePair <int, int> >();
            var innerJoinGraph = new InnerJoinGraph(6, innerJoins);
            var streamStack    = new Stack <int>();

            NStreamOuterQueryPlanBuilder.RecursiveBuild(streamNum, streamStack, queryGraph, outerInnerGraph, innerJoinGraph, completedStreams,
                                                        substreamsPerStream, requiredPerStream, new DependencyGraph(6, false));

            Assert.AreEqual(6, substreamsPerStream.Count);
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream[2], new int[] { 3, 1 });
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream.Get(3), new int[] { 4, 5 });
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream[1], new int[] { 0 });
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream.Get(4), new int[] {});
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream.Get(5), new int[] {});
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream[0], new int[] {});

            NStreamOuterQueryPlanBuilder.VerifyJoinedPerStream(2, substreamsPerStream);
            EPAssertionUtil.AssertEqualsExactOrder(requiredPerStream, new bool[] { false, false, false, true, true, false }
                                                   );
        }
예제 #3
0
        private QueryGraph MakeQueryGraph()
        {
            QueryGraph graph = new QueryGraph(2, null, false);

            graph.AddStrictEquals(0, "P01", Make(0, "P01"), 1, "P11", Make(1, "P11"));
            graph.AddStrictEquals(0, "P02", Make(0, "P02"), 1, "P12", Make(1, "P12"));
            return(graph);
        }
예제 #4
0
        public void TestIndexAlreadyExists()
        {
            _queryGraph = new QueryGraph(5, null, false);
            _queryGraph.AddStrictEquals(0, "p00", Make(0, "p00"), 1, "p10", Make(1, "p10"));
            _queryGraph.AddStrictEquals(0, "p00", Make(0, "p00"), 2, "p20", Make(2, "p20"));

            QueryPlanIndex[] indexes = QueryPlanIndexBuilder.BuildIndexSpec(_queryGraph, _types, new String[_queryGraph.NumStreams][][]);

            String[][] expected = new String[][] { new [] { "p00" } };
            EPAssertionUtil.AssertEqualsExactOrder(indexes[0].IndexProps, expected);
        }
예제 #5
0
        public void TestGetNavigableStreams()
        {
            _queryGraph = new QueryGraph(5, null, false);
            _queryGraph.AddStrictEquals(3, "p3", null, 4, "p4", null);
            _queryGraph.AddStrictEquals(2, "p2", null, 3, "p3", null);
            _queryGraph.AddStrictEquals(1, "p1", null, 2, "p2", null);

            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));
        }
예제 #6
0
        /// <summary>
        /// Analye EQUALS (=) node.
        /// </summary>
        /// <param name="equalsNode">node to analyze</param>
        /// <param name="queryGraph">store relationships between stream properties</param>
        /// <param name="isOuterJoin">if set to <c>true</c> [is outer join].</param>
        internal static void AnalyzeEqualsNode(ExprEqualsNode equalsNode, QueryGraph queryGraph, bool isOuterJoin)
        {
            if ((equalsNode.ChildNodes[0] is ExprIdentNode) &&
                (equalsNode.ChildNodes[1] is ExprIdentNode))
            {
                var identNodeLeft  = (ExprIdentNode)equalsNode.ChildNodes[0];
                var identNodeRight = (ExprIdentNode)equalsNode.ChildNodes[1];

                if (identNodeLeft.StreamId != identNodeRight.StreamId)
                {
                    queryGraph.AddStrictEquals(identNodeLeft.StreamId, identNodeLeft.ResolvedPropertyName, identNodeLeft,
                                               identNodeRight.StreamId, identNodeRight.ResolvedPropertyName, identNodeRight);
                }

                return;
            }
            if (isOuterJoin)        // outerjoins don't use constants or one-way expression-derived information to evaluate join
            {
                return;
            }

            // handle constant-compare or transformation case
            var           indexedStream   = -1;
            ExprIdentNode indexedPropExpr = null;
            ExprNode      exprNodeNoIdent = null;

            if (equalsNode.ChildNodes[0] is ExprIdentNode)
            {
                indexedPropExpr = (ExprIdentNode)equalsNode.ChildNodes[0];
                indexedStream   = indexedPropExpr.StreamId;
                exprNodeNoIdent = equalsNode.ChildNodes[1];
            }
            else if (equalsNode.ChildNodes[1] is ExprIdentNode)
            {
                indexedPropExpr = (ExprIdentNode)equalsNode.ChildNodes[1];
                indexedStream   = indexedPropExpr.StreamId;
                exprNodeNoIdent = equalsNode.ChildNodes[0];
            }
            if (indexedStream == -1)
            {
                return;     // require property of right/left side of equals
            }

            var eligibility = EligibilityUtil.VerifyInputStream(exprNodeNoIdent, indexedStream);

            if (!eligibility.Eligibility.IsEligible())
            {
                return;
            }

            if (eligibility.Eligibility == Eligibility.REQUIRE_NONE)
            {
                queryGraph.AddUnkeyedExpression(indexedStream, indexedPropExpr, exprNodeNoIdent);
            }
            else
            {
                queryGraph.AddKeyedExpression(indexedStream, indexedPropExpr, eligibility.StreamNum.Value, exprNodeNoIdent);
            }
        }
예제 #7
0
        public void SetUp()
        {
            _types = new EventType[] {
                SupportEventTypeFactory.CreateMapType(CreateType("p00,p01")),
                SupportEventTypeFactory.CreateMapType(CreateType("p10")),
                SupportEventTypeFactory.CreateMapType(CreateType("p20,p21")),
                SupportEventTypeFactory.CreateMapType(CreateType("p30,p31")),
                SupportEventTypeFactory.CreateMapType(CreateType("p40,p41,p42")),
            };

            _queryGraph = new QueryGraph(5, null, false);
            _queryGraph.AddStrictEquals(0, "p00", Make(0, "p00"), 1, "p10", Make(1, "p10"));
            _queryGraph.AddStrictEquals(0, "p01", Make(0, "p01"), 2, "p20", Make(2, "p20"));
            _queryGraph.AddStrictEquals(4, "p40", Make(4, "p40"), 3, "p30", Make(3, "p30"));
            _queryGraph.AddStrictEquals(4, "p41", Make(4, "p41"), 3, "p31", Make(3, "p31"));
            _queryGraph.AddStrictEquals(4, "p42", Make(4, "p42"), 2, "p21", Make(2, "p21"));
        }
예제 #8
0
        public void TestComputeNavigableDepth()
        {
            _queryGraph.AddStrictEquals(3, "P30", null, 2, "P20", null);
            _queryGraph.AddStrictEquals(2, "P30", null, 1, "P20", null);

            int depth = NStreamQueryPlanBuilder.ComputeNavigableDepth(0, new int[] { 1, 2, 3, 4 }, _queryGraph);

            Assert.AreEqual(4, depth);

            depth = NStreamQueryPlanBuilder.ComputeNavigableDepth(0, new int[] { 4, 2, 3, 1 }, _queryGraph);
            Assert.AreEqual(0, depth);

            depth = NStreamQueryPlanBuilder.ComputeNavigableDepth(4, new int[] { 3, 2, 1, 0 }, _queryGraph);
            Assert.AreEqual(4, depth);

            depth = NStreamQueryPlanBuilder.ComputeNavigableDepth(1, new int[] { 0, 3, 4, 2 }, _queryGraph);
            Assert.AreEqual(1, depth);
        }
예제 #9
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, QueryGraph 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);
                var hashKeys = value.HashKeyProps;

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

                if (otherIndexProps == null)
                {
                    continue;
                }

                for (var i = 0; i < otherIndexProps.Count; 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);
        }
예제 #10
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, QueryGraphTestUtil.GetStrictKeyProperties(_queryGraph, 0, 2).Count);
            Assert.AreEqual(0, QueryGraphTestUtil.GetIndexProperties(_queryGraph, 0, 2).Count);

            QueryGraph.FillEquivalentNav(_types, _queryGraph);

            Assert.IsTrue(_queryGraph.IsNavigableAtAll(0, 2));
            String[] expectedOne = new String[] { "p00" };
            String[] expectedTwo = new String[] { "p20" };
            Assert.IsTrue(Collections.AreEqual(expectedOne, QueryGraphTestUtil.GetStrictKeyProperties(_queryGraph, 0, 2)));
            Assert.IsTrue(Collections.AreEqual(expectedTwo, QueryGraphTestUtil.GetIndexProperties(_queryGraph, 0, 2)));

            // test with 5 streams, connect all streams to all streams
            _queryGraph = new QueryGraph(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"));

            QueryGraph.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);
                }
            }
        }
예제 #11
0
 private static void Add(QueryGraph queryGraph, ExprIdentNode identNodeLeft, ExprIdentNode identNodeRight)
 {
     queryGraph.AddStrictEquals(identNodeLeft.StreamId, identNodeLeft.ResolvedPropertyName, identNodeLeft,
             identNodeRight.StreamId, identNodeRight.ResolvedPropertyName, identNodeRight);
 }