Exemplo n.º 1
0
        private void RunPlainPropertyWDatetimeEtc(bool grouped, bool soda)
        {
            var myBean = typeof(MyBean).FullName.Replace('+', '$');

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, "create objectarray schema MyEvent as (p0 string)");
            SupportModelHelper.CreateByCompileOrParse(_epService, soda, "create objectarray schema PopulateEvent as (" +
                                                      "key string" +
                                                      ", ts long" +
                                                      ", mb " + myBean +
                                                      ", mbarr " + myBean + "[]" +
                                                      ", me MyEvent, mearr MyEvent[])");

            var eplDeclare = "create table varagg (key string" + (grouped ? " primary key" : "") +
                             ", ts long" +
                             ", mb " + myBean +
                             ", mbarr " + myBean + "[]" +
                             ", me MyEvent, mearr MyEvent[])";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplDeclare);

            var key       = grouped ? "[\"E1\"]" : "";
            var eplSelect = "select " +
                            "varagg" + key + ".ts.getMinuteOfHour() as c0, " +
                            "varagg" + key + ".mb.get_MyProperty() as c1, " +
                            "varagg" + key + ".mbarr.takeLast(1) as c2, " +
                            "varagg" + key + ".me.p0 as c3, " +
                            "varagg" + key + ".mearr.selectFrom(i => i.p0) as c4 " +
                            "from SupportBean_S0";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplSelect).AddListener(_listener);

            var eplMerge = "on PopulateEvent merge varagg " +
                           "when not matched then insert " +
                           "select key, ts, mb, mbarr, me, mearr";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplMerge);

            var @event = MakePopulateEvent();

            _epService.EPRuntime.SendEvent(@event, "PopulateEvent");
            _epService.EPRuntime.SendEvent(new SupportBean_S0(0, "E1"));
            var output = _listener.AssertOneGetNewAndReset();

            EPAssertionUtil.AssertProps(output, "c0,c1,c3".Split(','),
                                        new object[] { 55, "x", "p0value" });
            Assert.AreEqual(1, ((ICollection <object>)output.Get("c2")).Count);
            Assert.AreEqual("[0_p0, 1_p0]", output.Get("c4").Render());

            _epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 2
0
        private void RunAssertionEventIndexOnTriggerNWInsertRemove(EPServiceProvider epService, bool soda)
        {
            SupportModelHelper.CreateByCompileOrParse(epService, soda, "create window MyWindow#length(5) as select * from SupportSpatialEventRectangle");
            SupportModelHelper.CreateByCompileOrParse(epService, soda, "create index MyIndex on MyWindow((x,y,width,height) mxcifquadtree(0,0,100,100))");
            SupportModelHelper.CreateByCompileOrParse(epService, soda, "insert into MyWindow select * from SupportSpatialEventRectangle");

            var epl = IndexBackingTableInfo.INDEX_CALLBACK_HOOK + " on SupportSpatialAABB as aabb " +
                      "select rects.id as c0 from MyWindow as rects where rectangle(rects.x,rects.y,rects.width,rects.height).intersects(rectangle(aabb.x,aabb.y,aabb.width,aabb.height))";
            var stmt     = SupportModelHelper.CreateByCompileOrParse(epService, soda, epl);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SupportQueryPlanIndexHook.AssertOnExprTableAndReset("MyIndex", "non-unique hash={} btree={} advanced={mxcifquadtree(x,y,width,height)}");

            SendEventRectangle(epService, "R1", 10, 40, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R1", null, null, null, null);

            SendEventRectangle(epService, "R2", 80, 80, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R1", null, null, "R2", null);

            SendEventRectangle(epService, "R3", 10, 40, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R1,R3", null, null, "R2", null);

            SendEventRectangle(epService, "R4", 60, 40, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R1,R3", "R4", null, "R2", "R4");

            SendEventRectangle(epService, "R5", 20, 75, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R1,R3", "R4", "R5", "R2", "R4");

            SendEventRectangle(epService, "R6", 50, 50, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R3,R6", "R4,R6", "R5,R6", "R2,R6", "R4,R6");

            SendEventRectangle(epService, "R7", 0, 0, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R3,R6,R7", "R4,R6", "R5,R6", "R6", "R4,R6");

            SendEventRectangle(epService, "R8", 99.999, 0, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R6,R7", "R4,R6,R8", "R5,R6", "R6", "R4,R6");

            SendEventRectangle(epService, "R9", 0, 99.999, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R6,R7", "R6,R8", "R5,R6,R9", "R6", "R6");

            SendEventRectangle(epService, "R10", 99.999, 99.999, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R6,R7", "R6,R8", "R6,R9", "R6,R10", "R6");

            SendEventRectangle(epService, "R11", 0, 0, 1, 1);
            AssertRectanglesManyRow(epService, listener, BOXES, "R7,R11", "R8", "R9", "R10", null);

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 3
0
        private void RunAssertionNestedDotMethod(bool grouped, bool soda)
        {
            var eplDeclare = "create table varagg (" +
                             (grouped ? "key string primary key, " : "") +
                             "windowSupportBean window(*) @type('SupportBean'))";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplDeclare);

            var eplInto = "into table varagg " +
                          "select window(*) as windowSupportBean from SupportBean.win:length(2)" +
                          (grouped ? " group by TheString" : "");

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplInto);

            var key       = grouped ? "[\"E1\"]" : "";
            var eplSelect = "select " +
                            "varagg" + key + ".windowSupportBean.last(*).IntPrimitive as c0, " +
                            "varagg" + key + ".windowSupportBean.window(*).countOf() as c1, " +
                            "varagg" + key + ".windowSupportBean.window(IntPrimitive).take(1) as c2" +
                            " from SupportBean_S0";
            EPStatement stmtSelect = SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplSelect);

            stmtSelect.AddListener(_listener);
            var expectedAggType = new object[][]
            {
                new object[] { "c0", typeof(int?) },
                new object[] { "c1", typeof(int) },
                new object[] { "c2", typeof(ICollection <object>) }
            };

            EventTypeAssertionUtil.AssertEventTypeProperties(expectedAggType, stmtSelect.EventType, EventTypeAssertionEnum.NAME, EventTypeAssertionEnum.TYPE);

            var fields = "c0,c1,c2".Split(',');

            MakeSendBean("E1", 10, 0);
            _epService.EPRuntime.SendEvent(new SupportBean_S0(0));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 10, 1, Collections.SingletonList(10) });

            MakeSendBean("E1", 20, 0);
            _epService.EPRuntime.SendEvent(new SupportBean_S0(0));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 20, 2, Collections.SingletonList(10) });

            MakeSendBean("E1", 30, 0);
            _epService.EPRuntime.SendEvent(new SupportBean_S0(0));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 30, 2, Collections.SingletonList(20) });

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__internal", false);
            _epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__public", false);
        }
Exemplo n.º 4
0
        private void RunAssertionLastFirstWindow(bool soda)
        {
            string[] fields     = "lasteveru,firsteveru,windowb".Split(',');
            string   eplDeclare = "create table varagg (" +
                                  "lasteveru lastever(*) @type('SupportBean'), " +
                                  "firsteveru firstever(*) @type('SupportBean'), " +
                                  "windowb window(*) @type('SupportBean'))";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplDeclare);

            string      eplIterate  = "select varagg from SupportBean_S0#lastevent";
            EPStatement stmtIterate = SupportModelHelper.CreateByCompileOrParse(epService, soda, eplIterate);

            epService.EPRuntime.SendEvent(new SupportBean_S0(0));

            string eplBoundInto = "into table varagg select window(*) as windowb from SupportBean#length(2)";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplBoundInto);

            string eplUnboundInto = "into table varagg select lastever(*) as lasteveru, firstever(*) as firsteveru from SupportBean";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplUnboundInto);

            SupportBean b1 = MakeSendBean("E1", 20);
            SupportBean b2 = MakeSendBean("E2", 15);
            SupportBean b3 = MakeSendBean("E3", 10);

            AssertResults(stmtIterate, fields, new object[] { b3, b1, new object[] { b2, b3 } });

            SupportBean b4 = MakeSendBean("E4", 5);

            AssertResults(stmtIterate, fields, new object[] { b4, b1, new object[] { b3, b4 } });

            // invalid: bound aggregation into unbound max
            SupportMessageAssertUtil.TryInvalid(epService, "into table varagg select last(*) as lasteveru from SupportBean#length(2)",
                                                "Error starting statement: Failed to validate select-clause expression 'last(*)': For into-table use 'window(*)' or ''window(stream.*)' instead [");
            // invalid: unbound aggregation into bound max
            SupportMessageAssertUtil.TryInvalid(epService, "into table varagg select lastever(*) as windowb from SupportBean#length(2)",
                                                "Error starting statement: Incompatible aggregation function for table 'varagg' column 'windowb', expecting 'window(*)' and received 'lastever(*)': Not a 'window' aggregation [");

            // valid: bound with unbound variable
            string eplBoundIntoUnbound = "into table varagg select lastever(*) as lasteveru from SupportBean#length(2)";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplBoundIntoUnbound);

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__internal", false);
            epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__public", false);
        }
