Exemplo n.º 1
0
        public void TestInKeywordMultiIndex()
        {
            _epServiceRetained.EPAdministrator.Configuration.AddEventType <SupportBean_S0>("S0");

            String stmtText = INDEX_CALLBACK_HOOK + "select * from S0 s0, " +
                              " sql:MyDB ['select mycol1, mycol2, mycol3 from mytesttable_large'] as s1 " +
                              " where p00 in (mycol2, mycol1)";
            EPStatement statement = _epServiceRetained.EPAdministrator.CreateEPL(stmtText);

            _listener         = new SupportUpdateListener();
            statement.Events += _listener.Update;

            QueryPlanIndexDescHistorical historical = SupportQueryPlanIndexHook.AssertHistoricalAndReset();

            Assert.That(historical.IndexName, Is.EqualTo(typeof(PollResultIndexingStrategyIndexSingleArray).Name));
            Assert.That(historical.StrategyName, Is.EqualTo(typeof(HistoricalIndexLookupStrategyInKeywordMulti).Name));

            var delta = PerformanceObserver.TimeMillis(
                () =>
            {
                for (int i = 0; i < 2000; i++)
                {
                    _epServiceRetained.EPRuntime.SendEvent(new SupportBean_S0(i, "815"));
                    Assert.AreEqual(815, _listener.AssertOneGetNewAndReset().Get("s1.mycol3"));
                }
            });

            Log.Info("delta=" + delta);
            Assert.That(delta, Is.LessThan(500));
        }
Exemplo n.º 2
0
        private void RunAssertion(CaseEnum caseEnum, String uniqueFields, String whereClause, bool unique, IndexAssertionEventSend assertion)
        {
            String eplUnique = INDEX_CALLBACK_HOOK +
                               "select * from ";

            if (caseEnum == CaseEnum.UNIDIRECTIONAL || caseEnum == CaseEnum.UNIDIRECTIONAL_3STREAM)
            {
                eplUnique += "SSB1 as ssb1 unidirectional ";
            }
            else
            {
                eplUnique += "SSB1#lastevent as ssb1 ";
            }
            eplUnique += ", SSB2#unique(" + uniqueFields + ") as ssb2 ";
            if (caseEnum == CaseEnum.UNIDIRECTIONAL_3STREAM || caseEnum == CaseEnum.MULTIDIRECTIONAL_3STREAM)
            {
                eplUnique += ", SupportBean#lastevent ";
            }
            eplUnique += whereClause;

            EPStatement stmtUnique = _epService.EPAdministrator.CreateEPL(eplUnique);

            stmtUnique.Events += _listener.Update;

            SupportQueryPlanIndexHook.AssertJoinOneStreamAndReset(unique);

            _epService.EPRuntime.SendEvent(new SupportBean("JOINEVENT", 1));
            assertion.Invoke();

            stmtUnique.Dispose();
        }
Exemplo n.º 3
0
            public void Run(RegressionEnvironment env)
            {
                var epl =
                    "@Name('win') create window MyRectWindow#keepall as (Id string, rx double, ry double, rw double, rh double);\n" +
                    "@Name('insert') insert into MyRectWindow select Id, X as rx, Y as ry, Width as rw, Height as rh from SupportSpatialEventRectangle;\n" +
                    "@Name('Idx') create unique index Idx on MyRectWindow( (rx, ry, rw, rh) mxcifquadtree(0, 0, 100, 100));\n" +
                    IndexBackingTableInfo.INDEX_CALLBACK_HOOK +
                    "@Name('out') on SupportSpatialAABB select mpw.Id as c0 from MyRectWindow as mpw where rectangle(rx, ry, rw, rh).intersects(rectangle(X, Y, Width, Height));\n";
                env.CompileDeploy(epl).AddListener("out");

                SupportQueryPlanIndexHook.AssertOnExprTableAndReset(
                    "Idx",
                    "unique hash={} btree={} advanced={mxcifquadtree(rx,ry,rw,rh)}");

                SendEventRectangle(env, "P1", 10, 15, 1, 2);
                try {
                    SendEventRectangle(env, "P1", 10, 15, 1, 2);
                    Assert.Fail();
                }
                catch (Exception ex) { // we have a handler
                    SupportMessageAssertUtil.AssertMessage(
                        ex,
                        "Unexpected exception in statement 'win': Unique index violation, index 'Idx' is a unique index and key '(10.0d,15.0d,1.0d,2.0d)' already exists");
                }

                env.UndeployAll();
            }
