Пример #1
0
            public void Run(RegressionEnvironment env)
            {
                var copier = SerializableObjectCopier.GetInstance(env.Container);

                var model = new EPStatementObjectModel();

                model.SelectClause = SelectClause.Create()
                                     .Add(
                    Expressions.CaseWhenThen()
                    .Add(Expressions.Eq("Symbol", "GE"), Expressions.Property("Volume"))
                    .Add(Expressions.Eq("Symbol", "DELL"), Expressions.Sum("Price")),
                    "p1");
                model.FromClause = FromClause.Create(
                    FilterStream
                    .Create(typeof(SupportMarketDataBean).Name)
                    .AddView("win", "length", Expressions.Constant(10)));
                model = copier.Copy(model);

                var epl = "select case" +
                          " when Symbol=\"GE\" then Volume" +
                          " when Symbol=\"DELL\" then sum(Price) " +
                          "end as p1 from SupportMarketDataBean.win:length(10)";

                Assert.AreEqual(epl, model.ToEPL());
                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                env.CompileDeploy(model).AddListener("s0").Milestone(0);

                Assert.AreEqual(typeof(double?), env.Statement("s0").EventType.GetPropertyType("p1"));

                RunCaseSyntax1Sum(env);

                env.UndeployAll();
            }
Пример #2
0
        private void RunAssertionAliasesAggregationOM(EPServiceProvider epService)
        {
            var model = new EPStatementObjectModel();

            model.SelectClause      = SelectClause.Create("symbol", "volume").Add(Expressions.Sum("price"), "mySum");
            model.FromClause        = FromClause.Create(FilterStream.Create(typeof(SupportMarketDataBean).FullName).AddView(View.Create("length", Expressions.Constant(20))));
            model.GroupByClause     = GroupByClause.Create("symbol");
            model.OutputLimitClause = OutputLimitClause.Create(6);
            model.OrderByClause     = OrderByClause.Create(Expressions.Sum("price")).Add("symbol", false);
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(epService.Container, model);

            string statementString = "select symbol, volume, sum(price) as mySum from " +
                                     typeof(SupportMarketDataBean).FullName + "#length(20) " +
                                     "group by symbol " +
                                     "output every 6 events " +
                                     "order by sum(price), symbol";

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

            var         testListener = new SupportUpdateListener();
            EPStatement statement    = epService.EPAdministrator.Create(model);

            statement.Events += testListener.Update;

            TryAssertionDefault(epService, testListener);

            statement.Dispose();
        }
Пример #3
0
        public void TestInstanceofStringAndNull_OM()
        {
            String stmtText = "select instanceof(TheString,string) as t0, " +
                              "instanceof(TheString,float,string,int) as t1 " +
                              "from " + typeof(SupportBean).FullName;

            EPStatementObjectModel model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create()
                                 .Add(Expressions.InstanceOf("TheString", "string"), "t0")
                                 .Add(Expressions.InstanceOf(Expressions.Property("TheString"), "float", "string", "int"), "t1");
            model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).FullName));
            model            = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);
            Assert.AreEqual(stmtText, model.ToEPL());

            EPStatement selectTestCase = _epService.EPAdministrator.Create(model);

            selectTestCase.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean("abc", 100));
            EventBean theEvent = _listener.AssertOneGetNewAndReset();

            Assert.IsTrue(theEvent.Get("t0").AsBoolean());
            Assert.IsTrue(theEvent.Get("t1").AsBoolean());

            _epService.EPRuntime.SendEvent(new SupportBean(null, 100));
            theEvent = _listener.AssertOneGetNewAndReset();
            Assert.IsFalse(theEvent.Get("t0").AsBoolean());
            Assert.IsFalse(theEvent.Get("t1").AsBoolean());
        }
Пример #4
0
        public void TestCountOneViewOM()
        {
            var model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create().SetStreamSelector(StreamSelector.RSTREAM_ISTREAM_BOTH)
                                 .Add("Symbol")
                                 .Add(Expressions.CountStar(), "countAll")
                                 .Add(Expressions.CountDistinct("volume"), "countDistVol")
                                 .Add(Expressions.Count("volume"), "countVol");
            model.FromClause  = FromClause.Create(FilterStream.Create(typeof(SupportMarketDataBean).FullName).AddView("win", "length", Expressions.Constant(3)));
            model.WhereClause = Expressions.Or()
                                .Add(Expressions.Eq("Symbol", "DELL"))
                                .Add(Expressions.Eq("Symbol", "IBM"))
                                .Add(Expressions.Eq("Symbol", "GE"));
            model.GroupByClause = GroupByClause.Create("Symbol");
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);

            var viewExpr = "select irstream Symbol, " +
                           "count(*) as countAll, " +
                           "count(distinct volume) as countDistVol, " +
                           "count(volume) as countVol" +
                           " from " + typeof(SupportMarketDataBean).FullName + ".win:length(3) " +
                           "where Symbol=\"DELL\" or Symbol=\"IBM\" or Symbol=\"GE\" " +
                           "group by Symbol";

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

            _selectTestView = _epService.EPAdministrator.Create(model);
            _selectTestView.AddListener(_testListener);

            RunAssertion();
        }