Exemplo n.º 5
0
        private void RunAssertionTopLevelReadGrouped2Keys(bool soda)
        {
            SupportModelHelper.CreateByCompileOrParse(_epService, soda, "create objectarray schema MyEvent as (c0 int, c1 string, c2 int)");
            SupportModelHelper.CreateByCompileOrParse(_epService, soda, "create table windowAndTotal (" +
                                                      "keyi int primary key, keys string primary key, TheWindow window(*) @type('MyEvent'), TheTotal sum(int))");
            SupportModelHelper.CreateByCompileOrParse(_epService, soda, "into table windowAndTotal " +
                                                      "select window(*) as TheWindow, sum(c2) as TheTotal from MyEvent.win:length(2) group by c0, c1");

            var stmtSelect = SupportModelHelper.CreateByCompileOrParse(_epService, soda, "select windowAndTotal[id,p00] as Val0 from SupportBean_S0");

            stmtSelect.AddListener(_listener);
            AssertTopLevelTypeInfo(stmtSelect);

            var e1 = new object[] { 10, "G1", 100 };

            _epService.EPRuntime.SendEvent(e1, "MyEvent");

            var fieldsInner = "TheWindow,TheTotal".Split(',');

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "G1"));
            EPAssertionUtil.AssertPropsMap((IDictionary <string, object>)_listener.AssertOneGetNewAndReset().Get("Val0"), fieldsInner, new object[][] { e1 }, 100);

            var e2 = new object[] { 20, "G2", 200 };

            _epService.EPRuntime.SendEvent(e2, "MyEvent");

            _epService.EPRuntime.SendEvent(new SupportBean_S0(20, "G2"));
            EPAssertionUtil.AssertPropsMap((IDictionary <string, object>)_listener.AssertOneGetNewAndReset().Get("Val0"), fieldsInner, new object[][] { e2 }, 200);

            var e3 = new object[] { 20, "G2", 300 };

            _epService.EPRuntime.SendEvent(e3, "MyEvent");

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "G1"));
            EPAssertionUtil.AssertPropsMap((IDictionary <string, object>)_listener.AssertOneGetNewAndReset().Get("Val0"), fieldsInner, null, null);
            _epService.EPRuntime.SendEvent(new SupportBean_S0(20, "G2"));
            EPAssertionUtil.AssertPropsMap((IDictionary <string, object>)_listener.AssertOneGetNewAndReset().Get("Val0"), fieldsInner, new object[][] { e2, e3 }, 500);

            // test typable output
            stmtSelect.Dispose();
            var stmtConvert = _epService.EPAdministrator.CreateEPL("insert into AggBean select windowAndTotal[20, 'G2'] as Val0 from SupportBean_S0");

            stmtConvert.AddListener(_listener);

            _epService.EPRuntime.SendEvent(new SupportBean_S0(0));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "Val0.TheWindow,Val0.TheTotal".Split(','), new object[] { new object[][] { e2, e3 }, 500 });

            _epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 6
0
        private void RunAssertion_A_parenthesisBstar(EPServiceProvider epService)
        {
            EPServiceProviderIsolated isolated = epService.GetEPServiceIsolated("I1");

            SendTimer(isolated, 0);

            string[] fields = "a,b0,b1,b2".Split(',');
            string   text   = "select * from MyEvent#keepall " +
                              "match_recognize (" +
                              " measures A.TheString as a, B[0].TheString as b0, B[1].TheString as b1, B[2].TheString as b2" +
                              " pattern (A (B)*)" +
                              " interval 10 seconds or terminated" +
                              " define" +
                              " A as A.TheString like \"A%\"," +
                              " B as B.TheString like \"B%\"" +
                              ")";

            EPStatement stmt     = isolated.EPAdministrator.CreateEPL(text, "stmt1", null);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            // test output by terminated because of misfit event
            isolated.EPRuntime.SendEvent(new SupportRecogBean("A1"));
            isolated.EPRuntime.SendEvent(new SupportRecogBean("B1"));
            Assert.IsFalse(listener.IsInvoked);
            isolated.EPRuntime.SendEvent(new SupportRecogBean("X1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "A1", "B1", null, null });

            SendTimer(isolated, 20000);
            Assert.IsFalse(listener.IsInvoked);

            // test output by timer expiry
            isolated.EPRuntime.SendEvent(new SupportRecogBean("A2"));
            isolated.EPRuntime.SendEvent(new SupportRecogBean("B2"));
            Assert.IsFalse(listener.IsInvoked);
            SendTimer(isolated, 29999);

            SendTimer(isolated, 30000);
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "A2", "B2", null, null });

            // destroy
            stmt.Dispose();
            isolated.Dispose();

            EPStatement stmtFromModel = SupportModelHelper.CompileCreate(epService, text);

            stmtFromModel.Dispose();
        }