Exemplo n.º 4
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeployWBusPublicType("create schema Geofence(x double, y double, vin string)", path);

                env.CompileDeploy(
                    "create table Regions(regionId string primary key, rx double, ry double, rwidth double, rheight double)",
                    path);
                env.CompileDeploy(
                    "create index RectangleIndex on Regions((rx, ry, rwidth, rheight) mxcifquadtree(0, 0, 10, 12))",
                    path);
                env.CompileDeploy(
                    "@Name('s0') " +
                    IndexBackingTableInfo.INDEX_CALLBACK_HOOK +
                    "on Geofence as vin insert into VINWithRegion select regionId, vin from Regions where rectangle(rx, ry, rwidth, rheight).intersects(rectangle(vin.x, vin.y, 0, 0))",
                    path);
                env.AddListener("s0");

                SupportQueryPlanIndexHook.AssertOnExprTableAndReset(
                    "RectangleIndex",
                    "non-unique hash={} btree={} advanced={mxcifquadtree(rx,ry,rwidth,rheight)}");

                env.CompileExecuteFAF("insert into Regions values ('R1', 2, 2, 5, 5)", path);
                env.SendEventMap(CollectionUtil.PopulateNameValueMap("x", 3d, "y", 3d, "vin", "V1"), "Geofence");

                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"vin", "regionId"},
                    new object[] {"V1", "R1"});

                env.UndeployAll();
            }
Exemplo n.º 5
0
 private static void RunAssertionFAF(
     RegressionEnvironment env,
     RegressionPath path,
     double x,
     double y,
     double width,
     double height,
     bool expected)
 {
     var result = env.CompileExecuteFAF(
         IndexBackingTableInfo.INDEX_CALLBACK_HOOK +
         "select Id as c0 from MyTable where rectangle(tx, ty, tw, th).intersects(rectangle(" +
         x +
         ", " +
         y +
         ", " +
         width +
         ", " +
         height +
         "))",
         path);
     SupportQueryPlanIndexHook.AssertFAFAndReset("MyIdxCIFQuadTree", "EventTableQuadTreeMXCIF");
     if (expected) {
         EPAssertionUtil.AssertPropsPerRowAnyOrder(
             result.Array,
             new[] {"c0"},
             new[] {
                 new object[] {"R1"}
             });
     }
     else {
         Assert.AreEqual(0, result.Array.Length);
     }
 }
Exemplo n.º 6
0
        private static void TryAssertion(
            RegressionEnvironment env,
            bool disableImplicitUniqueIdx,
            string uniqueFields,
            string whereClause,
            string backingTable,
            IndexAssertionEventSend assertion)
        {
            SupportQueryPlanIndexHook.Reset();
            var eplUnique = "@Name('s0')" +
                            INDEX_CALLBACK_HOOK +
                            "select S1 as c0, " +
                            "(select S2 from SupportSimpleBeanTwo#unique(" +
                            uniqueFields +
                            ") as ssb2 " +
                            whereClause +
                            ") as c1 " +
                            "from SupportSimpleBeanOne as ssb1";
            if (disableImplicitUniqueIdx) {
                eplUnique = "@Hint('DISABLE_UNIQUE_IMPLICIT_IDX')" + eplUnique;
            }

            env.CompileDeploy(eplUnique).AddListener("s0");

            SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(SUBQUERY_NUM_FIRST, null, backingTable);

            assertion.Invoke();

            env.UndeployAll();
        }
        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();
        }