Пример #5
0
        public void TestLikeRegexStringAndNull_OM()
        {
            String stmtText = "select p00 like p01 as r1, " +
                              "p00 like p01 escape \"!\" as r2, " +
                              "p02 regexp p03 as r3 " +
                              "from " + typeof(SupportBean_S0).FullName;

            EPStatementObjectModel model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create()
                                 .Add(Expressions.Like(Expressions.Property("p00"), Expressions.Property("p01")), "r1")
                                 .Add(Expressions.Like(Expressions.Property("p00"), Expressions.Property("p01"), Expressions.Constant("!")), "r2")
                                 .Add(Expressions.Regexp(Expressions.Property("p02"), Expressions.Property("p03")), "r3");
            model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean_S0).FullName));
            model            = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);
            Assert.AreEqual(stmtText, model.ToEPL());

            EPStatement selectTestCase = _epService.EPAdministrator.Create(model);

            selectTestCase.Events += _testListener.Update;

            RunLikeRegexStringAndNull();

            String epl = "select * from " + typeof(SupportBean).FullName + "(TheString not like \"foo%\")";
            EPPreparedStatement eps       = _epService.EPAdministrator.PrepareEPL(epl);
            EPStatement         statement = _epService.EPAdministrator.Create(eps);

            Assert.AreEqual(epl, statement.Text);

            epl       = "select * from " + typeof(SupportBean).FullName + "(TheString not regexp \"foo\")";
            eps       = _epService.EPAdministrator.PrepareEPL(epl);
            statement = _epService.EPAdministrator.Create(eps);
            Assert.AreEqual(epl, statement.Text);
        }
Пример #6
0
        private void RunAssertionGetTimestamp_OM(EPServiceProvider epService)
        {
            SendTimer(epService, 0);
            string stmtText = "select current_timestamp() as t0 from " + typeof(SupportBean).FullName;

            var model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create().Add(Expressions.CurrentTimestamp(), "t0");
            model.FromClause   = FromClause.Create().Add(FilterStream.Create(typeof(SupportBean).FullName));
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(epService.Container, model);
            Assert.AreEqual(stmtText, model.ToEPL());

            EPStatement stmt     = epService.EPAdministrator.Create(model);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            Assert.AreEqual(typeof(long?), stmt.EventType.GetPropertyType("t0"));

            SendTimer(epService, 777);
            epService.EPRuntime.SendEvent(new SupportBean());
            EventBean theEvent = listener.AssertOneGetNewAndReset();

            AssertResults(theEvent, new object[] { 777L });

            stmt.Dispose();
        }
Пример #7
0
        private void RunAssertionWherePreviousOM(EPServiceProvider epService)
        {
            var subquery = new EPStatementObjectModel();

            subquery.SelectClause = SelectClause.Create().Add(Expressions.Previous(1, "id"));
            subquery.FromClause   = FromClause.Create(FilterStream.Create("S1").AddView(View.Create("length", Expressions.Constant(1000))));
            subquery.WhereClause  = Expressions.EqProperty("id", "s0.id");

            var model = new EPStatementObjectModel();

            model.FromClause   = FromClause.Create(FilterStream.Create("S0", "s0"));
            model.SelectClause = SelectClause.Create().Add(Expressions.Subquery(subquery), "value");
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(epService.Container, model);

            string stmtText = "select (select prev(1,id) from S1#length(1000) where id=s0.id) as value from S0 as s0";

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

            EPStatement stmt     = epService.EPAdministrator.Create(model);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;
            RunWherePrevious(epService, listener);

            stmt.Dispose();
        }
Пример #8
0
			public void Run(RegressionEnvironment env)
			{
				string textOne = "@Name('s0') select irstream CONCATSTRING(TheString) as val from SupportBean#length(10) group by IntPrimitive";
				TryGrouped(env, textOne, null);

				string textTwo = "@Name('s0') select irstream concatstring(TheString) as val from SupportBean#win:length(10) group by IntPrimitive";
				TryGrouped(env, textTwo, null);

				string textThree = "@Name('s0') select irstream concatstring(TheString) as val from SupportBean#length(10) group by IntPrimitive";
				EPStatementObjectModel model = env.EplToModel(textThree);
				SerializableObjectCopier.CopyMayFail(env.Container, model);
				Assert.AreEqual(textThree, model.ToEPL());
				TryGrouped(env, null, model);

				string textFour = "select irstream concatstring(TheString) as val from SupportBean#length(10) group by IntPrimitive";
				EPStatementObjectModel modelTwo = new EPStatementObjectModel();
				modelTwo.SelectClause = SelectClause
					.Create(StreamSelector.RSTREAM_ISTREAM_BOTH)
					.Add(Expressions.PlugInAggregation("concatstring", Expressions.Property("TheString")), "val");
				modelTwo.FromClause = FromClause.Create(FilterStream.Create("SupportBean").AddView(null, "length", Expressions.Constant(10)));
				modelTwo.GroupByClause = GroupByClause.Create("IntPrimitive");
				Assert.AreEqual(textFour, modelTwo.ToEPL());
				SerializableObjectCopier.CopyMayFail(env.Container, modelTwo);
				modelTwo.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
				TryGrouped(env, null, modelTwo);

				env.UndeployAll();
			}