Exemplo n.º 7
0
        private void TryAssertionEventBeanArray(EPServiceProvider epService, string methodName, bool soda)
        {
            string      epl      = "select p0 from SupportBean, method:" + typeof(SupportStaticMethodLib).FullName + "." + methodName + "(TheString) @Type(MyItemEvent)";
            EPStatement stmt     = SupportModelHelper.CreateByCompileOrParse(epService, soda, epl);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("a,b", 0));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), "p0".Split(','), new object[][] {
                new object[] { "a" }, new object[] { "b" }
            });

            stmt.Dispose();
        }
Exemplo n.º 8
0
        private void RunAssertionOverlappingWithPattern(EPServiceProvider epService)
        {
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));
            string contextExpr = "create context MyContext " +
                                 "initiated by @Now and pattern [every timer:interval(10)] terminated after 10 sec";

            epService.EPAdministrator.CreateEPL(contextExpr);

            var    fields     = new string[] { "cnt" };
            string streamExpr = "context MyContext " +
                                "select count(*) as cnt from SupportBean output last when terminated";
            EPStatement stream   = epService.EPAdministrator.CreateEPL(streamExpr);
            var         listener = new SupportUpdateListener();

            stream.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(8000));
            epService.EPRuntime.SendEvent(new SupportBean("E3", 3));

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(9999));
            Assert.IsFalse(listener.IsInvoked);
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(10000));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 3L });

            epService.EPRuntime.SendEvent(new SupportBean("E4", 4));
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(10100));
            epService.EPRuntime.SendEvent(new SupportBean("E5", 5));
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(19999));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(20000));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2L });

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(30000));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 0L });

            epService.EPRuntime.SendEvent(new SupportBean("E6", 6));

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(40000));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1L });

            SupportModelHelper.CompileCreate(epService, streamExpr);

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 9
0
        private void RunAssertionSortedMinMaxBy(bool soda)
        {
            string[] fields     = "maxbyeveru,minbyeveru,sortedb".Split(',');
            string   eplDeclare = "create table varagg (" +
                                  "maxbyeveru maxbyever(IntPrimitive) @type('SupportBean'), " +
                                  "minbyeveru minbyever(IntPrimitive) @type('SupportBean'), " +
                                  "sortedb sorted(IntPrimitive) @type('SupportBean'))";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplDeclare);

            string      eplIterate  = "select varagg from SupportBean_S0#lastevent";
            EPStatement stmtIterate = SupportModelHelper.CreateByCompileOrParse(epService, soda, eplIterate);

            epService.EPRuntime.SendEvent(new SupportBean_S0(0));

            string eplBoundInto = "into table varagg select sorted() as sortedb from SupportBean#length(2)";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplBoundInto);

            string eplUnboundInto = "into table varagg select maxbyever() as maxbyeveru, minbyever() as minbyeveru from SupportBean";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplUnboundInto);

            SupportBean b1 = MakeSendBean("E1", 20);
            SupportBean b2 = MakeSendBean("E2", 15);
            SupportBean b3 = MakeSendBean("E3", 10);

            AssertResults(stmtIterate, fields, new object[] { b1, b3, new object[] { b3, b2 } });

            // invalid: bound aggregation into unbound max
            SupportMessageAssertUtil.TryInvalid(epService, "into table varagg select maxby(IntPrimitive) as maxbyeveru from SupportBean#length(2)",
                                                "Error starting statement: Failed to validate select-clause expression 'maxby(IntPrimitive)': When specifying into-table a sort expression cannot be provided [");
            // invalid: unbound aggregation into bound max
            SupportMessageAssertUtil.TryInvalid(epService, "into table varagg select maxbyever() as sortedb from SupportBean#length(2)",
                                                "Error starting statement: Incompatible aggregation function for table 'varagg' column 'sortedb', expecting 'sorted(IntPrimitive)' and received 'maxbyever()': The required aggregation function name is 'sorted' and provided is 'maxbyever' [");

            // valid: bound with unbound variable
            string eplBoundIntoUnbound = "into table varagg select " +
                                         "maxbyever() as maxbyeveru, minbyever() as minbyeveru " +
                                         "from SupportBean#length(2)";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplBoundIntoUnbound);

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__internal", false);
            epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__public", false);
        }
Exemplo n.º 10
0
        private void TryAssertionMinMax(EPServiceProvider epService, bool soda)
        {
            var fields = "maxb,maxu,minb,minu".Split(',');
            var eplDeclare = "create table varagg (" +
                             "maxb max(int), maxu maxever(int), minb min(int), minu minever(int))";
            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplDeclare);

            var eplIterate = "select varagg from SupportBean_S0#lastevent";
            var stmtIterate = SupportModelHelper.CreateByCompileOrParse(epService, soda, eplIterate);
            epService.EPRuntime.SendEvent(new SupportBean_S0(0));

            var eplBoundInto = "into table varagg select " +
                               "max(IntPrimitive) as maxb, min(IntPrimitive) as minb " +
                               "from SupportBean#length(2)";
            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplBoundInto);

            var eplUnboundInto = "into table varagg select " +
                                 "maxever(IntPrimitive) as maxu, minever(IntPrimitive) as minu " +
                                 "from SupportBean";
            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplUnboundInto);

            epService.EPRuntime.SendEvent(new SupportBean("E1", 20));
            epService.EPRuntime.SendEvent(new SupportBean("E2", 15));
            epService.EPRuntime.SendEvent(new SupportBean("E3", 10));
            AssertResults(stmtIterate, fields, new object[] {15, 20, 10, 10});

            epService.EPRuntime.SendEvent(new SupportBean("E4", 5));
            AssertResults(stmtIterate, fields, new object[] {10, 20, 5, 5});

            epService.EPRuntime.SendEvent(new SupportBean("E5", 25));
            AssertResults(stmtIterate, fields, new object[] {25, 25, 5, 5});

            // invalid: unbound aggregation into bound max
            SupportMessageAssertUtil.TryInvalid(
                epService, "into table varagg select max(IntPrimitive) as maxb from SupportBean",
                "Error starting statement: Incompatible aggregation function for table 'varagg' column 'maxb', expecting 'max(int)' and received 'max(IntPrimitive)': The aggregation declares use with data windows and provided is unbound [");

            // valid: bound with unbound variable
            var eplBoundIntoUnbound = "into table varagg select " +
                                      "maxever(IntPrimitive) as maxu, minever(IntPrimitive) as minu " +
                                      "from SupportBean#length(2)";
            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplBoundIntoUnbound);

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__internal", false);
            epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__public", false);
        }
