Exemplo n.º 1
0
            private void TryAssertionInsertWhereOMStaggered(
                RegressionEnvironment env,
                EventRepresentationChoice eventRepresentationEnum)
            {
                var path = new RegressionPath();
                var stmtTextCreateOne = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyWindowIWOM>() +
                                        " @Name('window') create window MyWindowIWOM#keepall as select a, b from MyMapAB";
                env.CompileDeploy(stmtTextCreateOne, path);
                Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("window").EventType.UnderlyingType));
                env.AddListener("window");

                // create insert into
                var stmtTextInsertOne = "insert into MyWindowIWOM select a, b from MyMapAB";
                env.CompileDeploy(stmtTextInsertOne, path);

                // populate some data
                env.SendEventMap(BuildMap(new[] {new object[] {"a", "E1"}, new object[] {"b", 2}}), "MyMapAB");
                env.SendEventMap(BuildMap(new[] {new object[] {"a", "E2"}, new object[] {"b", 10}}), "MyMapAB");
                env.SendEventMap(BuildMap(new[] {new object[] {"a", "E3"}, new object[] {"b", 10}}), "MyMapAB");

                // create window with keep-all using OM
                var model = new EPStatementObjectModel();
                eventRepresentationEnum.AddAnnotationForNonMap(model);
                Expression where = Expressions.Eq("b", 10);
                model.CreateWindow =
                    CreateWindowClause.Create("MyWindowIWOMTwo", View.Create("keepall"))
                        .WithInsert(true)
                        .WithInsertWhereClause(where)
                        .WithAsEventTypeName("MyWindowIWOM");
                model.SelectClause = SelectClause.CreateWildcard();
                var text = eventRepresentationEnum.GetAnnotationTextForNonMap() +
                           " create window MyWindowIWOMTwo#keepall as select * from MyWindowIWOM insert where b=10";
                Assert.AreEqual(text.Trim(), model.ToEPL());

                var modelTwo = env.EplToModel(text);
                Assert.AreEqual(text.Trim(), modelTwo.ToEPL());
                modelTwo.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("windowTwo"));
                env.CompileDeploy(modelTwo, path).AddListener("windowTwo");

                EPAssertionUtil.AssertPropsPerRow(
                    env.GetEnumerator("windowTwo"),
                    new[] {"a", "b"},
                    new[] {new object[] {"E2", 10}, new object[] {"E3", 10}});

                // test select individual fields and from an insert-from named window
                env.CompileDeploy(
                    eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyWindowIWOMThree>() +
                    " @Name('windowThree') create window MyWindowIWOMThree#keepall as select a from MyWindowIWOMTwo insert where a = 'E2'",
                    path);
                EPAssertionUtil.AssertPropsPerRow(
                    env.GetEnumerator("windowThree"),
                    new[] {"a"},
                    new[] {new object[] {"E2"}});

                env.UndeployAll();
            }
        private void TryAssertionInsertWhereOMStaggered(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            IDictionary <string, object> dataType = MakeMap(new[] { new object[] { "a", typeof(string) }, new object[] { "b", typeof(int) } });

            epService.EPAdministrator.Configuration.AddEventType("MyMap", dataType);

            string      stmtTextCreateOne = eventRepresentationEnum.GetAnnotationText() + " create window MyWindowIWOM#keepall as select a, b from MyMap";
            EPStatement stmtCreateOne     = epService.EPAdministrator.CreateEPL(stmtTextCreateOne);

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreateOne.EventType.UnderlyingType));
            var listener = new SupportUpdateListener();

            stmtCreateOne.Events += listener.Update;

            // create insert into
            string stmtTextInsertOne = "insert into MyWindowIWOM select a, b from MyMap";

            epService.EPAdministrator.CreateEPL(stmtTextInsertOne);

            // populate some data
            epService.EPRuntime.SendEvent(MakeMap(new[] { new object[] { "a", "E1" }, new object[] { "b", 2 } }), "MyMap");
            epService.EPRuntime.SendEvent(MakeMap(new[] { new object[] { "a", "E2" }, new object[] { "b", 10 } }), "MyMap");
            epService.EPRuntime.SendEvent(MakeMap(new[] { new object[] { "a", "E3" }, new object[] { "b", 10 } }), "MyMap");

            // create window with keep-all using OM
            var model = new EPStatementObjectModel();

            eventRepresentationEnum.AddAnnotationForNonMap(model);
            Expression where   = Expressions.Eq("b", 10);
            model.CreateWindow = CreateWindowClause.Create("MyWindowIWOMTwo", View.Create("keepall"))
                                 .SetIsInsert(true)
                                 .SetInsertWhereClause(where);
            model.SelectClause = SelectClause.CreateWildcard();
            model.FromClause   = FromClause.Create(FilterStream.Create("MyWindowIWOM"));
            string text = eventRepresentationEnum.GetAnnotationTextForNonMap() + " create window MyWindowIWOMTwo#keepall as select * from MyWindowIWOM insert where b=10";

            Assert.AreEqual(text.Trim(), model.ToEPL());

            EPStatementObjectModel modelTwo = epService.EPAdministrator.CompileEPL(text);

            Assert.AreEqual(text.Trim(), modelTwo.ToEPL());

            EPStatement stmt = epService.EPAdministrator.Create(modelTwo);

            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), "a,b".Split(','), new[] { new object[] { "E2", 10 }, new object[] { "E3", 10 } });

            // test select individual fields and from an insert-from named window
            stmt = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window MyWindowIWOMThree#keepall as select a from MyWindowIWOMTwo insert where a = 'E2'");
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), "a".Split(','), new[] { new object[] { "E2" } });

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowIWOM", true);
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowIWOMTwo", true);
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowIWOMThree", true);
        }