Exemplo n.º 8
0
        private void RunAssertionEventIndexExpression(EPServiceProvider epService)
        {
            epService.EPAdministrator.CreateEPL("create table MyTable(id string primary key, tx double, ty double)");
            epService.EPRuntime.ExecuteQuery("insert into MyTable values ('P1', 50, 30)");
            epService.EPRuntime.ExecuteQuery("insert into MyTable values ('P2', 50, 28)");
            epService.EPRuntime.ExecuteQuery("insert into MyTable values ('P3', 50, 30)");
            epService.EPRuntime.ExecuteQuery("insert into MyTable values ('P4', 49, 29)");
            epService.EPAdministrator.CreateEPL("create index MyIdxWithExpr on MyTable( (tx*10, ty*10) pointregionquadtree(0, 0, 1000, 1000))");

            var eplOne       = IndexBackingTableInfo.INDEX_CALLBACK_HOOK + "on SupportSpatialAABB select tbl.id as c0 from MyTable as tbl where point(tx, ty).inside(rectangle(x, y, width, height))";
            var statementOne = epService.EPAdministrator.CreateEPL(eplOne);
            var listener     = new SupportUpdateListener();

            statementOne.Events += listener.Update;
            SupportQueryPlanIndexHook.AssertOnExprTableAndReset(null, null);
            AssertRectanglesManyRow(epService, listener, BOXES, "P4", "P1,P2,P3", null, null, "P1,P2,P3,P4");
            statementOne.Dispose();

            var eplTwo       = IndexBackingTableInfo.INDEX_CALLBACK_HOOK + "on SupportSpatialAABB select tbl.id as c0 from MyTable as tbl where point(tx*10, tbl.ty*10).inside(rectangle(x, y, width, height))";
            var statementTwo = epService.EPAdministrator.CreateEPL(eplTwo);

            statementTwo.Events += listener.Update;
            SupportQueryPlanIndexHook.AssertOnExprTableAndReset("MyIdxWithExpr", "non-unique hash={} btree={} advanced={pointregionquadtree(tx*10,ty*10)}");
            AssertRectanglesManyRow(epService, listener, BOXES, null, null, null, null, null);
            AssertRectanglesManyRow(epService, listener, Collections.SingletonList(new BoundingBox(500, 300, 501, 301)), "P1,P3");
            statementTwo.Dispose();

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 9
0
        private void RunAssertionEventIndexOnTriggerTable(EPServiceProvider epService)
        {
            var epl =
                "create table MyPointTable(my_x double primary key, my_y double primary key, my_id string);\n" +
                "@Audit create index MyIndex on MyPointTable( (my_x, my_y) pointregionquadtree(0, 0, 100, 100));\n" +
                "on SupportSpatialPoint ssp merge MyPointTable where ssp.px = my_x and ssp.py = my_y when not matched then insert select px as my_x, py as my_y, id as my_id;\n" +
                IndexBackingTableInfo.INDEX_CALLBACK_HOOK +
                "@Audit @Name('s0') on SupportSpatialAABB select my_id as c0 from MyPointTable as c0 where point(my_x, my_y).inside(rectangle(x, y, width, height))";
            var deploymentId = epService.EPAdministrator.DeploymentAdmin.ParseDeploy(epl).DeploymentId;

            var stmt     = epService.EPAdministrator.GetStatement("s0");
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SupportQueryPlanIndexHook.AssertOnExprTableAndReset("MyIndex", "non-unique hash={} btree={} advanced={pointregionquadtree(my_x,my_y)}");

            SendPoint(epService, "P1", 55, 45);
            AssertRectanglesManyRow(epService, listener, BOXES, null, "P1", null, null, "P1");

            SendPoint(epService, "P2", 45, 45);
            AssertRectanglesManyRow(epService, listener, BOXES, "P2", "P1", null, null, "P1,P2");

            SendPoint(epService, "P3", 55, 55);
            AssertRectanglesManyRow(epService, listener, BOXES, "P2", "P1", null, "P3", "P1,P2,P3");

            epService.EPRuntime.ExecuteQuery("delete from MyPointTable where my_x = 55 and my_y = 45");
            SendPoint(epService, "P4", 45, 55);
            AssertRectanglesManyRow(epService, listener, BOXES, "P2", null, "P4", "P3", "P2,P3,P4");

            epService.EPAdministrator.DeploymentAdmin.Undeploy(deploymentId);
        }
        private void RunAssertionInKeywordMultiIndex(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType("S0", typeof(SupportBean_S0));

            var stmtText = INDEX_CALLBACK_HOOK + "select * from S0 s0, " +
                           " sql:MyDB ['select mycol1, mycol2, mycol3 from mytesttable_large'] as s1 " +
                           " where p00 in (mycol2, mycol1)";
            var statement = epService.EPAdministrator.CreateEPL(stmtText);
            var listener  = new SupportUpdateListener();

            statement.AddListener(listener);

            var historical = SupportQueryPlanIndexHook.AssertHistoricalAndReset();

            Assert.AreEqual(typeof(PollResultIndexingStrategyIndexSingleArray).Name, historical.IndexName);
            Assert.AreEqual(typeof(HistoricalIndexLookupStrategyInKeywordMulti).Name, historical.StrategyName);

            var startTime = PerformanceObserver.MilliTime;

            for (var i = 0; i < 2000; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBean_S0(i, "815"));
                Assert.AreEqual(815, listener.AssertOneGetNewAndReset().Get("s1.mycol3"));
            }

            var endTime = PerformanceObserver.MilliTime;
            var delta   = endTime - startTime;

            Log.Info("delta=" + delta);
            Assert.IsTrue(delta < 500, "Delta=" + delta);

            statement.Dispose();
        }