Пример #9
0
        public void TestBitWiseOperators_OM()
        {
            String viewExpr = "select BytePrimitive&ByteBoxed as myFirstProperty, " +
                              "ShortPrimitive|ShortBoxed as mySecondProperty, " +
                              "IntPrimitive|IntBoxed as myThirdProperty, " +
                              "LongPrimitive^LongBoxed as myFourthProperty, " +
                              "BoolPrimitive&BoolBoxed as myFifthProperty " +
                              "from " + typeof(SupportBean).FullName + ".win:length(3)";

            EPStatementObjectModel model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create()
                                 .Add(Expressions.BinaryAnd().Add("BytePrimitive").Add("ByteBoxed"), "myFirstProperty")
                                 .Add(Expressions.BinaryOr().Add("ShortPrimitive").Add("ShortBoxed"), "mySecondProperty")
                                 .Add(Expressions.BinaryOr().Add("IntPrimitive").Add("IntBoxed"), "myThirdProperty")
                                 .Add(Expressions.BinaryXor().Add("LongPrimitive").Add("LongBoxed"), "myFourthProperty")
                                 .Add(Expressions.BinaryAnd().Add("BoolPrimitive").Add("BoolBoxed"), "myFifthProperty");
            model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).FullName).AddView("win", "length", Expressions.Constant(3)));
            model            = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);
            Assert.AreEqual(viewExpr, model.ToEPL());

            EPStatement selectTestView = _epService.EPAdministrator.CreateEPL(viewExpr);

            selectTestView.Events += _listener.Update;

            RunBitWiseOperators();
        }
Пример #10
0
        public void TestMinMaxWindowStats_OM()
        {
            String viewExpr = "select max(LongBoxed,IntBoxed) as myMax, " +
                              "max(LongBoxed,IntBoxed,ShortBoxed) as myMaxEx, " +
                              "min(LongBoxed,IntBoxed) as myMin, " +
                              "min(LongBoxed,IntBoxed,ShortBoxed) as myMinEx" +
                              " from " + typeof(SupportBean).FullName + "#length(3)";

            var model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create()
                                 .Add(Expressions.Max("LongBoxed", "IntBoxed"), "myMax")
                                 .Add(Expressions.Max(Expressions.Property("LongBoxed"),
                                                      Expressions.Property("IntBoxed"),
                                                      Expressions.Property("ShortBoxed")), "myMaxEx")
                                 .Add(Expressions.Min("LongBoxed", "IntBoxed"), "myMin")
                                 .Add(Expressions.Min(Expressions.Property("LongBoxed"),
                                                      Expressions.Property("IntBoxed"),
                                                      Expressions.Property("ShortBoxed")), "myMinEx");
            model.FromClause = FromClause
                               .Create(FilterStream.Create(typeof(SupportBean).FullName)
                                       .AddView("length", Expressions.Constant(3)));
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);
            Assert.AreEqual(viewExpr, model.ToEPL());

            EPStatement selectTestView = _epService.EPAdministrator.Create(model);

            selectTestView.Events += _testListener.Update;
            _testListener.Reset();

            RunMinMaxWindowStats();
        }
Пример #11
0
        private void RunAssertionInSelectOM(EPServiceProvider epService)
        {
            var subquery = new EPStatementObjectModel();

            subquery.SelectClause = SelectClause.Create("id");
            subquery.FromClause   = FromClause.Create(FilterStream.Create("S1").AddView(View.Create("length", Expressions.Constant(1000))));

            var model = new EPStatementObjectModel();

            model.FromClause   = FromClause.Create(FilterStream.Create("S0"));
            model.SelectClause = SelectClause.Create().Add(Expressions.SubqueryIn("id", subquery), "value");
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(epService.Container, model);

            string stmtText = "select id in (select id from S1#length(1000)) as value from S0";

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

            EPStatement stmt     = epService.EPAdministrator.Create(model);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            RunTestInSelect(epService, listener);

            stmt.Dispose();
        }
Пример #12
0
        public void TestSameEventOM()
        {
            EPStatementObjectModel subquery = new EPStatementObjectModel();

            subquery.SelectClause = SelectClause.CreateWildcard();
            subquery.FromClause   = FromClause.Create(FilterStream.Create("S1").AddView(View.Create("length", Expressions.Constant(1000))));

            EPStatementObjectModel model = new EPStatementObjectModel();

            model.FromClause   = FromClause.Create(FilterStream.Create("S1"));
            model.SelectClause = SelectClause.Create().Add(Expressions.Subquery(subquery), "events1");
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);

            String stmtText = "select (select * from S1#length(1000)) as events1 from S1";

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

            EPStatement stmt = _epService.EPAdministrator.Create(model);

            stmt.Events += _listener.Update;

            EventType type = stmt.EventType;

            Assert.AreEqual(typeof(SupportBean_S1), type.GetPropertyType("events1"));

            Object theEvent = new SupportBean_S1(-1, "Y");

            _epService.EPRuntime.SendEvent(theEvent);
            EventBean result = _listener.AssertOneGetNewAndReset();

            Assert.AreSame(theEvent, result.Get("events1"));
        }
