private void RunAssertionMultiIdxConstants(EPServiceProvider epService)
        {
            SupportQueryPlanIndexHook.Reset();
            var epl = INDEX_CALLBACK_HOOK + "select * from S0 as s0 unidirectional, S1#keepall as s1 " +
                      "where 'a' in (P10, P11)";
            var fields = "s0.Id,s1.Id".Split(',');
            var stmt = epService.EPAdministrator.CreateEPL(epl);
            var listener = new SupportUpdateListener();
            stmt.Events += listener.Update;

            var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[1].Items;
            Assert.AreEqual("[P10][P11]", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));

            epService.EPRuntime.SendEvent(new SupportBean_S1(100, "x", "y"));
            epService.EPRuntime.SendEvent(new SupportBean_S1(101, "x", "a"));

            epService.EPRuntime.SendEvent(new SupportBean_S0(1));
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                listener.GetAndResetLastNewData(), fields, new[] {new object[] {1, 101}});

            epService.EPRuntime.SendEvent(new SupportBean_S1(102, "b", "a"));
            epService.EPRuntime.SendEvent(new SupportBean_S0(2));
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                listener.GetAndResetLastNewData(), fields, new[] {new object[] {2, 101}, new object[] {2, 102}});

            stmt.Dispose();
        }
        private void RunAssertionMultiIdxMultipleInAndMultirow(EPServiceProvider epService)
        {
            // assert join
            SupportQueryPlanIndexHook.Reset();
            var epl = INDEX_CALLBACK_HOOK + "select * from S0 as s0 unidirectional, S1#keepall as s1 " +
                      "where P00 in (P10, P11) and P01 in (P12, P13)";
            var stmt = epService.EPAdministrator.CreateEPL(epl);
            var listener = new SupportUpdateListener();
            stmt.Events += listener.Update;

            var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[1].Items;
            Assert.AreEqual("[P10][P11]", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));

            TryAssertionMultiIdx(epService, listener);
            epService.EPAdministrator.DestroyAllStatements();

            // assert named window
            epService.EPAdministrator.CreateEPL("create window S1Window#keepall as S1");
            epService.EPAdministrator.CreateEPL("insert into S1Window select * from S1");

            var eplNamedWindow = INDEX_CALLBACK_HOOK + "on S0 as s0 select * from S1Window as s1 " +
                                 "where P00 in (P10, P11) and P01 in (P12, P13)";
            var stmtNamedWindow = epService.EPAdministrator.CreateEPL(eplNamedWindow);
            stmtNamedWindow.Events += listener.Update;

            var onExprNamedWindow = SupportQueryPlanIndexHook.AssertOnExprAndReset();
            Assert.AreEqual(
                typeof(SubordInKeywordMultiTableLookupStrategyFactory).Name, onExprNamedWindow.TableLookupStrategy);

            TryAssertionMultiIdx(epService, listener);

            // assert table
            epService.EPAdministrator.CreateEPL(
                "create table S1Table("
                + "Id int primary key, "
                + "P10 string primary key, "
                + "P11 string primary key, "
                + "P12 string primary key, "
                + "P13 string primary key)"
                );
            epService.EPAdministrator.CreateEPL("insert into S1Table select * from S1");
            epService.EPAdministrator.CreateEPL("create index S1Idx1 on S1Table(P10)");
            epService.EPAdministrator.CreateEPL("create index S1Idx2 on S1Table(P11)");
            epService.EPAdministrator.CreateEPL("create index S1Idx3 on S1Table(P12)");
            epService.EPAdministrator.CreateEPL("create index S1Idx4 on S1Table(P13)");

            var eplTable = INDEX_CALLBACK_HOOK + "on S0 as s0 select * from S1Table as s1 " +
                           "where P00 in (P10, P11) and P01 in (P12, P13)";
            var stmtTable = epService.EPAdministrator.CreateEPL(eplTable);
            stmtTable.Events += listener.Update;

            var onExprTable = SupportQueryPlanIndexHook.AssertOnExprAndReset();
            Assert.AreEqual(
                typeof(SubordInKeywordMultiTableLookupStrategyFactory).Name, onExprTable.TableLookupStrategy);

            TryAssertionMultiIdx(epService, listener);

            epService.EPAdministrator.DestroyAllStatements();
        }
        private void TryAssertion(EPServiceProvider epService, string epl, QueryPlan expectedPlan)
        {
            SupportQueryPlanIndexHook.Reset();
            epl = INDEX_CALLBACK_HOOK + epl;
            epService.EPAdministrator.CreateEPL(epl);

            var actualPlan = SupportQueryPlanIndexHook.AssertJoinAndReset();
            SupportQueryPlanIndexHelper.CompareQueryPlans(expectedPlan, actualPlan);

            epService.EPAdministrator.DestroyAllStatements();
        }