Exemplo n.º 11
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy("create window MyWindow#keepall as (p0 string, p1 int);", path);
                env.CompileDeploy("create unique index MyIndex on MyWindow(p0);", path);
                env.CompileDeploy(
                    INDEX_CALLBACK_HOOK +
                    "@Name('s0') on SupportBean_S0 as S0 select p0, p1 from MyWindow as win where win.p0 = S0.P00;",
                    path);
                env.AddListener("s0");

                SupportQueryPlanIndexHook.AssertOnExprTableAndReset(
                    "MyIndex",
                    "unique hash={p0(string)} btree={} advanced={}");

                env.CompileExecuteFAF("insert into MyWindow select 'a' as p0, 1 as p1", path);

                env.SendEventBean(new SupportBean_S0(1, "a"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"p0", "p1"},
                    new object[] {"a", 1});

                env.UndeployAll();
            }
Exemplo n.º 12
0
        private void RunAssertionDocSample(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType(typeof(AEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(BEvent));

            var hints = new string[] {
                "@Hint('Exclude_plan(true)')",
                "@Hint('Exclude_plan(opname=\"equals\")')",
                "@Hint('Exclude_plan(opname=\"equals\" and from_streamname=\"a\")')",
                "@Hint('Exclude_plan(opname=\"equals\" and from_streamname=\"b\")')",
                "@Hint('Exclude_plan(exprs[0]=\"aprop\")')"
            };

            foreach (string hint in hints)
            {
                epService.EPAdministrator.CreateEPL("@Audit " + hint +
                                                    "select * from AEvent#keepall as a, BEvent#keepall as b where aprop = bprop");
            }

            // test subquery
            SupportQueryPlanIndexHook.Reset();
            epService.EPAdministrator.CreateEPL(INDEX_CALLBACK_HOOK + "@Hint('Exclude_plan(true)') select (select * from S0#unique(p00) as s0 where s1.p10 = p00) from S1 as s1");
            QueryPlanIndexDescSubquery subq = SupportQueryPlanIndexHook.GetAndResetSubqueries()[0];

            Assert.AreEqual(typeof(SubordFullTableScanLookupStrategyFactory).Name, subq.TableLookupStrategy);

            // test named window
            epService.EPAdministrator.CreateEPL("create window S0Window#keepall as S0");
            epService.EPAdministrator.CreateEPL(INDEX_CALLBACK_HOOK + "@Hint('Exclude_plan(true)') on S1 as s1 select * from S0Window as s0 where s1.p10 = s0.p00");
            QueryPlanIndexDescOnExpr onExpr = SupportQueryPlanIndexHook.GetAndResetOnExpr();

            Assert.AreEqual(typeof(SubordWMatchExprLookupStrategyFactoryAllFiltered).Name, onExpr.StrategyName);

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 13
0
        private void RunAssertionMultipleIndexHints(EPServiceProvider epService, bool namedWindow)
        {
            string eplCreate = namedWindow ?
                               "@Hint('enable_window_subquery_indexshare') create window MyInfraMIH#keepall as select * from SSB1" :
                               "create table MyInfraMIH(s1 string primary key, i1 int  primary key, d1 double primary key, l1 long primary key)";

            epService.EPAdministrator.CreateEPL(eplCreate);
            epService.EPAdministrator.CreateEPL("create unique index I1 on MyInfraMIH (s1)");
            epService.EPAdministrator.CreateEPL("create unique index I2 on MyInfraMIH (i1)");

            epService.EPAdministrator.CreateEPL(INDEX_CALLBACK_HOOK +
                                                "@Hint('index(subquery(1), I1, bust)')\n" +
                                                "@Hint('index(subquery(0), I2, bust)')\n" +
                                                "select " +
                                                "(select * from MyInfraMIH where s1 = ssb2.s2 and i1 = ssb2.i2) as sub1," +
                                                "(select * from MyInfraMIH where i1 = ssb2.i2 and s1 = ssb2.s2) as sub2 " +
                                                "from SSB2 ssb2");
            List <QueryPlanIndexDescSubquery> subqueries = SupportQueryPlanIndexHook.GetAndResetSubqueries();

            subqueries.Sort((o1, o2) => o1.Tables[0].IndexName.CompareTo(o2.Tables[0].IndexName));
            SupportQueryPlanIndexHook.AssertSubquery(subqueries[0], 1, "I1", "unique hash={s1(string)} btree={} advanced={}");
            SupportQueryPlanIndexHook.AssertSubquery(subqueries[1], 0, "I2", "unique hash={i1(int)} btree={} advanced={}");

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyInfraMIH", false);
        }
Exemplo n.º 14
0
        private void RunAssertionEventIndexChoiceOfTwo(EPServiceProvider epService)
        {
            var epl =
                "create table MyPointTable(" +
                " id string primary key," +
                " x1 double, y1 double, \n" +
                " x2 double, y2 double);\n" +
                "create index Idx1 on MyPointTable( (x1, y1) pointregionquadtree(0, 0, 100, 100));\n" +
                "create index Idx2 on MyPointTable( (x2, y2) pointregionquadtree(0, 0, 100, 100));\n" +
                "on SupportSpatialDualPoint dp merge MyPointTable t where dp.id = t.id when not matched then insert select dp.id as id,x1,y1,x2,y2;\n";
            var deploymentId = epService.EPAdministrator.DeploymentAdmin.ParseDeploy(epl).DeploymentId;

            var textOne      = IndexBackingTableInfo.INDEX_CALLBACK_HOOK + "on SupportSpatialAABB select tbl.id as c0 from MyPointTable as tbl where point(x1, y1).inside(rectangle(x, y, width, height))";
            var statementOne = epService.EPAdministrator.CreateEPL(textOne);
            var listener     = new SupportUpdateListener();

            statementOne.Events += listener.Update;
            SupportQueryPlanIndexHook.AssertOnExprTableAndReset("Idx1", "non-unique hash={} btree={} advanced={pointregionquadtree(x1,y1)}");

            var textTwo      = IndexBackingTableInfo.INDEX_CALLBACK_HOOK + "on SupportSpatialAABB select tbl.id as c0 from MyPointTable as tbl where point(tbl.x2, y2).inside(rectangle(x, y, width, height))";
            var statementTwo = epService.EPAdministrator.CreateEPL(textTwo);

            statementTwo.Events += listener.Update;
            SupportQueryPlanIndexHook.AssertOnExprTableAndReset("Idx2", "non-unique hash={} btree={} advanced={pointregionquadtree(x2,y2)}");

            epService.EPRuntime.SendEvent(new SupportSpatialDualPoint("P1", 10, 10, 60, 60));
            epService.EPRuntime.SendEvent(new SupportSpatialDualPoint("P2", 55, 20, 4, 88));

            AssertRectanglesSingleValue(epService, listener, BOXES, "P1", "P2", "P2", "P1", "P1");

            statementOne.Dispose();
            statementTwo.Dispose();
            epService.EPAdministrator.DeploymentAdmin.Undeploy(deploymentId);
        }
Exemplo n.º 15
0
        private void RunAssertionMultipleIndexHints(bool namedWindow)
        {
            var eplCreate = namedWindow ?
                            "@Hint('enable_window_subquery_indexshare') create window MyInfra#keepall as select * from SSB1" :
                            "create table MyInfra(S1 String primary key, I1 int  primary key, D1 double primary key, L1 long primary key)";

            _epService.EPAdministrator.CreateEPL(eplCreate);
            _epService.EPAdministrator.CreateEPL("create unique index I1 on MyInfra (S1)");
            _epService.EPAdministrator.CreateEPL("create unique index I2 on MyInfra (I1)");

            _epService.EPAdministrator.CreateEPL(INDEX_CALLBACK_HOOK +
                                                 "@Hint('index(subquery(1), I1, bust)')\n" +
                                                 "@Hint('index(subquery(0), I2, bust)')\n" +
                                                 "select " +
                                                 "(select * from MyInfra where S1 = ssb2.S2 and I1 = ssb2.I2) as sub1," +
                                                 "(select * from MyInfra where I1 = ssb2.I2 and S1 = ssb2.S2) as sub2 " +
                                                 "from SSB2 ssb2");
            var subqueries = SupportQueryPlanIndexHook.GetAndResetSubqueries();

            Collections.SortInPlace(subqueries, (o1, o2) => o1.Tables[0].IndexName.CompareTo(o2.Tables[0].IndexName));
            SupportQueryPlanIndexHook.AssertSubquery(subqueries[0], 1, "I1", "unique hash={S1(string)} btree={}");
            SupportQueryPlanIndexHook.AssertSubquery(subqueries[1], 0, "I2", "unique hash={I1(int)} btree={}");

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false);
        }
Exemplo n.º 16
0
            public void Run(RegressionEnvironment env)
            {
                var stmtText = "@Name('s0') " +
                               INDEX_CALLBACK_HOOK +
                               "select * from SupportBean_S0 S0, " +
                               " sql:MyDBWithLRU100000 ['select mycol1, mycol2, mycol3 from mytesttable_large'] as S1 " +
                               " where P00 in (mycol2, mycol1)";
                env.CompileDeploy(stmtText).AddListener("s0");

                var historical = SupportQueryPlanIndexHook.AssertHistoricalAndReset();
                Assert.AreEqual(typeof(PollResultIndexingStrategyInKeywordMultiForge).Name, historical.IndexName);
                Assert.AreEqual(typeof(HistoricalIndexLookupStrategyInKeywordMultiForge).Name, historical.StrategyName);

                var startTime = PerformanceObserver.MilliTime;
                for (var i = 0; i < 2000; i++) {
                    env.SendEventBean(new SupportBean_S0(i, "815"));
                    Assert.AreEqual(815, env.Listener("s0").AssertOneGetNewAndReset().Get("S1.mycol3"));
                }

                var endTime = PerformanceObserver.MilliTime;
                var delta = endTime - startTime;
                // log.info("delta=" + delta);
                Assert.That(delta, Is.LessThan(500), "Delta=" + delta);

                env.UndeployAll();
            }
Exemplo n.º 17
0
 public void Run(RegressionEnvironment env)
 {
     SupportQueryPlanIndexHook.Reset();
     var epl = "@Name('s0') " +
               INDEX_CALLBACK_HOOK +
               "select S1.Id as c0," +
               "(select * from SupportBean_S0#keepall as S0 " +
               "  where S0.P00 in (S1.P10, SupportBean_S1.P11) and S0.P01 in (S1.P12, SupportBean_S1.P13))" +
               ".selectFrom(a->SupportBean_S0.Id) as c1 " +
               " from SupportBean_S1 as S1";
     env.CompileDeploy(epl).AddListener("s0");
     var subquery = SupportQueryPlanIndexHook.AssertSubqueryAndReset();
     Assert.AreEqual(typeof(SubordInKeywordSingleTableLookupStrategyFactoryForge).Name, subquery.TableLookupStrategy);
     // single row tests
     env.SendEventBean(new SupportBean_S0(100, "a", "c"));
     env.SendEventBean(new SupportBean_S1(1, "a1", "b", "c", "d"));
     AssertSubqueryC0C1(env, 1, null);
     env.SendEventBean(new SupportBean_S1(2, "a", "b", "x", "d"));
     AssertSubqueryC0C1(env, 2, null);
     env.SendEventBean(new SupportBean_S1(3, "a", "b", "c", "d"));
     AssertSubqueryC0C1(env, 3, new int?[] {100});
     env.SendEventBean(new SupportBean_S1(4, "x", "a", "x", "c"));
     AssertSubqueryC0C1(env, 4, new int?[] {100});
     // 2-rows available tests
     env.SendEventBean(new SupportBean_S0(101, "a", "d"));
     env.SendEventBean(new SupportBean_S1(10, "a1", "b", "c", "d"));
     AssertSubqueryC0C1(env, 10, null);
     env.SendEventBean(new SupportBean_S1(11, "a", "b", "x", "c1"));
     AssertSubqueryC0C1(env, 11, null);
     env.SendEventBean(new SupportBean_S1(12, "a", "b", "c", "d"));
     AssertSubqueryC0C1(env, 12, new int?[] {100, 101});
     env.SendEventBean(new SupportBean_S1(13, "x", "a", "x", "c"));
     AssertSubqueryC0C1(env, 13, new int?[] {100});
     env.SendEventBean(new SupportBean_S1(14, "x", "a", "d", "x"));
     AssertSubqueryC0C1(env, 14, new int?[] {101});
     // 3-rows available tests
     env.SendEventBean(new SupportBean_S0(102, "b", "c"));
     env.SendEventBean(new SupportBean_S1(20, "a1", "b", "c1", "d"));
     AssertSubqueryC0C1(env, 20, null);
     env.SendEventBean(new SupportBean_S1(21, "a", "b", "x", "c1"));
     AssertSubqueryC0C1(env, 21, null);
     env.SendEventBean(new SupportBean_S1(22, "a", "b", "c", "d"));
     AssertSubqueryC0C1(env, 22, new int?[] {100, 101, 102});
     env.SendEventBean(new SupportBean_S1(23, "b", "a", "x", "c"));
     AssertSubqueryC0C1(env, 23, new int?[] {100, 102});
     env.SendEventBean(new SupportBean_S1(24, "b", "a", "d", "c"));
     AssertSubqueryC0C1(env, 24, new int?[] {100, 101, 102});
     env.SendEventBean(new SupportBean_S1(25, "b", "x", "x", "c"));
     AssertSubqueryC0C1(env, 25, new int?[] {102});
     env.UndeployAll();
     // test coercion absence - types the same
     var eplCoercion = INDEX_CALLBACK_HOOK +
                       "select *," +
                       "(select * from SupportBean#keepall as sb where sb.LongPrimitive in (S0.Id)) from SupportBean_S0 as S0";
     env.CompileDeploy(eplCoercion);
     var subqueryCoercion = SupportQueryPlanIndexHook.AssertSubqueryAndReset();
     Assert.AreEqual(typeof(SubordFullTableScanLookupStrategyFactoryForge).Name, subqueryCoercion.TableLookupStrategy);
     env.UndeployAll();
 }
Exemplo n.º 18
0
        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();
        }