Пример #13
0
            public void Run(RegressionEnvironment env)
            {
                var stmtText = "select " +
                               "instanceof(TheString,string) as t0, " +
                               "instanceof(TheString,float,string,int) as t1 " +
                               "from SupportBean";

                var model = new EPStatementObjectModel();

                model.SelectClause = SelectClause.Create()
                                     .Add(Expressions.InstanceOf("TheString", "string"), "t0")
                                     .Add(Expressions.InstanceOf(Expressions.Property("TheString"), "float", "string", "int"), "t1");
                model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).Name));
                model            = SerializableObjectCopier.GetInstance(env.Container).Copy(model);
                Assert.AreEqual(stmtText, model.ToEPL());

                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                env.CompileDeploy(model).AddListener("s0").Milestone(0);

                env.SendEventBean(new SupportBean("abc", 100));
                var theEvent = env.Listener("s0").AssertOneGetNewAndReset();

                Assert.IsTrue((Boolean)theEvent.Get("t0"));
                Assert.IsTrue((Boolean)theEvent.Get("t1"));

                env.SendEventBean(new SupportBean(null, 100));
                theEvent = env.Listener("s0").AssertOneGetNewAndReset();
                Assert.IsFalse((Boolean)theEvent.Get("t0"));
                Assert.IsFalse((Boolean)theEvent.Get("t1"));

                env.UndeployAll();
            }
Пример #14
0
        private void RunAssertionBitWiseOperators_OM(EPServiceProvider epService)
        {
            string epl = "select bytePrimitive&byteBoxed as myFirstProperty, " +
                         "ShortPrimitive|ShortBoxed as mySecondProperty, " +
                         "IntPrimitive|IntBoxed as myThirdProperty, " +
                         "LongPrimitive^LongBoxed as myFourthProperty, " +
                         "BoolPrimitive&BoolBoxed as myFifthProperty " +
                         "from " + typeof(SupportBean).FullName + "#length(3)";

            var model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create()
                                 .Add(Expressions.BinaryAnd().Add("bytePrimitive").Add("byteBoxed"), "myFirstProperty")
                                 .Add(Expressions.BinaryOr().Add("ShortPrimitive").Add("ShortBoxed"), "mySecondProperty")
                                 .Add(Expressions.BinaryOr().Add("IntPrimitive").Add("IntBoxed"), "myThirdProperty")
                                 .Add(Expressions.BinaryXor().Add("LongPrimitive").Add("LongBoxed"), "myFourthProperty")
                                 .Add(Expressions.BinaryAnd().Add("BoolPrimitive").Add("BoolBoxed"), "myFifthProperty");

            model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).FullName).AddView("length", Expressions.Constant(3)));
            model            = (EPStatementObjectModel)SerializableObjectCopier.Copy(epService.Container, model);
            Assert.AreEqual(epl, model.ToEPL());

            EPStatement stmt     = epService.EPAdministrator.CreateEPL(epl);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            RunBitWiseOperators(epService, listener);

            stmt.Dispose();
        }
Пример #15
0
        public void TestTimeBatchOM()
        {
            String[] fields = ALL_FIELDS.Split(',');
            String   sql    = "select " + ALL_FIELDS + " from mytesttable where ${IntPrimitive} = mytesttable.mybigint";

            var model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create(fields);
            FromClause fromClause = FromClause.Create(
                SQLStream.Create("MyDB", sql, "s0"),
                FilterStream.Create(typeof(SupportBean).FullName, "s1").AddView(View.Create("win", "time_batch",
                                                                                            Expressions.Constant(10))
                                                                                ));

            model.FromClause = fromClause;
            SerializableObjectCopier.Copy(model);

            Assert.AreEqual(
                "select mybigint, myint, myvarchar, mychar, mybool, mynumeric, mydecimal, mydouble, myreal from sql:MyDB[\"select mybigint, myint, myvarchar, mychar, mybool, mynumeric, mydecimal, mydouble, myreal from mytesttable where ${IntPrimitive} = mytesttable.mybigint\"] as s0, com.espertech.esper.support.bean.SupportBean.win:time_batch(10) as s1",
                model.ToEPL());

            EPStatement stmt = _epService.EPAdministrator.Create(model);

            RuntestTimeBatch(stmt);

            stmt = _epService.EPAdministrator.CreateEPL(model.ToEPL());
        }
Пример #16
0
        public void TestGrouped()
        {
            var textOne = "select irstream CONCATSTRING(TheString) as val from " + typeof(SupportBean).FullName + ".win:length(10) group by IntPrimitive";

            TryGrouped(textOne, null);

            var textTwo = "select irstream concatstring(TheString) as val from " + typeof(SupportBean).FullName + ".win:length(10) group by IntPrimitive";

            TryGrouped(textTwo, null);

            var textThree = "select irstream concatstring(TheString) as val from " + typeof(SupportBean).FullName + ".win:length(10) group by IntPrimitive";
            var model     = _epService.EPAdministrator.CompileEPL(textThree);

            SerializableObjectCopier.Copy(model);
            Assert.AreEqual(textThree, model.ToEPL());
            TryGrouped(null, model);

            var textFour = "select irstream concatstring(TheString) as val from " + typeof(SupportBean).FullName + ".win:length(10) group by IntPrimitive";
            var modelTwo = new EPStatementObjectModel();

            modelTwo.SelectClause = SelectClause.Create().SetStreamSelector(StreamSelector.RSTREAM_ISTREAM_BOTH)
                                    .Add(Expressions.PlugInAggregation("concatstring", Expressions.Property("TheString")), "val");
            modelTwo.FromClause    = FromClause.Create(FilterStream.Create(typeof(SupportBean).FullName).AddView("win", "length", Expressions.Constant(10)));
            modelTwo.GroupByClause = GroupByClause.Create("IntPrimitive");
            Assert.AreEqual(textFour, modelTwo.ToEPL());
            SerializableObjectCopier.Copy(modelTwo);
            TryGrouped(null, modelTwo);

            var textFive = "select irstream concatstringTwo(TheString) as val from " + typeof(SupportBean).FullName + ".win:length(10) group by IntPrimitive";

            TryGrouped(textFive, null);
        }