Пример #4
0
 public void Run(RegressionEnvironment env)
 {
     SupportQueryPlanIndexHook.Reset();
     var epl = INDEX_CALLBACK_HOOK +
               "select * from SupportBean_S0 as S0 unidirectional, SupportBean_S1#keepall as S1 " +
               "where P00 not in (P10, P11)";
     env.CompileDeploy(epl);
     var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[1].Items;
     Assert.AreEqual("[]", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));
     env.UndeployAll();
 }
Пример #5
0
        public void TestMultiIdxMultipleInAndMultirow()
        {
            // assert join
            SupportQueryPlanIndexHook.Reset();
            var epl = INDEX_CALLBACK_HOOK + "select * from S0 as s0 unidirectional, S1.win:keepall() as s1 " +
                      "where p00 in (p10, p11) and p01 in (p12, p13)";
            var stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.AddListener(_listener);

            var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[1].Items;

            Assert.AreEqual("[p10][p11]", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));

            RunAssertionMultiIdx();
            _epService.EPAdministrator.DestroyAllStatements();

            // assert named window
            _epService.EPAdministrator.CreateEPL("create window S1Window.win:keepall() as S1");
            _epService.EPAdministrator.CreateEPL("insert into S1Window select * from S1");

            var eplNamedWindow = INDEX_CALLBACK_HOOK + "on S0 as s0 select * from S1Window as s1 " +
                                 "where P00 in (P10, p11) and P01 in (P12, P13)";
            var stmtNamedWindow = _epService.EPAdministrator.CreateEPL(eplNamedWindow);

            stmtNamedWindow.AddListener(_listener);

            var onExprNamedWindow = SupportQueryPlanIndexHook.AssertOnExprAndReset();

            Assert.AreEqual(typeof(SubordInKeywordMultiTableLookupStrategyFactory).Name, onExprNamedWindow.TableLookupStrategy);

            RunAssertionMultiIdx();

            // assert table
            _epService.EPAdministrator.CreateEPL("create table S1Table(Id int primary key, P10 string primary key, P11 string primary key, P12 string primary key, P13 string primary key)");
            _epService.EPAdministrator.CreateEPL("insert into S1Table select * from S1");
            _epService.EPAdministrator.CreateEPL("create index S1Idx1 on S1Table(P10)");
            _epService.EPAdministrator.CreateEPL("create index S1Idx2 on S1Table(P11)");
            _epService.EPAdministrator.CreateEPL("create index S1Idx3 on S1Table(P12)");
            _epService.EPAdministrator.CreateEPL("create index S1Idx4 on S1Table(P13)");

            var eplTable = INDEX_CALLBACK_HOOK + "on S0 as s0 select * from S1Table as s1 " +
                           "where P00 in (P10, P11) and P01 in (P12, P13)";
            var stmtTable = _epService.EPAdministrator.CreateEPL(eplTable);

            stmtTable.AddListener(_listener);

            var onExprTable = SupportQueryPlanIndexHook.AssertOnExprAndReset();

            Assert.AreEqual(typeof(SubordInKeywordMultiTableLookupStrategyFactory).Name, onExprTable.TableLookupStrategy);

            RunAssertionMultiIdx();
        }
Пример #6
0
 private static void TryAssertion(
     RegressionEnvironment env,
     string epl,
     QueryPlanForge expectedPlan)
 {
     SupportQueryPlanIndexHook.Reset();
     epl = INDEX_CALLBACK_HOOK + epl;
     env.CompileDeploy(epl);
     var actualPlan = SupportQueryPlanIndexHook.AssertJoinAndReset();
     SupportQueryPlanIndexHelper.CompareQueryPlans(expectedPlan, actualPlan);
     env.UndeployAll();
 }
Пример #7
0
        public void TestNotIn()
        {
            SupportQueryPlanIndexHook.Reset();
            var epl = INDEX_CALLBACK_HOOK + "select * from S0 as s0 unidirectional, S1.win:keepall() as s1 " +
                      "where p00 not in (p10, p11)";
            var stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.AddListener(_listener);

            var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[1].Items;

            Assert.AreEqual("null", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));
        }