Exemplo n.º 11
0
        private void RunAssertionInsertMap(bool soda)
        {
            SupportModelHelper.CreateByCompileOrParse(_epService, soda, "create map schema EmptyMapSchema as ()");
            _epService.EPAdministrator.CreateEPL("insert into EmptyMapSchema() select null from SupportBean");

            var stmt = _epService.EPAdministrator.CreateEPL("select * from EmptyMapSchema");

            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(new SupportBean());
            var @event = _listener.AssertOneGetNewAndReset();

            Assert.IsTrue(@event.Underlying.AsBasicDictionary <string, object>().IsEmpty());
            Assert.AreEqual(0, @event.EventType.PropertyDescriptors.Count);

            _epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 12
0
        private void TryAssertionInsertMap(EPServiceProvider epService, bool soda)
        {
            SupportModelHelper.CreateByCompileOrParse(epService, soda, "create map schema EmptyMapSchema as ()");
            epService.EPAdministrator.CreateEPL("insert into EmptyMapSchema() select null from SupportBean");

            EPStatement stmt     = epService.EPAdministrator.CreateEPL("select * from EmptyMapSchema");
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean());
            EventBean @event = listener.AssertOneGetNewAndReset();

            Assert.IsTrue(((IDictionary <string, object>)@event.Underlying).IsEmpty());
            Assert.AreEqual(0, @event.EventType.PropertyDescriptors.Count);

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 13
0
        private void RunAssertionDatetimeBaseTypes(EPServiceProvider epService, bool soda)
        {
            var epl = "select " +
                      "cast(yyyymmdd,date,dateformat:\"yyyyMMdd\") as c0, " +
                      "cast(yyyymmdd,System.DateTime,dateformat:\"yyyyMMdd\") as c1, " +
                      "cast(yyyymmdd,dto,dateformat:\"yyyyMMdd\") as c2, " +
                      "cast(yyyymmdd,dtx,dateformat:\"yyyyMMdd\") as c3, " +
                      "cast(yyyymmdd,long,dateformat:\"yyyyMMdd\") as c4, " +
                      "cast(yyyymmdd,System.Int64,dateformat:\"yyyyMMdd\") as c5, " +
                      "cast(yyyymmdd,datetime,dateformat:\"yyyyMMdd\").get(\"month\") as c6, " +
                      "cast(yyyymmdd,long,dateformat:\"yyyyMMdd\").get(\"month\") as c8 " +
                      "from MyType";

            var stmt     = SupportModelHelper.CreateByCompileOrParse(epService, soda, epl);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            var values = new Dictionary <string, object>();

            values.Put("yyyymmdd", "20100510");
            epService.EPRuntime.SendEvent(values, "MyType");

            var formatYYYYMMdd = "yyyyMMdd";
            var dateYYMMdd     = DateTime.ParseExact("20100510", formatYYYYMMdd, null, DateTimeStyles.None);
            var dateYYMMddDto  = new DateTimeOffset(dateYYMMdd, TimeZoneInfo.Local.GetUtcOffset(dateYYMMdd));
            var dateYYMMddDtx  = DateTimeEx.GetInstance(TimeZoneInfo.Local, dateYYMMdd);

            EPAssertionUtil.AssertProps(
                listener.AssertOneGetNewAndReset(), "c0,c1,c2,c3,c4,c5,c6,c8".Split(','),
                new object[]
            {
                dateYYMMdd,
                dateYYMMdd,
                dateYYMMddDto,
                dateYYMMddDtx,
                dateYYMMddDto.TimeInMillis(),
                dateYYMMddDto.TimeInMillis(),
                5,
                5
            });

            stmt.Dispose();
        }
Exemplo n.º 14
0
        private void RunAssertionGroupedSingleKeyNoContext(bool soda)
        {
            var eplDeclare = "create table varTotal (key string primary key, total sum(int))";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplDeclare);

            var eplBind = "into table varTotal " +
                          "select TheString, sum(IntPrimitive) as total from SupportBean group by TheString";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplBind);

            var eplUse = "select p00 as c0, varTotal[p00].total as c1 from SupportBean_S0";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplUse).AddListener(_listener);

            RunAssertionTopLevelSingle();

            _epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 15
0
        private void TryAssertionFromClauseOutputFirstWhere(EPServiceProvider epService, bool soda)
        {
            var fieldsOrderId = "oe.orderdetail.OrderId".Split(',');
            var epl           = "on OrderEvent as oe " +
                                "insert into HeaderEvent select orderdetail.OrderId as OrderId where 1=2 " +
                                "insert into StreamOne select * from [select oe, * from orderdetail.Items] where productId=\"10020\" " +
                                "insert into StreamTwo select * from [select oe, * from orderdetail.Items] where productId=\"10022\" " +
                                "insert into StreamThree select * from [select oe, * from orderdetail.Items] where productId in (\"10020\",\"10025\",\"10022\")";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, epl);

            var listeners   = GetListeners();
            var listenerEPL = new[] { "select * from StreamOne", "select * from StreamTwo", "select * from StreamThree" };

            for (var i = 0; i < listenerEPL.Length; i++)
            {
                epService.EPAdministrator.CreateEPL(listenerEPL[i]).Events += listeners[i].Update;
                listeners[i].Reset();
            }

            epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventOne());
            EPAssertionUtil.AssertProps(listeners[0].AssertOneGetNewAndReset(), fieldsOrderId, new object[] { "PO200901" });
            Assert.IsFalse(listeners[1].IsInvoked);
            Assert.IsFalse(listeners[2].IsInvoked);

            epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventTwo());
            Assert.IsFalse(listeners[0].IsInvoked);
            EPAssertionUtil.AssertProps(listeners[1].AssertOneGetNewAndReset(), fieldsOrderId, new object[] { "PO200902" });
            Assert.IsFalse(listeners[2].IsInvoked);

            epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventThree());
            Assert.IsFalse(listeners[0].IsInvoked);
            Assert.IsFalse(listeners[1].IsInvoked);
            EPAssertionUtil.AssertProps(listeners[2].AssertOneGetNewAndReset(), fieldsOrderId, new object[] { "PO200903" });

            epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventFour());
            Assert.IsFalse(listeners[0].IsInvoked);
            Assert.IsFalse(listeners[1].IsInvoked);
            Assert.IsFalse(listeners[2].IsInvoked);

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 16
0
        private void TryAssertionGroupedSingleKeyNoContext(EPServiceProvider epService, bool soda)
        {
            var eplDeclare = "create table varTotalG1K (key string primary key, total sum(int))";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplDeclare);

            var eplBind = "into table varTotalG1K " +
                          "select TheString, sum(IntPrimitive) as total from SupportBean group by TheString";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplBind);

            var eplUse   = "select p00 as c0, varTotalG1K[p00].total as c1 from SupportBean_S0";
            var listener = new SupportUpdateListener();

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplUse).Events += listener.Update;

            TryAssertionTopLevelSingle(epService, listener);

            epService.EPAdministrator.DestroyAllStatements();
        }
        private void RunAssertionFirstAggSODA(EPServiceProvider epService, bool soda)
        {
            var fields = "c0,c1".Split(',');
            var epl = "select " +
                      "first(*,filter:IntPrimitive=1).TheString as c0, " +
                      "first(*,filter:IntPrimitive=2).TheString as c1" +
                      " from SupportBean#length(3)";
            var stmt = SupportModelHelper.CreateByCompileOrParse(epService, soda, epl);
            var listener = new SupportUpdateListener();
            stmt.Events += listener.Update;

            SendEventAssert(epService, listener, "E1", 3, fields, new object[] {null, null});
            SendEventAssert(epService, listener, "E2", 2, fields, new object[] {null, "E2"});
            SendEventAssert(epService, listener, "E3", 1, fields, new object[] {"E3", "E2"});
            SendEventAssert(epService, listener, "E4", 2, fields, new object[] {"E3", "E2"});
            SendEventAssert(epService, listener, "E5", -1, fields, new object[] {"E3", "E4"});
            SendEventAssert(epService, listener, "E6", -1, fields, new object[] {null, "E4"});
            SendEventAssert(epService, listener, "E7", -1, fields, new object[] {null, null});

            stmt.Dispose();
        }