Пример #17
0
        public void TestArrayNoArg()
        {
            var joinStatement = "select id, theString from "
                                + typeof(SupportBean).FullName + "#length(3) as s1, "
                                + "method:" + typeof(SupportStaticMethodLib).FullName
                                + ".FetchArrayNoArg";
            var stmt = _epService.EPAdministrator.CreateEPL(joinStatement);

            TryArrayNoArg(stmt);

            joinStatement = "select id, theString from "
                            + typeof(SupportBean).FullName + "#length(3) as s1, "
                            + "method:" + typeof(SupportStaticMethodLib).FullName
                            + ".FetchArrayNoArg()";
            stmt = _epService.EPAdministrator.CreateEPL(joinStatement);
            TryArrayNoArg(stmt);

            var model = _epService.EPAdministrator.CompileEPL(joinStatement);

            Assert.AreEqual(joinStatement, model.ToEPL());
            stmt = _epService.EPAdministrator.Create(model);
            TryArrayNoArg(stmt);

            model = new EPStatementObjectModel();
            model.SelectClause = SelectClause.Create("id", "theString");
            model.FromClause   = FromClause.Create()
                                 .Add(FilterStream.Create(typeof(SupportBean).FullName, "s1").AddView("length", Expressions.Constant(3)))
                                 .Add(MethodInvocationStream.Create(typeof(SupportStaticMethodLib).FullName, "FetchArrayNoArg"));
            stmt = _epService.EPAdministrator.Create(model);
            Assert.AreEqual(joinStatement, model.ToEPL());

            TryArrayNoArg(stmt);
        }
Пример #18
0
        public void TestCaseSyntax1WithElse_OM()
        {
            var model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create().Add(Expressions.CaseWhenThen()
                                                           .SetElse(Expressions.Property("Volume"))
                                                           .Add(Expressions.Eq("Symbol", "DELL"),
                                                                Expressions.Multiply(
                                                                    Expressions.Property("Volume"),
                                                                    Expressions.Constant(3))), "p1");
            model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportMarketDataBean).FullName).AddView("win", "length",
                                                                                                                     Expressions.
                                                                                                                     Constant(10)));
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);

            String caseExpr = "select case " +
                              "when Symbol=\"DELL\" then Volume*3 " +
                              "else Volume " +
                              "end as p1 from " + typeof(SupportMarketDataBean).FullName + ".win:length(10)";

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

            EPStatement selectTestCase = _epService.EPAdministrator.Create(model);

            selectTestCase.Events += _testListener.Update;
            Assert.AreEqual(typeof(long?), selectTestCase.EventType.GetPropertyType("p1"));

            RunCaseSyntax1WithElse();
        }
Пример #19
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('s0') select {\"a\",\"b\"} as StringArray, " +
                          "{} as EmptyArray, " +
                          "{1} as OneEleArray, " +
                          "{1,2,3} as IntArray " +
                          "from " +
                          typeof(SupportBean).Name;
                var model = new EPStatementObjectModel();

                model.Annotations  = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                model.SelectClause = SelectClause.Create()
                                     .Add(Expressions.Array().Add(Expressions.Constant("a")).Add(Expressions.Constant("b")), "StringArray")
                                     .Add(Expressions.Array(), "EmptyArray")
                                     .Add(Expressions.Array().Add(Expressions.Constant(1)), "OneEleArray")
                                     .Add(Expressions.Array().Add(Expressions.Constant(1)).Add(2).Add(3), "IntArray");

                model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).Name));
                Assert.AreEqual(epl, model.ToEPL());
                env.CompileDeploy(model).AddListener("s0");

                var bean = new SupportBean("a", 10);

                env.SendEventBean(bean);

                var theEvent = env.Listener("s0").AssertOneGetNewAndReset();

                EPAssertionUtil.AssertEqualsExactOrder(theEvent.Get("StringArray").Unwrap <string>(), new[] { "a", "b" });
                EPAssertionUtil.AssertEqualsExactOrder(theEvent.Get("EmptyArray").Unwrap <object>(), new object[0]);
                EPAssertionUtil.AssertEqualsExactOrder(theEvent.Get("OneEleArray").Unwrap <int>(), new int[] { 1 });
                EPAssertionUtil.AssertEqualsExactOrder(theEvent.Get("IntArray").Unwrap <int>(), new int[] { 1, 2, 3 });

                env.UndeployAll();
            }