Пример #8
0
        public void TestSingleIdxMultipleInAndMultirow()
        {
            // assert join
            SupportQueryPlanIndexHook.Reset();
            var epl = INDEX_CALLBACK_HOOK + "select * from S0#keepall as s0, S1 as s1 unidirectional " +
                      "where P00 in (P10, P11) and P01 in (P12, P13)";
            var stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.AddListener(_listener);

            var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[0].Items;

            Assert.AreEqual("[P00]", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));

            RunAssertionSingleIdx();
            _epService.EPAdministrator.DestroyAllStatements();

            // assert named window
            _epService.EPAdministrator.CreateEPL("create window S0Window#keepall as S0");
            _epService.EPAdministrator.CreateEPL("insert into S0Window select * from S0");

            var eplNamedWindow = INDEX_CALLBACK_HOOK + "on S1 as s1 select * from S0Window as s0 " +
                                 "where P00 in (P10, P11) and P01 in (P12, P13)";
            var stmtNamedWindow = _epService.EPAdministrator.CreateEPL(eplNamedWindow);

            stmtNamedWindow.AddListener(_listener);

            var onExprNamedWindow = SupportQueryPlanIndexHook.AssertOnExprAndReset();

            Assert.AreEqual(typeof(SubordInKeywordSingleTableLookupStrategyFactory).Name, onExprNamedWindow.TableLookupStrategy);

            RunAssertionSingleIdx();

            // assert table
            _epService.EPAdministrator.CreateEPL("create table S0Table(Id int primary key, P00 string primary key, P01 string primary key, P02 string primary key, P03 string primary key)");
            _epService.EPAdministrator.CreateEPL("insert into S0Table select * from S0");
            _epService.EPAdministrator.CreateEPL("create index S0Idx1 on S0Table(P00)");
            _epService.EPAdministrator.CreateEPL("create index S0Idx2 on S0Table(P01)");

            var eplTable = INDEX_CALLBACK_HOOK + "on S1 as s1 select * from S0Table as s0 " +
                           "where P00 in (P10, P11) and P01 in (P12, P13)";
            var stmtTable = _epService.EPAdministrator.CreateEPL(eplTable);

            stmtTable.AddListener(_listener);

            var onExprTable = SupportQueryPlanIndexHook.AssertOnExprAndReset();

            Assert.AreEqual(typeof(SubordInKeywordSingleTableLookupStrategyFactory).Name, onExprTable.TableLookupStrategy);

            RunAssertionSingleIdx();
        }
        private void RunAssertionNotIn(EPServiceProvider epService)
        {
            SupportQueryPlanIndexHook.Reset();
            var epl = INDEX_CALLBACK_HOOK + "select * from S0 as s0 unidirectional, S1#keepall as s1 " +
                      "where P00 not in (P10, P11)";
            var stmt = epService.EPAdministrator.CreateEPL(epl);
            var listener = new SupportUpdateListener();
            stmt.Events += listener.Update;

            var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[1].Items;
            Assert.AreEqual("null", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));

            stmt.Dispose();
        }
Пример #10
0
 public void Run(RegressionEnvironment env)
 {
     // assert join
     SupportQueryPlanIndexHook.Reset();
     var epl = "@Name('s0') " +
               INDEX_CALLBACK_HOOK +
               "select * from SupportBean_S0 as S0 unidirectional, SupportBean_S1#keepall as S1 " +
               "where P00 in (P10, P11) and P01 in (P12, P13)";
     env.CompileDeploy(epl).AddListener("s0");
     var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[1].Items;
     Assert.AreEqual("[\"P10\"][\"P11\"]", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));
     TryAssertionMultiIdx(env);
     env.UndeployAll();
     // assert named window
     var path = new RegressionPath();
     env.CompileDeploy("create window S1Window#keepall as SupportBean_S1", path);
     env.CompileDeploy("insert into S1Window select * from SupportBean_S1", path);
     var eplNamedWindow = "@Name('s0') " +
                          INDEX_CALLBACK_HOOK +
                          "on SupportBean_S0 as S0 select * from S1Window as S1 " +
                          "where P00 in (P10, P11) and P01 in (P12, P13)";
     env.CompileDeploy(eplNamedWindow, path).AddListener("s0");
     var onExprNamedWindow = SupportQueryPlanIndexHook.AssertOnExprAndReset();
     Assert.AreEqual(typeof(SubordInKeywordMultiTableLookupStrategyFactoryForge).Name, onExprNamedWindow.TableLookupStrategy);
     TryAssertionMultiIdx(env);
     // assert table
     path.Clear();
     env.CompileDeploy(
         "create table S1Table(Id int primary key, P10 string primary key, P11 string primary key, P12 string primary key, P13 string primary key)",
         path);
     env.CompileDeploy("insert into S1Table select * from SupportBean_S1", path);
     env.CompileDeploy("create index S1Idx1 on S1Table(P10)", path);
     env.CompileDeploy("create index S1Idx2 on S1Table(P11)", path);
     env.CompileDeploy("create index S1Idx3 on S1Table(P12)", path);
     env.CompileDeploy("create index S1Idx4 on S1Table(P13)", path);
     var eplTable = "@Name('s0') " +
                    INDEX_CALLBACK_HOOK +
                    "on SupportBean_S0 as S0 select * from S1Table as S1 " +
                    "where P00 in (P10, P11) and P01 in (P12, P13)";
     env.CompileDeploy(eplTable, path).AddListener("s0");
     var onExprTable = SupportQueryPlanIndexHook.AssertOnExprAndReset();
     Assert.AreEqual(typeof(SubordInKeywordMultiTableLookupStrategyFactoryForge).Name, onExprTable.TableLookupStrategy);
     TryAssertionMultiIdx(env);
     env.UndeployAll();
 }
