コード例 #1
0
ファイル: EPLSubselectIndex.cs プロジェクト: lanicon/nesper
        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();
        }
コード例 #2
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);
        }
コード例 #3
0
        private void RunAssertion(bool disableImplicitUniqueIdx, String uniqueFields, String whereClause, String backingTable, IndexAssertionEventSend assertion)
        {
            String eplUnique = INDEX_CALLBACK_HOOK + "select s1 as c0, " +
                               "(select s2 from SSB2.std:unique(" + uniqueFields + ") as ssb2 " + whereClause + ") as c1 " +
                               "from SSB1 as ssb1";

            if (disableImplicitUniqueIdx)
            {
                eplUnique = "@Hint('DISABLE_UNIQUE_IMPLICIT_IDX')" + eplUnique;
            }
            EPStatement stmtUnique = _epService.EPAdministrator.CreateEPL(eplUnique);

            stmtUnique.Events += _listener.Update;

            SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(0, null, backingTable);

            assertion.Invoke();

            stmtUnique.Dispose();
        }
コード例 #4
0
        public void TestUniqueIndexCorrelated()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            _epService.EPAdministrator.Configuration.AddEventType("S0", typeof(SupportBean_S0));
            String[] fields = "c0,c1".Split(',');

            // test std:unique
            String eplUnique = INDEX_CALLBACK_HOOK + "select id as c0, " +
                               "(select IntPrimitive from SupportBean.std:unique(TheString) where TheString = s0.p00) as c1 " +
                               "from S0 as s0";
            EPStatement stmtUnique = _epService.EPAdministrator.CreateEPL(eplUnique);

            stmtUnique.Events += _listener.Update;

            SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(0, null, BACKING_SINGLE_UNIQUE);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 4));

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "E2"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 10, 4 });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(11, "E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 11, 3 });

            stmtUnique.Dispose();

            // test std:firstunique
            String eplFirstUnique = INDEX_CALLBACK_HOOK + "select id as c0, " +
                                    "(select IntPrimitive from SupportBean.std:firstunique(TheString) where TheString = s0.p00) as c1 " +
                                    "from S0 as s0";
            EPStatement stmtFirstUnique = _epService.EPAdministrator.CreateEPL(eplFirstUnique);

            stmtFirstUnique.Events += _listener.Update;

            SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(0, null, BACKING_SINGLE_UNIQUE);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 4));

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "E2"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 10, 2 });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(11, "E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 11, 1 });

            stmtFirstUnique.Dispose();

            // test intersection std:firstunique
            String eplIntersection = INDEX_CALLBACK_HOOK + "select id as c0, " +
                                     "(select IntPrimitive from SupportBean.win:time(1).std:unique(TheString) where TheString = s0.p00) as c1 " +
                                     "from S0 as s0";
            EPStatement stmtIntersection = _epService.EPAdministrator.CreateEPL(eplIntersection);

            stmtIntersection.Events += _listener.Update;

            SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(0, null, BACKING_SINGLE_UNIQUE);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 2));
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 4));

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "E2"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 10, 4 });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(11, "E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 11, 3 });

            stmtIntersection.Dispose();

            // test grouped unique
            String eplGrouped = INDEX_CALLBACK_HOOK + "select id as c0, " +
                                "(select LongPrimitive from SupportBean.std:groupwin(TheString).std:unique(IntPrimitive) where TheString = s0.p00 and IntPrimitive = s0.id) as c1 " +
                                "from S0 as s0";
            EPStatement stmtGrouped = _epService.EPAdministrator.CreateEPL(eplGrouped);

            stmtGrouped.Events += _listener.Update;

            SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(0, null, BACKING_MULTI_UNIQUE);

            _epService.EPRuntime.SendEvent(MakeBean("E1", 1, 100));
            _epService.EPRuntime.SendEvent(MakeBean("E1", 2, 101));
            _epService.EPRuntime.SendEvent(MakeBean("E1", 1, 102));

            _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 1, 102L });

            stmtGrouped.Dispose();
        }
コード例 #5
0
        private static void AssertIndexChoice(
            RegressionEnvironment env,
            bool namedWindow,
            bool indexShare,
            string[] indexes,
            object[] preloadedEvents,
            string datawindow,
            IndexAssertion[] assertions)
        {
            var path = new RegressionPath();
            var epl = namedWindow
                ? "create window MyInfra." + datawindow + " as select * from SupportSimpleBeanOne"
                : "create table MyInfra(S1 string primary key, I1 int, D1 double, L1 long)";
            if (indexShare) {
                epl = "@Hint('enable_window_subquery_indexshare') " + epl;
            }

            env.CompileDeploy(epl, path);
            env.CompileDeploy("insert into MyInfra 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++);
                var consumeEpl = INDEX_CALLBACK_HOOK +
                                 "@Name('s0') " +
                                 (assertion.Hint ?? "") +
                                 "select *, " +
                                 "(select * from MyInfra where " +
                                 assertion.WhereClause +
                                 ") @eventbean as ssb1 from SupportSimpleBeanTwo as ssb2";

                EPCompiled compiled;
                try {
                    compiled = env.CompileWCheckedEx(consumeEpl, path);
                }
                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);
                }

                env.Deploy(compiled);

                // assert index and access
                SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(
                    0,
                    assertion.ExpectedIndexName,
                    assertion.IndexBackingClass);
                env.AddListener("s0");
                assertion.EventSendAssertion.Invoke();
                env.UndeployModuleContaining("s0");
            }

            env.UndeployAll();
        }