Пример #20
0
        public void TestCaseSyntax2WithNull_OM()
        {
            String caseExpr = "select case IntPrimitive " +
                              "when 1 then null " +
                              "when 2 then 1.0d " +
                              "when 3 then null " +
                              "else 2 " +
                              "end as p1 from " + typeof(SupportBean).FullName + ".win:length(100)";

            var model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create().Add(Expressions.CaseSwitch("IntPrimitive")
                                                           .SetElse(Expressions.Constant(2))
                                                           .Add(Expressions.Constant(1), Expressions.Constant(null))
                                                           .Add(Expressions.Constant(2), Expressions.Constant(1.0))
                                                           .Add(Expressions.Constant(3), Expressions.Constant(null)),
                                                           "p1");
            model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).FullName).AddView("win", "length",
                                                                                                           Expressions.Constant(100)));
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);

            Assert.AreEqual(caseExpr, model.ToEPL());
            EPStatement selectTestCase = _epService.EPAdministrator.Create(model);

            selectTestCase.Events += _testListener.Update;
            Assert.AreEqual(typeof(double?), selectTestCase.EventType.GetPropertyType("p1"));

            RunCaseSyntax2WithNull();
        }
Пример #21
0
            public void Run(RegressionEnvironment env)
            {
                var subquery = new EPStatementObjectModel();
                subquery.SelectClause = SelectClause.CreateWildcard();
                subquery.FromClause = FromClause.Create(
                    FilterStream.Create("SupportBean_S1").AddView("length", Expressions.Constant(1000)));

                var model = new EPStatementObjectModel();
                model.SelectClause = SelectClause.Create("Id");
                model.FromClause = FromClause.Create(FilterStream.Create("SupportBean_S0"));
                model.WhereClause = Expressions.Not(Expressions.SubqueryExists(subquery));
                model = env.CopyMayFail(model);

                var stmtText =
                    "select Id from SupportBean_S0 where not exists (select * from SupportBean_S1#length(1000))";
                Assert.AreEqual(stmtText, model.ToEPL());

                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                env.CompileDeploy(model).AddListener("s0");

                env.SendEventBean(new SupportBean_S0(2));
                Assert.AreEqual(2, env.Listener("s0").AssertOneGetNewAndReset().Get("Id"));

                env.SendEventBean(new SupportBean_S1(-1));
                env.SendEventBean(new SupportBean_S0(1));
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.SendEventBean(new SupportBean_S1(-2));
                env.SendEventBean(new SupportBean_S0(3));
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.UndeployAll();
            }
Пример #22
0
        private void RunAssertionArrayNoArg(EPServiceProvider epService)
        {
            string joinStatement = "select id, TheString from " +
                                   typeof(SupportBean).FullName + "#length(3) as s1, " +
                                   "method:" + typeof(SupportStaticMethodLib).FullName + ".FetchArrayNoArg";
            EPStatement stmt = epService.EPAdministrator.CreateEPL(joinStatement);

            TryArrayNoArg(epService, stmt);

            joinStatement = "select id, TheString from " +
                            typeof(SupportBean).FullName + "#length(3) as s1, " +
                            "method:" + typeof(SupportStaticMethodLib).FullName + ".FetchArrayNoArg()";
            stmt = epService.EPAdministrator.CreateEPL(joinStatement);
            TryArrayNoArg(epService, stmt);

            EPStatementObjectModel model = epService.EPAdministrator.CompileEPL(joinStatement);

            Assert.AreEqual(joinStatement, model.ToEPL());
            stmt = epService.EPAdministrator.Create(model);
            TryArrayNoArg(epService, stmt);

            model = new EPStatementObjectModel();
            model.SelectClause = SelectClause.Create("id", "TheString");
            model.FromClause   = FromClause.Create()
                                 .Add(FilterStream.Create(typeof(SupportBean).FullName, "s1").AddView("length", Expressions.Constant(3)))
                                 .Add(MethodInvocationStream.Create(typeof(SupportStaticMethodLib).FullName, "FetchArrayNoArg"));
            stmt = epService.EPAdministrator.Create(model);
            Assert.AreEqual(joinStatement, model.ToEPL());

            TryArrayNoArg(epService, stmt);
        }
Пример #23
0
        public void TestCastDoubleAndNull_OM()
        {
            String stmtText = "select exists(item?.IntBoxed) as t0 " +
                              "from " + typeof(SupportMarkerInterface).FullName;

            EPStatementObjectModel model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create().Add(Expressions.ExistsProperty("item?.IntBoxed"), "t0");
            model.FromClause   = FromClause.Create(FilterStream.Create(typeof(SupportMarkerInterface).FullName));
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);
            Assert.AreEqual(stmtText, model.ToEPL());

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

            selectTestCase.Events += listener.Update;

            Assert.AreEqual(typeof(bool?), selectTestCase.EventType.GetPropertyType("t0"));

            epService.EPRuntime.SendEvent(new SupportBeanDynRoot(new SupportBean()));
            Assert.AreEqual(true, listener.AssertOneGetNewAndReset().Get("t0"));

            epService.EPRuntime.SendEvent(new SupportBeanDynRoot(null));
            Assert.AreEqual(false, listener.AssertOneGetNewAndReset().Get("t0"));

            epService.EPRuntime.SendEvent(new SupportBeanDynRoot("abc"));
            Assert.AreEqual(false, listener.AssertOneGetNewAndReset().Get("t0"));
        }