Пример #11
0
 public void Run(RegressionEnvironment env)
 {
     SupportQueryPlanIndexHook.Reset();
     var epl = "@Name('s0') " +
               INDEX_CALLBACK_HOOK +
               "select * from SupportBean_S0 as S0 unidirectional, SupportBean_S1#keepall as S1 " +
               "where 'a' in (P10, P11)";
     var fields = new[] {"S0.Id", "S1.Id"};
     env.CompileDeploy(epl).AddListener("s0");
     var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[1].Items;
     Assert.AreEqual("[\"P10\"][\"P11\"]", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));
     env.SendEventBean(new SupportBean_S1(100, "x", "y"));
     env.SendEventBean(new SupportBean_S1(101, "x", "a"));
     env.SendEventBean(new SupportBean_S0(1));
     EPAssertionUtil.AssertPropsPerRowAnyOrder(env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {1, 101}});
     env.SendEventBean(new SupportBean_S1(102, "b", "a"));
     env.SendEventBean(new SupportBean_S0(2));
     EPAssertionUtil.AssertPropsPerRowAnyOrder(
         env.Listener("s0").GetAndResetLastNewData(),
         fields,
         new[] {new object[] {2, 101}, new object[] {2, 102}});
     env.UndeployAll();
 }
Пример #12
0
        public void TestMultiIdxConstants()
        {
            SupportQueryPlanIndexHook.Reset();
            var epl = INDEX_CALLBACK_HOOK + "select * from S0 as s0 unidirectional, S1.win:keepall() as s1 " +
                      "where 'a' in (p10, p11)";
            var fields = "s0.id,s1.id".Split(',');
            var stmt   = _epService.EPAdministrator.CreateEPL(epl);

            stmt.AddListener(_listener);

            var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[1].Items;

            Assert.AreEqual("[p10][p11]", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));

            _epService.EPRuntime.SendEvent(new SupportBean_S1(100, "x", "y"));
            _epService.EPRuntime.SendEvent(new SupportBean_S1(101, "x", "a"));

            _epService.EPRuntime.SendEvent(new SupportBean_S0(1));
            EPAssertionUtil.AssertPropsPerRowAnyOrder(_listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { 1, 101 } });

            _epService.EPRuntime.SendEvent(new SupportBean_S1(102, "b", "a"));
            _epService.EPRuntime.SendEvent(new SupportBean_S0(2));
            EPAssertionUtil.AssertPropsPerRowAnyOrder(_listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { 2, 101 }, new object[] { 2, 102 } });
        }