Exemplo n.º 18
0
        private void RunAssertionScriptReturningEvents(EPServiceProvider epService, bool soda)
        {
            var script = string.Join(
                "\n",
                "create expression EventBean[] @type(ItemEvent) jscript:myScriptReturnsEvents() [",
                "  function myScriptReturnsEvents() {",
                "    var events = host.newArr(EventBean, 3);",
                "    events[0] = epl.EventBeanService.AdapterForMap(Collections.SingletonDataMap(\"id\", \"id1\"), \"ItemEvent\");",
                "    events[1] = epl.EventBeanService.AdapterForMap(Collections.SingletonDataMap(\"id\", \"id2\"), \"ItemEvent\");",
                "    events[2] = epl.EventBeanService.AdapterForMap(Collections.SingletonDataMap(\"id\", \"id3\"), \"ItemEvent\");",
                "    return events;",
                "  }",
                "  return myScriptReturnsEvents();",
                "]"
                );

            var stmtScript = SupportModelHelper.CreateByCompileOrParse(epService, soda, script);

            var stmtSelect = epService.EPAdministrator.CreateEPL(
                "select myScriptReturnsEvents().where(v => v.id in ('id1', 'id3')) as c0 from SupportBean");
            var listener = new SupportUpdateListener();

            stmtSelect.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean());
            var coll = listener.AssertOneGetNewAndReset().Get("c0")
                       .UnwrapEnumerable <object>()
                       .Select(item => item.UnwrapStringDictionary())
                       .ToArray();

            EPAssertionUtil.AssertPropsPerRow(
                coll, "id".Split(','),
                new object[][] {
                new object[] { "id1" },
                new object[] { "id3" }
            });

            stmtSelect.Dispose();
            stmtScript.Dispose();
        }
Exemplo n.º 19
0
        private void RunAssertion2SplitNoDefaultOutputFirst(EPServiceProvider epService)
        {
            var stmtOrigText = "@Audit on SupportBean " +
                               "insert into AStream2SP select * where IntPrimitive=1 " +
                               "insert into BStream2SP select * where IntPrimitive=1 or IntPrimitive=2";
            var stmtOrig = epService.EPAdministrator.CreateEPL(stmtOrigText);

            TryAssertion(epService, stmtOrig);

            // statement object model
            var model = new EPStatementObjectModel();

            model.Annotations  = Collections.SingletonList(new AnnotationPart("Audit"));
            model.FromClause   = FromClause.Create(FilterStream.Create("SupportBean"));
            model.InsertInto   = InsertIntoClause.Create("AStream2SP");
            model.SelectClause = SelectClause.CreateWildcard();
            model.WhereClause  = Expressions.Eq("IntPrimitive", 1);
            var clause = OnClause.CreateOnInsertSplitStream();

            model.OnExpr = clause;
            var item = OnInsertSplitStreamItem.Create(
                InsertIntoClause.Create("BStream2SP"),
                SelectClause.CreateWildcard(),
                Expressions.Or(Expressions.Eq("IntPrimitive", 1), Expressions.Eq("IntPrimitive", 2)));

            clause.AddItem(item);
            Assert.AreEqual(stmtOrigText, model.ToEPL());
            stmtOrig = epService.EPAdministrator.Create(model);
            TryAssertion(epService, stmtOrig);

            var newModel = epService.EPAdministrator.CompileEPL(stmtOrigText);

            stmtOrig = epService.EPAdministrator.Create(newModel);
            Assert.AreEqual(stmtOrigText, newModel.ToEPL());
            TryAssertion(epService, stmtOrig);

            SupportModelHelper.CompileCreate(epService, stmtOrigText + " output all");

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 20
0
        private void RunAggregationWDatetimeEtc(bool grouped, bool soda)
        {
            var eplDeclare = "create table varagg (" + (grouped ? "key string primary key, " : "") +
                             "a1 lastever(long), a2 window(*) @type('SupportBean'))";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplDeclare);

            var eplInto = "into table varagg " +
                          "select lastever(LongPrimitive) as a1, window(*) as a2 from SupportBean#time(10 seconds)" +
                          (grouped ? " group by TheString" : "");
            EPStatement stmtInto        = SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplInto);
            var         expectedAggType = new object[][] { new object[] { "a1", typeof(long) }, new object[] { "a2", typeof(SupportBean[]) } };

            SupportEventTypeAssertionUtil.AssertEventTypeProperties(expectedAggType, stmtInto.EventType, SupportEventTypeAssertionEnum.NAME, SupportEventTypeAssertionEnum.TYPE);

            var key    = grouped ? "[\"E1\"]" : "";
            var eplGet = "select varagg" + key + ".a1.after(150L) as c0, " +
                         "varagg" + key + ".a2.countOf() as c1 from SupportBean_S0";
            EPStatement stmtGet = SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplGet);

            stmtGet.AddListener(_listener);
            var expectedGetType = new object[][] { new object[] { "c0", typeof(bool?) }, new object[] { "c1", typeof(int) } };

            SupportEventTypeAssertionUtil.AssertEventTypeProperties(expectedGetType, stmtGet.EventType, SupportEventTypeAssertionEnum.NAME, SupportEventTypeAssertionEnum.TYPE);

            var fields = "c0,c1".Split(',');

            MakeSendBean("E1", 10, 100);
            _epService.EPRuntime.SendEvent(new SupportBean_S0(0));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { false, 1 });

            MakeSendBean("E1", 20, 200);
            _epService.EPRuntime.SendEvent(new SupportBean_S0(0));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { true, 2 });

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__internal", false);
            _epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__public", false);
        }