Пример #24
0
        private void RunAssertionArrayWithArg(EPServiceProvider epService)
        {
            string joinStatement = "select irstream id, TheString from " +
                                   typeof(SupportBean).FullName + "()#length(3) as s1, " +
                                   " method:" + typeof(SupportStaticMethodLib).FullName + ".FetchArrayGen(IntPrimitive)";
            EPStatement stmt = epService.EPAdministrator.CreateEPL(joinStatement);

            TryArrayWithArg(epService, stmt);

            joinStatement = "select irstream id, TheString from " +
                            "method:" + typeof(SupportStaticMethodLib).FullName + ".FetchArrayGen(IntPrimitive) as s0, " +
                            typeof(SupportBean).FullName + "#length(3)";
            stmt = epService.EPAdministrator.CreateEPL(joinStatement);
            TryArrayWithArg(epService, stmt);

            EPStatementObjectModel model = epService.EPAdministrator.CompileEPL(joinStatement);

            Assert.AreEqual(joinStatement, model.ToEPL());
            stmt = epService.EPAdministrator.Create(model);
            TryArrayWithArg(epService, stmt);

            model = new EPStatementObjectModel();
            model.SelectClause = SelectClause.Create("id", "TheString")
                                 .SetStreamSelector(StreamSelector.RSTREAM_ISTREAM_BOTH);
            model.FromClause = FromClause.Create()
                               .Add(MethodInvocationStream.Create(typeof(SupportStaticMethodLib).FullName, "FetchArrayGen", "s0")
                                    .AddParameter(Expressions.Property("IntPrimitive")))
                               .Add(FilterStream.Create(typeof(SupportBean).FullName).AddView("length", Expressions.Constant(3)));
            stmt = epService.EPAdministrator.Create(model);
            Assert.AreEqual(joinStatement, model.ToEPL());

            TryArrayWithArg(epService, stmt);
        }
Пример #25
0
            public void Run(RegressionEnvironment env)
            {
                var stmtText = "@Name('s0') select P00 like P01 as r1, " +
                               "P00 like P01 escape \"!\" as r2, " +
                               "P02 regexp P03 as r3 " +
                               "from SupportBean_S0";

                var model = new EPStatementObjectModel();

                model.Annotations  = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                model.SelectClause = SelectClause.Create()
                                     .Add(Expressions.Like(Expressions.Property("P00"), Expressions.Property("P01")), "r1")
                                     .Add(Expressions.Like(Expressions.Property("P00"), Expressions.Property("P01"), Expressions.Constant("!")), "r2")
                                     .Add(Expressions.Regexp(Expressions.Property("P02"), Expressions.Property("P03")), "r3");

                model.FromClause = FromClause.Create(FilterStream.Create("SupportBean_S0"));
                model            = SerializableObjectCopier.GetInstance(env.Container).Copy(model);
                Assert.AreEqual(stmtText, model.ToEPL());

                var compiled = env.Compile(model, new CompilerArguments(env.Configuration));

                env.Deploy(compiled).AddListener("s0").Milestone(0);

                RunLikeRegexStringAndNull(env);

                env.UndeployAll();
            }
Пример #26
0
            public void Run(RegressionEnvironment env)
            {
                var caseExpr = "@Name('s0') select TheString in (\"a\",\"b\",\"c\") as result from " +
                               typeof(SupportBean).Name;
                var model = new EPStatementObjectModel();
                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                model.SelectClause = SelectClause.Create().Add(Expressions.In("TheString", "a", "b", "c"), "result");
                model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).Name));

                TryString(
                    env,
                    model,
                    caseExpr,
                    new[] {"0", "a", "b", "c", "d", null},
                    new bool?[] {false, true, true, true, false, null});

                model = new EPStatementObjectModel();
                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                model.SelectClause = SelectClause.Create().Add(Expressions.NotIn("TheString", "a", "b", "c"), "result");
                model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).Name));
                env.CopyMayFail(model);

                TryString(
                    env,
                    "TheString not in ('a', 'b', 'c')",
                    new[] {"0", "a", "b", "c", "d", null},
                    new bool?[] {true, false, false, false, true, null});
            }
Пример #27
0
        public void TestArrayWithArg()
        {
            var joinStatement = "select irstream id, theString from " +
                                typeof(SupportBean).Name + "().win:length(3) as s1, " +
                                " method:com.espertech.esper.support.epl.SupportStaticMethodLib.FetchArrayGen(intPrimitive)";
            var stmt = _epService.EPAdministrator.CreateEPL(joinStatement);

            TryArrayWithArg(stmt);

            joinStatement = "select irstream id, theString from " +
                            "method:com.espertech.esper.support.epl.SupportStaticMethodLib.FetchArrayGen(intPrimitive) as s0, " +
                            typeof(SupportBean).Name + ".win:length(3)";
            stmt = _epService.EPAdministrator.CreateEPL(joinStatement);
            TryArrayWithArg(stmt);

            var model = _epService.EPAdministrator.CompileEPL(joinStatement);

            Assert.AreEqual(joinStatement, model.ToEPL());
            stmt = _epService.EPAdministrator.Create(model);
            TryArrayWithArg(stmt);

            model = new EPStatementObjectModel();
            model.SelectClause = SelectClause.Create("id", "theString").SetStreamSelector(StreamSelector.RSTREAM_ISTREAM_BOTH);
            model.FromClause   = FromClause.Create()
                                 .Add(MethodInvocationStream.Create(typeof(SupportStaticMethodLib).FullName, "FetchArrayGen", "s0")
                                      .AddParameter(Expressions.Property("intPrimitive")))
                                 .Add(FilterStream.Create(typeof(SupportBean).Name).AddView("win", "length", Expressions.Constant(3)));

            stmt = _epService.EPAdministrator.Create(model);
            Assert.AreEqual(joinStatement, model.ToEPL());

            TryArrayWithArg(stmt);
        }
