Exemplo n.º 1
0
        public void TestGraphOuterJoins()
        {
            var descList = new OuterJoinDesc[2];

            descList[0] = SupportOuterJoinDescFactory.MakeDesc(
                container, "IntPrimitive", "s0", "IntBoxed", "s1", OuterJoinType.RIGHT);
            descList[1] = SupportOuterJoinDescFactory.MakeDesc(
                container, "SimpleProperty", "s2", "TheString", "s1", OuterJoinType.FULL);

            var graph = NStreamOuterQueryPlanBuilder.GraphOuterJoins(3, descList);

            // assert the inner and outer streams for each stream
            AssertInners(new[] { null, new[] { 0, 2 }, new[] { 1 } }, graph);
            AssertOuters(new[] { new[] { 1 }, new[] { 2 }, new[] { 1 } }, graph);

            descList[0] = SupportOuterJoinDescFactory.MakeDesc(
                container, "IntPrimitive", "s1", "IntBoxed", "s0", OuterJoinType.LEFT);
            descList[1] = SupportOuterJoinDescFactory.MakeDesc(
                container, "SimpleProperty", "s2", "TheString", "s1", OuterJoinType.RIGHT);

            graph = NStreamOuterQueryPlanBuilder.GraphOuterJoins(3, descList);

            // assert the inner and outer streams for each stream
            AssertInners(new[] { new[] { 1 }, null, new[] { 1 } }, graph);
            AssertOuters(new[] { null, new[] { 0, 2 }, null }, graph);

            try {
                NStreamOuterQueryPlanBuilder.GraphOuterJoins(3, new OuterJoinDesc[0]);
                Assert.Fail();
            }
            catch (ArgumentException) {
                // expected
            }
        }
Exemplo n.º 2
0
 private void TryVerifyJoinedPerStream(IDictionary <int, int[]> map)
 {
     try {
         NStreamOuterQueryPlanBuilder.VerifyJoinedPerStream(0, map);
         Assert.Fail();
     }
     catch (ArgumentException) {
         // expected
     }
 }
Exemplo n.º 3
0
        public void TestRecursiveBuild()
        {
            var streamNum           = 2;
            var queryGraph          = new QueryGraphForge(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);
            var fake = supportExprNodeFactory.MakeIdentNode("TheString", "s0");

            queryGraph.AddStrictEquals(2, "", fake, 3, "", fake);
            queryGraph.AddStrictEquals(3, "", fake, 4, "", fake);
            queryGraph.AddStrictEquals(3, "", fake, 5, "", fake);
            queryGraph.AddStrictEquals(2, "", fake, 1, "", fake);
            queryGraph.AddStrictEquals(1, "", fake, 0, "", fake);

            ISet <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.Get(2), new[] { 3, 1 });
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream.Get(3), new[] { 4, 5 });
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream.Get(1), new[] { 0 });
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream.Get(4), new int[] { });
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream.Get(5), new int[] { });
            EPAssertionUtil.AssertEqualsExactOrder(substreamsPerStream.Get(0), new int[] { });

            NStreamOuterQueryPlanBuilder.VerifyJoinedPerStream(2, substreamsPerStream);
            EPAssertionUtil.AssertEqualsExactOrder(
                requiredPerStream,
                new[] { false, false, false, true, true, false }
                );
        }
Exemplo n.º 4
0
        public static QueryPlanForgeDesc GetPlan(
            EventType[] typesPerStream,
            OuterJoinDesc[] outerJoinDescList,
            QueryGraphForge queryGraph,
            string[] streamNames,
            HistoricalViewableDesc historicalViewableDesc,
            DependencyGraph dependencyGraph,
            HistoricalStreamIndexListForge[] historicalStreamIndexLists,
            StreamJoinAnalysisResultCompileTime streamJoinAnalysisResult,
            bool isQueryPlanLogging,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            string methodName = ".getPlan ";

            int numStreams = typesPerStream.Length;
            if (numStreams < 2) {
                throw new ArgumentException("Number of join stream types is less then 2");
            }

            if (outerJoinDescList.Length >= numStreams) {
                throw new ArgumentException("Too many outer join descriptors found");
            }

            if (numStreams == 2) {
                OuterJoinType? outerJoinType = null;
                if (outerJoinDescList.Length > 0) {
                    outerJoinType = outerJoinDescList[0].OuterJoinType;
                }

                QueryPlanForgeDesc queryPlan = TwoStreamQueryPlanBuilder.Build(
                    typesPerStream,
                    queryGraph,
                    outerJoinType,
                    streamJoinAnalysisResult,
                    statementRawInfo);
                RemoveUnidirectionalAndTable(queryPlan.Forge, streamJoinAnalysisResult);

                if (Log.IsDebugEnabled) {
                    Log.Debug(methodName + "2-Stream queryPlan=" + queryPlan);
                }

                return queryPlan;
            }

            bool hasPreferMergeJoin = HintEnum.PREFER_MERGE_JOIN.GetHint(statementRawInfo.Annotations) != null;
            bool hasForceNestedIter = HintEnum.FORCE_NESTED_ITER.GetHint(statementRawInfo.Annotations) != null;
            bool isAllInnerJoins = outerJoinDescList.Length == 0 ||
                                   OuterJoinDesc.ConsistsOfAllInnerJoins(outerJoinDescList);

            if (isAllInnerJoins && !hasPreferMergeJoin) {
                QueryPlanForgeDesc queryPlan = NStreamQueryPlanBuilder.Build(
                    queryGraph,
                    typesPerStream,
                    historicalViewableDesc,
                    dependencyGraph,
                    historicalStreamIndexLists,
                    hasForceNestedIter,
                    streamJoinAnalysisResult.UniqueKeys,
                    streamJoinAnalysisResult.TablesPerStream,
                    streamJoinAnalysisResult,
                    statementRawInfo,
                    services.SerdeResolver);

                if (queryPlan != null) {
                    RemoveUnidirectionalAndTable(queryPlan.Forge, streamJoinAnalysisResult);

                    if (Log.IsDebugEnabled) {
                        Log.Debug(methodName + "N-Stream inner-join queryPlan=" + queryPlan);
                    }

                    return queryPlan;
                }

                if (isQueryPlanLogging && QUERY_PLAN_LOG.IsInfoEnabled) {
                    Log.Info("Switching to Outer-NStream algorithm for query plan");
                }
            }

            QueryPlanForgeDesc queryPlanX = NStreamOuterQueryPlanBuilder.Build(
                queryGraph,
                outerJoinDescList,
                streamNames,
                typesPerStream,
                historicalViewableDesc,
                dependencyGraph,
                historicalStreamIndexLists,
                streamJoinAnalysisResult.UniqueKeys,
                streamJoinAnalysisResult.TablesPerStream,
                streamJoinAnalysisResult,
                statementRawInfo,
                services);
            RemoveUnidirectionalAndTable(queryPlanX.Forge, streamJoinAnalysisResult);
            return queryPlanX;
        }