コード例 #6
0
ファイル: EPLSubselectIndex.cs プロジェクト: lanicon/nesper
            public void Run(RegressionEnvironment env)
            {
                var fields = new[] {"c0", "c1"};
                var milestone = new AtomicLong();

                // test std:unique
                SupportQueryPlanIndexHook.Reset();
                var eplUnique = INDEX_CALLBACK_HOOK +
                                "@Name('s0') select Id as c0, " +
                                "(select IntPrimitive from SupportBean#unique(TheString) where TheString = S0.P00) as c1 " +
                                "from SupportBean_S0 as S0";
                env.CompileDeployAddListenerMile(eplUnique, "s0", milestone.GetAndIncrement());

                SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(
                    SUBQUERY_NUM_FIRST,
                    null,
                    BACKING_SINGLE_UNIQUE);

                env.SendEventBean(new SupportBean("E1", 1));
                env.SendEventBean(new SupportBean("E2", 2));
                env.SendEventBean(new SupportBean("E1", 3));
                env.SendEventBean(new SupportBean("E2", 4));

                env.SendEventBean(new SupportBean_S0(10, "E2"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {10, 4});

                env.SendEventBean(new SupportBean_S0(11, "E1"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {11, 3});

                env.UndeployAll();

                // test std:firstunique
                SupportQueryPlanIndexHook.Reset();
                var eplFirstUnique = INDEX_CALLBACK_HOOK +
                                     "@Name('s0') select Id as c0, " +
                                     "(select IntPrimitive from SupportBean#firstunique(TheString) where TheString = S0.P00) as c1 " +
                                     "from SupportBean_S0 as S0";
                env.CompileDeployAddListenerMile(eplFirstUnique, "s0", milestone.GetAndIncrement());

                SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(
                    SUBQUERY_NUM_FIRST,
                    null,
                    BACKING_SINGLE_UNIQUE);

                env.SendEventBean(new SupportBean("E1", 1));
                env.SendEventBean(new SupportBean("E2", 2));
                env.SendEventBean(new SupportBean("E1", 3));
                env.SendEventBean(new SupportBean("E2", 4));

                env.SendEventBean(new SupportBean_S0(10, "E2"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {10, 2});

                env.SendEventBean(new SupportBean_S0(11, "E1"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {11, 1});

                env.UndeployAll();

                // test intersection std:firstunique
                SupportQueryPlanIndexHook.Reset();
                var eplIntersection = INDEX_CALLBACK_HOOK +
                                      "@Name('s0') select Id as c0, " +
                                      "(select IntPrimitive from SupportBean#time(1)#unique(TheString) where TheString = S0.P00) as c1 " +
                                      "from SupportBean_S0 as S0";
                env.CompileDeployAddListenerMile(eplIntersection, "s0", milestone.GetAndIncrement());

                SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(
                    SUBQUERY_NUM_FIRST,
                    null,
                    BACKING_SINGLE_UNIQUE);

                env.SendEventBean(new SupportBean("E1", 1));
                env.SendEventBean(new SupportBean("E1", 2));
                env.SendEventBean(new SupportBean("E1", 3));
                env.SendEventBean(new SupportBean("E2", 4));

                env.SendEventBean(new SupportBean_S0(10, "E2"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {10, 4});

                env.SendEventBean(new SupportBean_S0(11, "E1"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {11, 3});

                env.UndeployAll();

                // test grouped unique
                SupportQueryPlanIndexHook.Reset();
                var eplGrouped = INDEX_CALLBACK_HOOK +
                                 "@Name('s0') select Id as c0, " +
                                 "(select LongPrimitive from SupportBean#groupwin(TheString)#unique(IntPrimitive) where TheString = S0.P00 and IntPrimitive = S0.Id) as c1 " +
                                 "from SupportBean_S0 as S0";
                env.CompileDeployAddListenerMile(eplGrouped, "s0", milestone.GetAndIncrement());

                SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(SUBQUERY_NUM_FIRST, null, BACKING_MULTI_UNIQUE);

                env.SendEventBean(MakeBean("E1", 1, 100));
                env.SendEventBean(MakeBean("E1", 2, 101));
                env.SendEventBean(MakeBean("E1", 1, 102));

                env.SendEventBean(new SupportBean_S0(1, "E1"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {1, 102L});

                env.UndeployAll();
            }