Exemplo n.º 19
0
        private void AssertIndexChoiceJoin(bool namedWindow, string[] indexes, object[] preloadedEvents, string datawindowOne, string datawindowTwo, params IndexAssertion[] assertions)
        {
            if (namedWindow)
            {
                _epService.EPAdministrator.CreateEPL("create window W1." + datawindowOne + " as SSB1");
                _epService.EPAdministrator.CreateEPL("create window W2." + datawindowTwo + " as SSB2");
            }
            else
            {
                _epService.EPAdministrator.CreateEPL("create table W1 (s1 String primary key, i1 int primary key, d1 double primary key, l1 long primary key)");
                _epService.EPAdministrator.CreateEPL("create table W2 (s2 String primary key, i2 int primary key, d2 double primary key, l2 long primary key)");
            }
            _epService.EPAdministrator.CreateEPL("insert into W1 select s1,i1,d1,l1 from SSB1");
            _epService.EPAdministrator.CreateEPL("insert into W2 select s2,i2,d2,l2 from SSB2");

            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 ?? "") +
                          "select * from W1 as w1, W2 as w2 " +
                          "where " + assertion.WhereClause;
                EPOnDemandQueryResult result;
                try {
                    result = _epService.EPRuntime.ExecuteQuery(epl);
                }
                catch (EPStatementException ex) {
                    Log.Error("Failed to process:" + ex.Message, 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);
                }

                // assert index and access
                SupportQueryPlanIndexHook.AssertJoinAllStreamsAndReset(assertion.IsUnique ?? false);
                assertion.FAFAssertion.Invoke(result);
            }

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("W1", false);
            _epService.EPAdministrator.Configuration.RemoveEventType("W2", false);
        }