Exemplo n.º 3
0
            public void Run(RegressionEnvironment env)
            {
                var expected = "create window MyWindowOM#keepall as (a1 string, a2 double, a3 int)";

                // create window object model
                var model = new EPStatementObjectModel();
                var clause = CreateWindowClause.Create("MyWindowOM").AddView("keepall");
                clause.WithColumn(new SchemaColumnDesc("a1", "string"));
                clause.WithColumn(new SchemaColumnDesc("a2", "double"));
                clause.WithColumn(new SchemaColumnDesc("a3", "int"));
                model.CreateWindow = clause;
                Assert.AreEqual(expected, model.ToEPL());
            }
Exemplo n.º 4
0
        public void TestOMCreateTableSyntax()
        {
            var expected = "create window MyWindow.win:keepall() as (a1 string, a2 double, a3 int)";

            // create window object model
            var model  = new EPStatementObjectModel();
            var clause = CreateWindowClause.Create("MyWindow").AddView("win", "keepall");

            clause.AddColumn(new SchemaColumnDesc("a1", "string", false, false));
            clause.AddColumn(new SchemaColumnDesc("a2", "double", false, false));
            clause.AddColumn(new SchemaColumnDesc("a3", "int", false, false));
            model.CreateWindow = clause;
            Assert.AreEqual(expected, model.ToEPL());

            var stmtCreate = _epService.EPAdministrator.Create(model);

            Assert.AreEqual(expected, stmtCreate.Text);
        }