Exemplo n.º 21
0
        public void TestNonOverlapping()
        {
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));
            var contextExpr = "create context MyContext " +
                              "as start @now end after 10 seconds";

            _epService.EPAdministrator.CreateEPL(contextExpr);

            var fields     = new string[] { "cnt" };
            var streamExpr = "context MyContext " +
                             "select count(*) as cnt from SupportBean output last when terminated";
            var stream = _epService.EPAdministrator.CreateEPL(streamExpr);

            stream.AddListener(_listener);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(8000));
            _epService.EPRuntime.SendEvent(new SupportBean("E3", 3));
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(10000));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 3L });

            _epService.EPRuntime.SendEvent(new SupportBean("E4", 4));
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(19999));
            Assert.IsFalse(_listener.IsInvoked);
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(20000));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 1L });

            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(30000));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 0L });

            SupportModelHelper.CompileCreate(_epService, streamExpr);

            _epService.EPAdministrator.DestroyAllStatements();

            SupportModelHelper.CompileCreate(_epService, contextExpr);
            _epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 22
0
        private void RunAssertionIntegerIndexedPropertyLookAlike(bool soda)
        {
            var eplDeclare = "create table varagg (key int primary key, myevents window(*) @type('SupportBean'))";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplDeclare);

            var eplInto = "into table varagg select window(*) as myevents from SupportBean.win:length(3) group by IntPrimitive";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplInto);

            var eplSelect = "select varagg[1] as c0, varagg[1].myevents as c1, varagg[1].myevents.last(*) as c2 from SupportBean_S0";
            var stmt      = SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplSelect);

            stmt.AddListener(_listener);

            var e1 = MakeSendBean("E1", 1, 10L);
            var e2 = MakeSendBean("E2", 1, 20L);

            _epService.EPRuntime.SendEvent(new SupportBean_S0(0));
            AssertIntegerIndexed(_listener.AssertOneGetNewAndReset(), new SupportBean[] { e1, e2 });

            _epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 23
0
        public void TryPermute(bool soda, string pattern)
        {
            string epl = "select * from SupportBean " +
                         "match_recognize (" +
                         " partition by intPrimitive" +
                         " measures A as a, B as b, C as c" +
                         " pattern (" + pattern + ")" +
                         " define" +
                         " A as A.theString like \"A%\"," +
                         " B as B.theString like \"B%\"," +
                         " C as C.theString like \"C%\"" +
                         ")";
            EPStatement stmt = SupportModelHelper.CreateByCompileOrParse(_epService, soda, epl);

            stmt.AddListener(_listener);

            string[] prefixes = "A,B,C".Split(',');
            string[] fields   = "a,b,c".Split(',');

            var e     = PermutationEnumerator.Create(3);
            int count = 0;

            foreach (int[] indexes in e)
            {
                var expected = new object[3];
                for (int i = 0; i < 3; i++)
                {
                    expected[indexes[i]] = SendEvent(prefixes[indexes[i]] + count.ToString(), count);
                }
                count++;

                EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, expected);
            }

            stmt.Dispose();
        }
Exemplo n.º 24
0
        public void TestOM()
        {
            var model = new EPStatementObjectModel();

            model.CreateVariable = CreateVariableClause.Create("long", "var1", null);
            _epService.EPAdministrator.Create(model);
            Assert.AreEqual("create variable long var1", model.ToEPL());

            model = new EPStatementObjectModel();
            model.CreateVariable = CreateVariableClause.Create("string", "var2", Expressions.Constant("abc"));
            _epService.EPAdministrator.Create(model);
            Assert.AreEqual("create variable string var2 = \"abc\"", model.ToEPL());

            String      stmtTextSelect = "select var1, var2 from " + typeof(SupportBean).FullName;
            EPStatement stmtSelect     = _epService.EPAdministrator.CreateEPL(stmtTextSelect);

            stmtSelect.Events += _listener.Update;

            String[] fieldsVar = new String[] { "var1", "var2" };
            SendSupportBean("E1", 10);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsVar, new Object[] { null, "abc" });

            SupportModelHelper.CompileCreate(_epService, "create variable double[] arrdouble = {1.0d,2.0d}");
        }
Exemplo n.º 25
0
        public void TestBlackWhitePercent()
        {
            var fields = "cb,cnb,c,pct".Split(',');
            var epl    = "select count(*,black) as cb, count(*,not black) as cnb, count(*) as c, count(*,black)/count(*) as pct from BlackWhiteEvent#length(3)";
            var stmt   = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(epl);

            stmt.AddListener(_listener);
            Assert.IsFalse(stmt.StatementContext.IsStatelessSelect);

            _epService.EPRuntime.SendEvent(new BlackWhiteEvent(true));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 1L, 0L, 1L, 1d });

            _epService.EPRuntime.SendEvent(new BlackWhiteEvent(false));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 1L, 1L, 2L, 0.5d });

            _epService.EPRuntime.SendEvent(new BlackWhiteEvent(false));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 1L, 2L, 3L, 1 / 3d });

            _epService.EPRuntime.SendEvent(new BlackWhiteEvent(false));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 0L, 3L, 3L, 0d });

            SupportModelHelper.CompileCreate(_epService, epl);
            SupportModelHelper.CompileCreate(_epService, "select count(distinct black,not black), count(black,black) from BlackWhiteEvent");
        }
Exemplo n.º 26
0
        private void RunAssertionNonConstantVariable(bool soda)
        {
            var modifyEPL = "on SupportBean_S0 set MyNonConstantServiceVariable.Postfix=p00";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, modifyEPL);

            var epl = "select id as c0 from SupportBean as sb, " +
                      "method:MyNonConstantServiceVariable.FetchABean(IntPrimitive) as h0";
            var stmt = SupportModelHelper.CreateByCompileOrParse(_epService, soda, epl);

            _listener = new SupportUpdateListener();
            stmt.AddListener(_listener);

            SendEventAssert("E1", 10, "_10_postfix");

            _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "newpostfix"));
            SendEventAssert("E1", 20, "_20_newpostfix");

            // return to original value
            _epService.EPRuntime.SendEvent(new SupportBean_S0(2, "postfix"));
            SendEventAssert("E1", 30, "_30_postfix");

            _epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 27