Exemplo n.º 20
0
        public void SetUp()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.LoggingConfig.IsEnableQueryPlan = true;
            _epService = EPServiceProviderManager.GetDefaultProvider(config);
            _epService.Initialize();
            _listener = new SupportUpdateListener();
            SupportQueryPlanIndexHook.Reset();
        }
Exemplo n.º 21
0
        private void AssertIndexChoice(bool namedWindow, bool indexShare, string[] indexes, object[] preloadedEvents, string datawindow, IndexAssertion[] assertions)
        {
            var epl = namedWindow ?
                      "create window MyInfra." + datawindow + " as select * from SSB1" :
                      "create table MyInfra(S1 string primary key, I1 int, D1 double, L1 long)";

            if (indexShare)
            {
                epl = "@Hint('enable_window_subquery_indexshare') " + epl;
            }
            _epService.EPAdministrator.CreateEPL(epl);
            _epService.EPAdministrator.CreateEPL("insert into MyInfra select * from SSB1");
            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 consumeEpl = INDEX_CALLBACK_HOOK +
                                 (assertion.Hint ?? "") + "select *, " +
                                 "(select * from MyInfra where " + assertion.WhereClause + ") @eventbean as ssb1 from SSB2 as ssb2";

                EPStatement consumeStmt = null;
                try {
                    consumeStmt = _epService.EPAdministrator.CreateEPL(consumeEpl);
                }
                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);
                }

                // assert index and access
                SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(0, assertion.ExpectedIndexName, assertion.IndexBackingClass);
                consumeStmt.AddListener(_listenerStmtOne);
                assertion.EventSendAssertion.Invoke();
                consumeStmt.Dispose();
            }

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false);
        }