Exemplo n.º 5
0
        private void RunAssertionOMCreateTableSyntax(EPServiceProvider epService)
        {
            string expected = "create window MyWindowOM#keepall as (a1 string, a2 double, a3 int)";

            // create window object model
            var model = new EPStatementObjectModel();
            CreateWindowClause clause = CreateWindowClause.Create("MyWindowOM").AddView("keepall");

            clause.AddColumn(new SchemaColumnDesc("a1", "string", false, false));
            clause.AddColumn(new SchemaColumnDesc("a2", "double", false, false));
            clause.AddColumn(new SchemaColumnDesc("a3", "int", false, false));
            model.CreateWindow = clause;
            Assert.AreEqual(expected, model.ToEPL());

            EPStatement stmtCreate = epService.EPAdministrator.Create(model);

            Assert.AreEqual(expected, stmtCreate.Text);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a window.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="windowName">Name of the window.</param>
        /// <param name="view">The view.</param>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="insertWhereExpression">The insert where expression.</param>
        /// <returns></returns>
        public static EPStatementObjectModel CreateWindowAsObjectModel <T>(
            this EPServiceProvider serviceProvider,
            string windowName,
            View view,
            EsperQuery <T> esperQuery,
            System.Linq.Expressions.Expression <Func <T, bool> > insertWhereExpression)
        {
            var deriveObjectModel = DeriveObjectModel(esperQuery);

            using (ScopedInstance <EPStatementObjectModel> .Set(deriveObjectModel)) {
                deriveObjectModel.CreateWindow          = CreateWindowClause.Create(windowName, view);
                deriveObjectModel.CreateWindow.IsInsert = false;
                if (insertWhereExpression != null)
                {
                    deriveObjectModel.CreateWindow.InsertWhereClause =
                        LinqToSoda.LinqToSodaExpression(insertWhereExpression);
                    deriveObjectModel.CreateWindow.IsInsert = true;
                }

                return(deriveObjectModel);
            }
        }
Exemplo n.º 7
0
        public void TestOM()
        {
            var fields = new string[] { "key", "value" };

            // create window object model
            var model = new EPStatementObjectModel();

            model.CreateWindow = CreateWindowClause.Create("MyWindow").AddView("win", "keepall");
            model.SelectClause = SelectClause.Create()
                                 .AddWithAsProvidedName("TheString", "key")
                                 .AddWithAsProvidedName("LongBoxed", "value");
            model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).FullName));

            var stmtCreate = _epService.EPAdministrator.Create(model);

            stmtCreate.AddListener(_listenerWindow);

            var stmtTextCreate = "create window MyWindow.win:keepall() as select TheString as key, LongBoxed as value from " + typeof(SupportBean).FullName;

            Assert.AreEqual(stmtTextCreate, model.ToEPL());

            var stmtTextInsert = "insert into MyWindow select TheString as key, LongBoxed as value from " + typeof(SupportBean).FullName;
            var modelInsert    = _epService.EPAdministrator.CompileEPL(stmtTextInsert);
            var stmtInsert     = _epService.EPAdministrator.Create(modelInsert);

            // Consumer statement object model
            model = new EPStatementObjectModel();
            Expression multi = Expressions.Multiply(Expressions.Property("value"), Expressions.Constant(2));

            model.SelectClause = SelectClause.Create().SetStreamSelector(StreamSelector.RSTREAM_ISTREAM_BOTH)
                                 .Add("key")
                                 .Add(multi, "value");
            model.FromClause = FromClause.Create(FilterStream.Create("MyWindow", Expressions.IsNotNull("value")));

            var stmtSelectOne = _epService.EPAdministrator.Create(model);

            stmtSelectOne.AddListener(_listenerStmtOne);
            var stmtTextSelectOne = "select irstream key, value*2 as value from MyWindow(value is not null)";

            Assert.AreEqual(stmtTextSelectOne, model.ToEPL());

            // send events
            SendSupportBean("E1", 10L);
            EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetNewAndReset(), fields, new object[] { "E1", 20L });
            EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E1", 10L });

            SendSupportBean("E2", 20L);
            EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetNewAndReset(), fields, new object[] { "E2", 40L });
            EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E2", 20L });

            // create delete stmt
            model             = new EPStatementObjectModel();
            model.OnExpr      = OnClause.CreateOnDelete("MyWindow", "s1");
            model.FromClause  = FromClause.Create(FilterStream.Create(typeof(SupportMarketDataBean).FullName, "s0"));
            model.WhereClause = Expressions.EqProperty("s0.symbol", "s1.key");
            _epService.EPAdministrator.Create(model);
            var stmtTextDelete = "on " + typeof(SupportMarketDataBean).FullName + " as s0 delete from MyWindow as s1 where s0.symbol=s1.key";

            Assert.AreEqual(stmtTextDelete, model.ToEPL());

            // send delete event
            SendMarketBean("E1");
            EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetOldAndReset(), fields, new object[] { "E1", 20L });
            EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetOldAndReset(), fields, new object[] { "E1", 10L });

            // send delete event again, none deleted now
            SendMarketBean("E1");
            Assert.IsFalse(_listenerStmtOne.IsInvoked);
            Assert.IsFalse(_listenerWindow.IsInvoked);

            // send delete event
            SendMarketBean("E2");
            EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetOldAndReset(), fields, new object[] { "E2", 40L });
            EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetOldAndReset(), fields, new object[] { "E2", 20L });

            // On-select object model
            model              = new EPStatementObjectModel();
            model.OnExpr       = OnClause.CreateOnSelect("MyWindow", "s1");
            model.WhereClause  = Expressions.EqProperty("s0.id", "s1.key");
            model.FromClause   = FromClause.Create(FilterStream.Create(typeof(SupportBean_B).FullName, "s0"));
            model.SelectClause = SelectClause.CreateStreamWildcard("s1");
            var statement = _epService.EPAdministrator.Create(model);

            statement.AddListener(_listenerOnSelect);
            var stmtTextOnSelect = "on " + typeof(SupportBean_B).FullName + " as s0 select s1.* from MyWindow as s1 where s0.id=s1.key";

            Assert.AreEqual(stmtTextOnSelect, model.ToEPL());

            // send some more events
            SendSupportBean("E3", 30L);
            SendSupportBean("E4", 40L);

            _epService.EPRuntime.SendEvent(new SupportBean_B("B1"));
            Assert.IsFalse(_listenerOnSelect.IsInvoked);

            // trigger on-select
            _epService.EPRuntime.SendEvent(new SupportBean_B("E3"));
            EPAssertionUtil.AssertProps(_listenerOnSelect.AssertOneGetNewAndReset(), fields, new object[] { "E3", 30L });

            stmtSelectOne.Dispose();
            stmtInsert.Dispose();
            stmtCreate.Dispose();
        }