0
        private void RunAssertionFromClauseAsMultiple(bool soda)
        {
            String epl = "on OrderEvent as oe " +
                         "insert into StartEvent select oe.orderdetail.OrderId as oi " +
                         "insert into ThenEvent select * from [select oe.orderdetail.OrderId as oi, ItemId from orderdetail.Items] as Item " +
                         "insert into MoreEvent select oe.orderdetail.OrderId as oi, Item.ItemId as ItemId from [select oe, * from orderdetail.Items] as Item " +
                         "output all";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, epl);

            _epService.EPAdministrator.CreateEPL("select * from StartEvent").AddListener(_listeners[0]);
            _epService.EPAdministrator.CreateEPL("select * from ThenEvent").AddListener(_listeners[1]);
            _epService.EPAdministrator.CreateEPL("select * from MoreEvent").AddListener(_listeners[2]);

            _epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventOne());
            String[] fieldsOrderId = "oi".SplitCsv();
            String[] fieldsItems   = "oi,ItemId".SplitCsv();
            EPAssertionUtil.AssertProps(_listeners[0].AssertOneGetNewAndReset(), fieldsOrderId, new Object[] { "PO200901" });
            Object[][] expected = new Object[][] { new Object[] { "PO200901", "A001" }, new Object[] { "PO200901", "A002" }, new Object[] { "PO200901", "A003" } };
            EPAssertionUtil.AssertPropsPerRow(_listeners[1].GetAndResetDataListsFlattened().First, fieldsItems, expected);
            EPAssertionUtil.AssertPropsPerRow(_listeners[2].GetAndResetDataListsFlattened().First, fieldsItems, expected);

            _epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 28
0
        public void RunOnMergeInsertUpdDeleteTwoKey(bool soda)
        {
            var eplDeclare = "create table varagg (KeyOne int primary key, KeyTwo string primary key, Prop string)";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplDeclare);

            var         fields   = "c0,c1,c2".Split(',');
            var         eplRead  = "select varagg[id,p00].KeyOne as c0, varagg[id,p00].KeyTwo as c1, varagg[id,p00].Prop as c2 from SupportBean_S0";
            EPStatement stmtRead = SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplRead);

            stmtRead.AddListener(_listener);

            // assert selected column types
            var expectedAggType = new object[][] { new object[] { "c0", typeof(int) }, new object[] { "c1", typeof(string) }, new object[] { "c2", typeof(string) } };

            EventTypeAssertionUtil.AssertEventTypeProperties(expectedAggType, stmtRead.EventType, EventTypeAssertionEnum.NAME, EventTypeAssertionEnum.TYPE);

            // assert no row
            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "A"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null });

            // create merge
            var eplMerge = "on SupportBean merge varagg" +
                           " where IntPrimitive=KeyOne and TheString=KeyTwo" +
                           " when not matched then" +
                           " insert select IntPrimitive as KeyOne, TheString as KeyTwo, \"inserted\" as Prop" +
                           " when matched and LongPrimitive>0 then" +
                           " update set Prop=\"updated\"" +
                           " when matched and LongPrimitive<0 then" +
                           " delete";
            EPStatement stmtMerge    = SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplMerge);
            var         expectedType = new object[][] { new object[] { "KeyOne", typeof(int) }, new object[] { "KeyTwo", typeof(string) }, new object[] { "Prop", typeof(string) } };

            EventTypeAssertionUtil.AssertEventTypeProperties(expectedType, stmtMerge.EventType, EventTypeAssertionEnum.NAME, EventTypeAssertionEnum.TYPE);

            // merge for varagg[10, "A"]
            _epService.EPRuntime.SendEvent(new SupportBean("A", 10));

            // assert key {"10", "A"}
            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "A"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 10, "A", "inserted" });

            // update for varagg[10, "A"]
            _epService.EPRuntime.SendEvent(MakeSupportBean("A", 10, 1));
            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "A"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 10, "A", "updated" });

            // test typable output
            _epService.EPAdministrator.Configuration.AddEventType(typeof(LocalBean));
            var stmtConvert = _epService.EPAdministrator.CreateEPL("insert into LocalBean select varagg[10, 'A'] as Val0 from SupportBean_S1");

            stmtConvert.AddListener(_listener);
            _epService.EPRuntime.SendEvent(new SupportBean_S1(2));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "Val0.KeyOne".Split(','), new object[] { 10 });

            // delete for varagg[10, "A"]
            _epService.EPRuntime.SendEvent(MakeSupportBean("A", 10, -1));
            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "A"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null });

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__internal", false);
            _epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__public", false);
        }
Exemplo n.º 29
0
        public void RunOnMergeInsertUpdDeleteSingleKey(bool soda)
        {
            var fieldsTable = "key,p0,p1,p2,sumint".Split(',');
            var eplDeclare  = "create table varagg (key int primary key, p0 string, p1 int, p2 int[], sumint sum(int))";

            SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplDeclare);

            var         fields   = "c0,c1,c2,c3".Split(',');
            var         eplRead  = "select varagg[id].p0 as c0, varagg[id].p1 as c1, varagg[id].p2 as c2, varagg[id].sumint as c3 from SupportBean_S0";
            EPStatement stmtRead = SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplRead);

            stmtRead.AddListener(_listener);

            // assert selected column types
            var expectedAggType = new object[][] { new object[] { "c0", typeof(string) }, new object[] { "c1", typeof(int) }, new object[] { "c2", typeof(int[]) }, new object[] { "c3", typeof(int?) } };

            EventTypeAssertionUtil.AssertEventTypeProperties(expectedAggType, stmtRead.EventType, EventTypeAssertionEnum.NAME, EventTypeAssertionEnum.TYPE);

            // assert no row
            _epService.EPRuntime.SendEvent(new SupportBean_S0(10));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null });

            // create merge
            var eplMerge = "on SupportBean merge varagg" +
                           " where IntPrimitive=key" +
                           " when not matched then" +
                           " insert select IntPrimitive as key, \"v1\" as p0, 1000 as p1, {1,2} as p2" +
                           " when matched and TheString like \"U%\" then" +
                           " update set p0=\"v2\", p1=2000, p2={3,4}" +
                           " when matched and TheString like \"D%\" then" +
                           " delete";
            EPStatement stmtMerge = SupportModelHelper.CreateByCompileOrParse(_epService, soda, eplMerge);

            stmtMerge.AddListener(_listenerMerge);

            // merge for varagg[10]
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 10));
            EPAssertionUtil.AssertProps(_listenerMerge.AssertOneGetNewAndReset(), fieldsTable, new object[] { 10, "v1", 1000, new int[] { 1, 2 }, null });

            // assert key "10"
            _epService.EPRuntime.SendEvent(new SupportBean_S0(10));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "v1", 1000, new int?[] { 1, 2 }, null });

            // also aggregate-into the same key
            SupportModelHelper.CreateByCompileOrParse(_epService, soda, "into table varagg select sum(50) as sumint from SupportBean_S1 group by id");
            _epService.EPRuntime.SendEvent(new SupportBean_S1(10));
            _epService.EPRuntime.SendEvent(new SupportBean_S0(10));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "v1", 1000, new int?[] { 1, 2 }, 50 });

            // update for varagg[10]
            _epService.EPRuntime.SendEvent(new SupportBean("U2", 10));
            EPAssertionUtil.AssertProps(_listenerMerge.LastNewData[0], fieldsTable, new object[] { 10, "v2", 2000, new int[] { 3, 4 }, 50 });
            EPAssertionUtil.AssertProps(_listenerMerge.GetAndResetLastOldData()[0], fieldsTable, new object[] { 10, "v1", 1000, new int[] { 1, 2 }, 50 });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "v2", 2000, new int?[] { 3, 4 }, 50 });

            // delete for varagg[10]
            _epService.EPRuntime.SendEvent(new SupportBean("D3", 10));
            EPAssertionUtil.AssertProps(_listenerMerge.AssertOneGetOldAndReset(), fieldsTable, new object[] { 10, "v2", 2000, new int[] { 3, 4 }, 50 });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null });

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__internal", false);
            _epService.EPAdministrator.Configuration.RemoveEventType("table_varagg__public", false);
        }