Exemplo n.º 22
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();
 }
Exemplo n.º 23
0
        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();
        }
Exemplo n.º 24
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();
        }
Exemplo n.º 25
0
 public override void Configure(Configuration configuration)
 {
     configuration.EngineDefaults.Logging.IsEnableQueryPlan = true;
     configuration.AddPlugInVirtualDataWindow("test", "vdw", typeof(SupportVirtualDWFactory).FullName);
     configuration.AddPlugInVirtualDataWindow("invalid", "invalid", typeof(InvalidTypeForTest));
     configuration.AddPlugInVirtualDataWindow("test", "testnoindex", typeof(SupportVirtualDWInvalidFactory));
     configuration.AddPlugInVirtualDataWindow("test", "exceptionvdw", typeof(SupportVirtualDWExceptionFactory));
     configuration.AddEventType <SupportBean>();
     configuration.AddEventType("SupportBean_ST0", typeof(SupportBean_ST0));
     configuration.AddEventType("SupportBeanRange", typeof(SupportBeanRange));
     SupportQueryPlanIndexHook.Reset();
 }
Exemplo n.º 26
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();
 }
Exemplo n.º 27
0
        private void AssertIndexChoice(
            EPServiceProvider epService,
            bool namedWindow,
            string[] indexes,
            object[] preloadedEvents,
            string datawindow,
            IndexAssertion[] assertions)
        {
            string eplCreate = namedWindow ?
                               "create window MyInfra." + datawindow + " as SSB1" :
                               "create table MyInfra(s1 string primary key, i1 int primary key, d1 double primary key, l1 long primary key)";

            epService.EPAdministrator.CreateEPL(eplCreate);
            epService.EPAdministrator.CreateEPL("insert into MyInfra select s1,i1,d1,l1 from SSB1");
            foreach (string index in indexes)
            {
                epService.EPAdministrator.CreateEPL(index);
            }
            foreach (Object @event in preloadedEvents)
            {
                epService.EPRuntime.SendEvent(@event);
            }

            int count = 0;

            foreach (IndexAssertion assertion in assertions)
            {
                Log.Info("======= Testing #" + count++);
                string epl = INDEX_CALLBACK_HOOK +
                             (assertion.Hint == null ? "" : assertion.Hint) +
                             "select * from MyInfra where " + assertion.WhereClause;
                EPOnDemandQueryResult result;
                try {
                    result = epService.EPRuntime.ExecuteQuery(epl);
                } 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);
                }

                // assert index and access
                SupportQueryPlanIndexHook.AssertFAFAndReset(assertion.ExpectedIndexName, assertion.IndexBackingClass);
                assertion.FAFAssertion.Invoke(result);
            }

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false);
        }