Exemplo n.º 8
0
            public void Run(RegressionEnvironment env)
            {
                string[] fields = {"key", "value"};
                var path = new RegressionPath();

                // create window object model
                var model = new EPStatementObjectModel();
                model.CreateWindow = CreateWindowClause
                    .Create("MyWindow")
                    .AddView("keepall")
                    .WithAsEventTypeName("SupportBean");
                model.SelectClause = SelectClause.Create()
                    .AddWithAsProvidedName("TheString", "key")
                    .AddWithAsProvidedName("LongBoxed", "value");

                var stmtTextCreate =
                    "create window MyWindow#keepall as select TheString as key, LongBoxed as value from SupportBean";
                Assert.AreEqual(stmtTextCreate, model.ToEPL());

                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("create"));
                env.CompileDeploy(model, path).AddListener("create");

                var stmtTextInsert =
                    "insert into MyWindow select TheString as key, LongBoxed as value from SupportBean";
                env.EplToModelCompileDeploy(stmtTextInsert, path);

                // Consumer statement object model
                model = new EPStatementObjectModel();
                Expression multi = Expressions.Multiply(Expressions.Property("value"), Expressions.Constant(2));
                model.SelectClause = SelectClause.Create()
                    .SetStreamSelector(StreamSelector.RSTREAM_ISTREAM_BOTH)
                    .Add("key")
                    .Add(multi, "value");
                model.FromClause = FromClause.Create(FilterStream.Create("MyWindow", Expressions.IsNotNull("value")));
                var eplSelect = "select irstream key, value*2 as value from MyWindow(value is not null)";
                Assert.AreEqual(eplSelect, model.ToEPL());

                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("select"));
                env.CompileDeploy(model, path).AddListener("select");

                // send events
                SendSupportBean(env, "E1", 10L);
                EPAssertionUtil.AssertProps(
                    env.Listener("select").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E1", 20L});
                EPAssertionUtil.AssertProps(
                    env.Listener("create").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E1", 10L});

                SendSupportBean(env, "E2", 20L);
                EPAssertionUtil.AssertProps(
                    env.Listener("select").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E2", 40L});
                EPAssertionUtil.AssertProps(
                    env.Listener("create").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E2", 20L});

                // create delete stmt
                model = new EPStatementObjectModel();
                model.OnExpr = OnClause.CreateOnDelete("MyWindow", "S1");
                model.FromClause = FromClause.Create(FilterStream.Create("SupportMarketDataBean", "S0"));
                model.WhereClause = Expressions.EqProperty("S0.Symbol", "S1.key");

                var stmtTextDelete = "on SupportMarketDataBean as S0 delete from MyWindow as S1 where S0.Symbol=S1.key";
                Assert.AreEqual(stmtTextDelete, model.ToEPL());

                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("ondelete"));
                env.CompileDeploy(model, path).AddListener("ondelete");

                // send delete event
                SendMarketBean(env, "E1");
                EPAssertionUtil.AssertProps(
                    env.Listener("select").AssertOneGetOldAndReset(),
                    fields,
                    new object[] {"E1", 20L});
                EPAssertionUtil.AssertProps(
                    env.Listener("create").AssertOneGetOldAndReset(),
                    fields,
                    new object[] {"E1", 10L});

                // send delete event again, none deleted now
                SendMarketBean(env, "E1");
                Assert.IsFalse(env.Listener("select").IsInvoked);
                Assert.IsFalse(env.Listener("create").IsInvoked);

                // send delete event
                SendMarketBean(env, "E2");
                EPAssertionUtil.AssertProps(
                    env.Listener("select").AssertOneGetOldAndReset(),
                    fields,
                    new object[] {"E2", 40L});
                EPAssertionUtil.AssertProps(
                    env.Listener("create").AssertOneGetOldAndReset(),
                    fields,
                    new object[] {"E2", 20L});

                // On-select object model
                model = new EPStatementObjectModel();
                model.OnExpr = OnClause.CreateOnSelect("MyWindow", "S1");
                model.WhereClause = Expressions.EqProperty("S0.Id", "S1.key");
                model.FromClause = FromClause.Create(FilterStream.Create("SupportBean_B", "S0"));
                model.SelectClause = SelectClause.CreateStreamWildcard("S1");

                var stmtTextOnSelect = "on SupportBean_B as S0 select S1.* from MyWindow as S1 where S0.Id=S1.key";
                Assert.AreEqual(stmtTextOnSelect, model.ToEPL());

                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("onselect"));
                env.CompileDeploy(model, path).AddListener("onselect");

                // send some more events
                SendSupportBean(env, "E3", 30L);
                SendSupportBean(env, "E4", 40L);

                env.SendEventBean(new SupportBean_B("B1"));
                Assert.IsFalse(env.Listener("onselect").IsInvoked);

                // trigger on-select
                env.SendEventBean(new SupportBean_B("E3"));
                EPAssertionUtil.AssertProps(
                    env.Listener("onselect").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E3", 30L});

                env.UndeployAll();
            }