Пример #13
0
        private void AssertIndexChoice(string eplDeclare, string eplPopulate, string eplQuery,
                                       string[] indexes, object[] preloadedEvents,
                                       IndexAssertion[] assertions, bool multistream)
        {
            _epService.EPAdministrator.CreateEPL(eplDeclare);
            _epService.EPAdministrator.CreateEPL(eplPopulate);

            foreach (var index in indexes)
            {
                _epService.EPAdministrator.CreateEPL(index);
            }
            foreach (var @event in preloadedEvents)
            {
                _epService.EPRuntime.SendEvent(@event);
            }

            var count = 0;

            foreach (var assertion in assertions)
            {
                Log.Info("======= Testing #" + count++);
                var epl = INDEX_CALLBACK_HOOK + (assertion.Hint ?? "") + eplQuery;
                epl += ", varagg as va";
                if (multistream)
                {
                    epl += ", SupportBeanSimple.std:lastevent()";
                }
                epl += " where " + assertion.WhereClause;

                EPStatement stmt;
                try {
                    stmt         = _epService.EPAdministrator.CreateEPL(epl);
                    stmt.Events += _listener.Update;
                }
                catch (EPStatementException ex) {
                    if (assertion.EventSendAssertion == null)
                    {
                        // no assertion, expected
                        Assert.IsTrue(ex.Message.Contains("index hint busted"));
                        continue;
                    }
                    throw new EPRuntimeException("Unexpected statement exception: " + ex.Message, ex);
                }

                // send multistream seed event
                _epService.EPRuntime.SendEvent(new SupportBeanSimple("", -1));

                // assert index and access
                assertion.EventSendAssertion.Invoke();
                var plan = SupportQueryPlanIndexHook.AssertJoinAndReset();

                TableLookupPlan tableLookupPlan;
                if (plan.ExecNodeSpecs[0] is TableLookupNode)
                {
                    tableLookupPlan = ((TableLookupNode)plan.ExecNodeSpecs[0]).TableLookupPlan;
                }
                else
                {
                    var lqp = (LookupInstructionQueryPlanNode)plan.ExecNodeSpecs[0];
                    tableLookupPlan = lqp.LookupInstructions[0].LookupPlans[0];
                }
                Assert.AreEqual(assertion.ExpectedIndexName, tableLookupPlan.IndexNum[0].Name);
                Assert.AreEqual(assertion.ExpectedStrategy, tableLookupPlan.GetType());
                stmt.Dispose();
            }

            _epService.EPAdministrator.DestroyAllStatements();
        }
Пример #14
0
        private static void AssertIndexChoice(
            RegressionEnvironment env,
            string eplDeclare,
            string eplPopulate,
            string eplQuery,
            string[] indexes,
            object[] preloadedEvents,
            IndexAssertion[] assertions,
            AtomicLong milestone,
            bool multistream)
        {
            var path = new RegressionPath();
            env.CompileDeploy(eplDeclare, path);
            env.CompileDeploy(eplPopulate, path);

            foreach (var index in indexes) {
                env.CompileDeploy(index, path);
            }

            foreach (var @event in preloadedEvents) {
                env.SendEventBean(@event);
            }

            env.MilestoneInc(milestone);

            var count = -1;
            foreach (var assertion in assertions) {
                count++;
                log.Info("======= Testing #" + count++);
                var epl = INDEX_CALLBACK_HOOK + (assertion.Hint == null ? "" : assertion.Hint) + eplQuery;
                epl += ", varagg as va";
                if (multistream) {
                    epl += ", SupportBeanSimple#lastevent";
                }

                epl += " where " + assertion.WhereClause;

                try {
                    var compiled = env.CompileWCheckedEx("@Name('s0')" + epl, path);
                    env.Deploy(compiled).AddListener("s0");
                }
                catch (EPCompileException ex) {
                    if (assertion.EventSendAssertion == null) {
                        // no assertion, expected
                        Assert.IsTrue(ex.Message.Contains("index hint busted"));
                        continue;
                    }

                    throw new EPException("Unexpected statement exception: " + ex.Message, ex);
                }

                // send multistream seed event
                env.SendEventBean(new SupportBeanSimple("", -1));

                // assert index and access
                assertion.EventSendAssertion.Invoke();
                var plan = SupportQueryPlanIndexHook.AssertJoinAndReset();

                TableLookupPlanForge tableLookupPlan;
                if (plan.ExecNodeSpecs[0] is TableLookupNodeForge) {
                    tableLookupPlan = ((TableLookupNodeForge) plan.ExecNodeSpecs[0]).TableLookupPlan;
                }
                else {
                    var lqp = (LookupInstructionQueryPlanNodeForge) plan.ExecNodeSpecs[0];
                    tableLookupPlan = lqp.LookupInstructions[0].LookupPlans[0];
                }

                Assert.AreEqual(assertion.ExpectedIndexName, tableLookupPlan.IndexNum[0].IndexName);
                Assert.AreEqual(assertion.ExpectedStrategy, tableLookupPlan.GetType());
                env.UndeployModuleContaining("s0");
            }

            env.UndeployAll();
        }