Exemplo n.º 28
0
        public void SetUp()
        {
            var config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.LoggingConfig.IsEnableQueryPlan = true;
            _epService = EPServiceProviderManager.GetDefaultProvider(config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, this.GetType(), GetType().FullName);
            }
            SupportQueryPlanIndexHook.Reset();
        }
Exemplo n.º 29
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));
        }
Exemplo n.º 30
0
            private static void AssertIndexChoice(
                RegressionEnvironment env,
                string[] indexes,
                object[] preloadedEvents,
                string datawindow,
                params IndexAssertion[] assertions)
            {
                var path = new RegressionPath();
                env.CompileDeploy("create window MyWindow." + datawindow + " as SupportSimpleBeanOne", path);
                env.CompileDeploy("insert into MyWindow select * from SupportSimpleBeanOne", path);
                foreach (var index in indexes) {
                    env.CompileDeploy(index, path);
                }

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

                var count = 0;
                foreach (var assertion in assertions) {
                    log.Info("======= Testing #" + count);
                    count++;

                    var epl = INDEX_CALLBACK_HOOK +
                              (assertion.Hint == null ? "" : assertion.Hint) +
                              "select * " +
                              "from SupportSimpleBeanTwo as ssb2 unidirectional, MyWindow as ssb1 " +
                              "where " +
                              assertion.WhereClause;

                    try {
                        env.CompileDeploy("@Name('s0')" + epl, path).AddListener("s0");
                    }
                    catch (EPCompileExceptionItem 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);
                    }

                    // assert index and access
                    SupportQueryPlanIndexHook.AssertJoinOneStreamAndReset(assertion.Unique);
                    assertion.EventSendAssertion.Invoke();
                    env.UndeployModuleContaining("s0");
                }

                env.UndeployAll();
            }