Exemplo n.º 30
0
        private void RunAssertionUse(bool soda)
        {
            string eplCreate = "create table MyTable (" +
                               "col0 string, " +
                               "col1 sum(int), " +
                               "col2 sorted(IntPrimitive) @type('SupportBean'), " +
                               "col3 int[], " +
                               "col4 window(*) @type('SupportBean')" +
                               ")";

            SupportModelHelper.CreateByCompileOrParse(epService, soda, eplCreate);

            string eplIntoTable = "into table MyTable select sum(IntPrimitive) as col1, sorted() as col2, " +
                                  "window(*) as col4 from SupportBean.win:length(3)";
            EPStatement stmtIntoTable = SupportModelHelper.CreateByCompileOrParse(epService, soda, eplIntoTable);

            SupportBean[] sentSB = new SupportBean[2];
            sentSB[0] = MakeSendSupportBean("E1", 20);
            sentSB[1] = MakeSendSupportBean("E2", 21);
            stmtIntoTable.Dispose();

            string      eplMerge  = "on SupportBean merge MyTable when matched then update set col3={1,2,4,2}, col0=\"x\"";
            EPStatement stmtMerge = SupportModelHelper.CreateByCompileOrParse(epService, soda, eplMerge);

            MakeSendSupportBean(null, -1);
            stmtMerge.Dispose();

            string eplSelect = "select " +
                               "col0 as c0_1, mt.col0 as c0_2, " +
                               "col1 as c1_1, mt.col1 as c1_2, " +
                               "col2 as c2_1, mt.col2 as c2_2, " +
                               "col2.minBy() as c2_3, mt.col2.maxBy() as c2_4, " +
                               "col2.sorted().firstOf() as c2_5, mt.col2.sorted().firstOf() as c2_6, " +
                               "col3.mostFrequent() as c3_1, mt.col3.mostFrequent() as c3_2, " +
                               "col4 as c4_1 " +
                               "from SupportBean unidirectional, MyTable as mt";
            EPStatement stmtSelect = SupportModelHelper.CreateByCompileOrParse(epService, soda, eplSelect);

            stmtSelect.AddListener(listener);

            object[][] expectedType = new object[][] {
                new object[] { "c0_1", typeof(string) }, new object[] { "c0_2", typeof(string) },
                new object[] { "c1_1", typeof(int?) }, new object[] { "c1_2", typeof(int?) },
                new object[] { "c2_1", typeof(SupportBean[]) }, new object[] { "c2_2", typeof(SupportBean[]) },
                new object[] { "c2_3", typeof(SupportBean) }, new object[] { "c2_4", typeof(SupportBean) },
                new object[] { "c2_5", typeof(SupportBean) }, new object[] { "c2_6", typeof(SupportBean) },
                new object[] { "c3_1", typeof(int?) }, new object[] { "c3_2", typeof(int?) },
                new object[] { "c4_1", typeof(SupportBean[]) }
            };
            EventTypeAssertionUtil.AssertEventTypeProperties(expectedType, stmtSelect.EventType, EventTypeAssertionEnum.NAME, EventTypeAssertionEnum.TYPE);

            MakeSendSupportBean(null, -1);
            EventBean @event = listener.AssertOneGetNewAndReset();

            EPAssertionUtil.AssertProps(@event, "c0_1,c0_2,c1_1,c1_2".Split(','), new object[] { "x", "x", 41, 41 });
            EPAssertionUtil.AssertProps(@event, "c2_1,c2_2".Split(','), new object[] { sentSB, sentSB });
            EPAssertionUtil.AssertProps(@event, "c2_3,c2_4".Split(','), new object[] { sentSB[0], sentSB[1] });
            EPAssertionUtil.AssertProps(@event, "c2_5,c2_6".Split(','), new object[] { sentSB[0], sentSB[0] });
            EPAssertionUtil.AssertProps(@event, "c3_1,c3_2".Split(','), new object[] { 2, 2 });
            EPAssertionUtil.AssertProps(@event, "c4_1".Split(','), new object[] { sentSB });

            // unnamed column
            string eplSelectUnnamed = "select col2.sorted().firstOf(), mt.col2.sorted().firstOf()" +
                                      " from SupportBean unidirectional, MyTable mt";
            EPStatement stmtSelectUnnamed = epService.EPAdministrator.CreateEPL(eplSelectUnnamed);

            object[][] expectedTypeUnnamed = new object[][] {
                new object[] { "col2.sorted().firstOf()", typeof(SupportBean) },
                new object[] { "mt.col2.sorted().firstOf()", typeof(SupportBean) },
            };
            EventTypeAssertionUtil.AssertEventTypeProperties(expectedTypeUnnamed, stmtSelectUnnamed.EventType, EventTypeAssertionEnum.NAME, EventTypeAssertionEnum.TYPE);

            // invalid: ambiguous resolution
            SupportMessageAssertUtil.TryInvalid(epService, "" +
                                                "select col0 from SupportBean, MyTable, MyTable",
                                                "Error starting statement: Failed to validate select-clause expression 'col0': Ambiguous table column 'col0' should be prefixed by a stream name [");

            epService.EPAdministrator.DestroyAllStatements();
        }