Пример #28
0
        public void TestArrayExpressions_OM()
        {
            String stmtText = "select {\"a\",\"b\"} as stringArray, " +
                              "{} as emptyArray, " +
                              "{1} as oneEleArray, " +
                              "{1,2,3} as intArray " +
                              "from " + typeof(SupportBean).FullName;
            EPStatementObjectModel model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create()
                                 .Add(Expressions.Array().Add(Expressions.Constant("a")).Add(Expressions.Constant("b")), "stringArray")
                                 .Add(Expressions.Array(), "emptyArray")
                                 .Add(Expressions.Array().Add(Expressions.Constant(1)), "oneEleArray")
                                 .Add(Expressions.Array().Add(Expressions.Constant(1)).Add(2).Add(3), "intArray");
            model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).FullName));
            model            = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);
            Assert.AreEqual(stmtText, model.ToEPL());

            EPStatement           stmt     = _epService.EPAdministrator.Create(model);
            SupportUpdateListener listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SupportBean bean = new SupportBean("a", 10);

            _epService.EPRuntime.SendEvent(bean);

            EventBean theEvent = listener.AssertOneGetNewAndReset();

            EPAssertionUtil.AssertEqualsExactOrder((String[])theEvent.Get("stringArray"), new String[] { "a", "b" });
            EPAssertionUtil.AssertEqualsExactOrder((Object[])theEvent.Get("emptyArray"), new Object[0]);
            EPAssertionUtil.AssertEqualsExactOrder((int?[])theEvent.Get("oneEleArray"), new int?[] { 1 });
            EPAssertionUtil.AssertEqualsExactOrder((int?[])theEvent.Get("intArray"), new int?[] { 1, 2, 3 });
        }
Пример #29
0
        public void TestNotExists_OM()
        {
            EPStatementObjectModel subquery = new EPStatementObjectModel();

            subquery.SelectClause = SelectClause.CreateWildcard();
            subquery.FromClause   = FromClause.Create(FilterStream.Create("S1").AddView("win", "length", Expressions.Constant(1000)));

            EPStatementObjectModel model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.Create("id");
            model.FromClause   = FromClause.Create(FilterStream.Create("S0"));
            model.WhereClause  = Expressions.Not(Expressions.SubqueryExists(subquery));
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);

            String stmtText = "select id from S0 where not exists (select * from S1.win:length(1000))";

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

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

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean_S0(2));
            Assert.AreEqual(2, listener.AssertOneGetNewAndReset().Get("id"));

            epService.EPRuntime.SendEvent(new SupportBean_S1(-1));
            epService.EPRuntime.SendEvent(new SupportBean_S0(1));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new SupportBean_S1(-2));
            epService.EPRuntime.SendEvent(new SupportBean_S0(3));
            Assert.IsFalse(listener.IsInvoked);
        }
Пример #30
0
        private void RunAssertionGrouped(EPServiceProvider epService)
        {
            string textOne = "select irstream CONCATSTRING(TheString) as val from " + typeof(SupportBean).FullName + "#length(10) group by IntPrimitive";

            TryGrouped(epService, textOne, null);

            string textTwo = "select irstream concatstring(TheString) as val from " + typeof(SupportBean).FullName + "#win:length(10) group by IntPrimitive";

            TryGrouped(epService, textTwo, null);

            string textThree             = "select irstream concatstring(TheString) as val from " + typeof(SupportBean).FullName + "#length(10) group by IntPrimitive";
            EPStatementObjectModel model = epService.EPAdministrator.CompileEPL(textThree);

            SerializableObjectCopier.Copy(epService.Container, model);
            Assert.AreEqual(textThree, model.ToEPL());
            TryGrouped(epService, null, model);

            string textFour = "select irstream concatstring(TheString) as val from " + typeof(SupportBean).FullName + "#length(10) group by IntPrimitive";
            var    modelTwo = new EPStatementObjectModel();

            modelTwo.SelectClause = SelectClause.Create(StreamSelector.RSTREAM_ISTREAM_BOTH)
                                    .Add(Expressions.PlugInAggregation("concatstring", Expressions.Property("TheString")), "val");
            modelTwo.FromClause    = FromClause.Create(FilterStream.Create(typeof(SupportBean).FullName).AddView(null, "length", Expressions.Constant(10)));
            modelTwo.GroupByClause = GroupByClause.Create("IntPrimitive");
            Assert.AreEqual(textFour, modelTwo.ToEPL());
            SerializableObjectCopier.Copy(epService.Container, modelTwo);
            TryGrouped(epService, null, modelTwo);

            string textFive = "select irstream concatstringTwo(TheString) as val from " + typeof(SupportBean).FullName + "#length(10) group by IntPrimitive";

            TryGrouped(epService, textFive, null);

            epService.EPAdministrator.DestroyAllStatements();
        }