示例#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 RunAssertionRStreamOnly_Compile(EPServiceProvider epService)
        {
            string stmtText = "select rstream * from " + typeof(SupportBean).FullName + "#length(3)";
            EPStatementObjectModel model = epService.EPAdministrator.CompileEPL(stmtText);

            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(epService.Container, model);

            Assert.AreEqual(stmtText, model.ToEPL());
            EPStatement statement    = epService.EPAdministrator.Create(model);
            var         testListener = new SupportUpdateListener();

            statement.Events += testListener.Update;

            Object theEvent = SendEvent(epService, "a", 2);

            Assert.IsFalse(testListener.IsInvoked);

            SendEvents(epService, new string[] { "a", "b" });
            Assert.IsFalse(testListener.IsInvoked);

            SendEvent(epService, "d", 2);
            Assert.AreSame(theEvent, testListener.LastNewData[0].Underlying); // receive 'a' as new data
            Assert.IsNull(testListener.LastOldData);                          // receive no more old data

            statement.Dispose();
        }
示例#3
0
        public void TestWhere_Compile()
        {
            String stmtText = "select s0.id as idS0, s1.id as idS1 " +
                              "from pattern [every s0=" + typeof(SupportBean_S0).FullName +
                              " or every s1=" + typeof(SupportBean_S1).FullName + "] " +
                              "where s0.id is not null and s0.id<100 or s1.id is not null and s1.id>=100";
            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(stmtText);

            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);

            String reverse = model.ToEPL();

            Assert.AreEqual(stmtText, reverse);

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

            statement.Events += _updateListener.Update;

            SendEventS0(1);
            AssertEventIds(1, null);

            SendEventS0(101);
            Assert.IsFalse(_updateListener.IsInvoked);

            SendEventS1(1);
            Assert.IsFalse(_updateListener.IsInvoked);

            SendEventS1(100);
            AssertEventIds(null, 100);
        }
示例#4
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();
        }
示例#5
0
        public void TestCountOneViewOM()
        {
            EPStatementObjectModel 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);

            String 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.Events += _testListener.Update;

            RunAssertion();
        }
示例#6
0
        private void TryEnumeration(String expression)
        {
            String      epl  = expression + " select (callIt()).countOf(v => v < 6) as val0 from SupportBean";
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.Events += _listener.Update;
            Assert.AreEqual(typeof(int), stmt.EventType.GetPropertyType("val0"));

            _epService.EPRuntime.SendEvent(new SupportBean());
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "val0".Split(','), new Object[] { 2 });

            stmt.Dispose();

            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(epl);

            Assert.AreEqual(epl, model.ToEPL());
            EPStatement stmtTwo = _epService.EPAdministrator.Create(model);

            stmtTwo.Events += _listener.Update;
            Assert.AreEqual(epl, stmtTwo.Text);

            _epService.EPRuntime.SendEvent(new SupportBean());
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "val0".Split(','), new Object[] { 2 });

            stmtTwo.Dispose();
        }
        public void TestStar()
        {
            string epl = "select " +
                         "first(*) as firststar, " +
                         "first(sb.*) as firststarsb, " +
                         "last(*) as laststar, " +
                         "last(sb.*) as laststarsb, " +
                         "window(*) as windowstar, " +
                         "window(sb.*) as windowstarsb " +
                         "from SupportBean.win:length(2) as sb";
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.AddListener(_listener);

            RunAssertionStar();
            stmt.Dispose();

            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(epl);

            stmt = _epService.EPAdministrator.Create(model);
            stmt.AddListener(_listener);
            Assert.AreEqual(epl, model.ToEPL());

            RunAssertionStar();
        }
示例#8
0
        public void TestIndexedValuePropOM()
        {
            var epService = EPServiceProviderManager.GetDefaultProvider(SupportConfigFactory.GetConfiguration());

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            var type = typeof(SupportBeanComplexProps).FullName;

            var model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.CreateWildcard();
            PatternExpr pattern = Patterns.FollowedBy(Patterns.EveryFilter(type, "a"),
                                                      Patterns.Filter(Filter.Create(type, Expressions.EqProperty("Indexed[0]", "a.Indexed[0]")), "b"));

            model.FromClause = FromClause.Create(PatternStream.Create(pattern));
            model            = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);

            var patternText = "select * from pattern [every a=" + type + " -> b=" + type + "(Indexed[0]=a.Indexed[0])]";

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

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

            RunIndexedValueProp(epService, stmt);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#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 Run(RegressionEnvironment env)
            {
                var model = new EPStatementObjectModel();
                model.SelectClause = SelectClause.CreateWildcard();
                var fromClause = FromClause.Create(
                    FilterStream.Create("SupportBean_A", "streamA")
                        .AddView(View.Create("length", Expressions.Constant(3))),
                    FilterStream.Create("SupportBean_B", "streamB")
                        .AddView(View.Create("length", Expressions.Constant(3))),
                    FilterStream.Create("SupportBean_C", "streamC")
                        .AddView(View.Create("length", Expressions.Constant(3))));
                model.FromClause = fromClause;
                model.WhereClause = Expressions.And(
                    Expressions.EqProperty("streamA.Id", "streamB.Id"),
                    Expressions.EqProperty("streamB.Id", "streamC.Id"),
                    Expressions.EqProperty("streamA.Id", "streamC.Id"));
                model = env.CopyMayFail(model);

                var epl = "select * from " +
                          "SupportBean_A#length(3) as streamA, " +
                          "SupportBean_B#length(3) as streamB, " +
                          "SupportBean_C#length(3) as streamC " +
                          "where streamA.Id=streamB.Id " +
                          "and streamB.Id=streamC.Id " +
                          "and streamA.Id=streamC.Id";
                Assert.AreEqual(epl, model.ToEPL());

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

                RunJoinUniquePerId(env);

                env.UndeployAll();
            }
示例#11
0
        public void TestJoinUniquePerIdOM()
        {
            EPStatementObjectModel model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.CreateWildcard();
            FromClause fromClause = FromClause.Create(
                FilterStream.Create(_eventA, "streamA").AddView(View.Create("length", Expressions.Constant(3))),
                FilterStream.Create(_eventB, "streamB").AddView(View.Create("length", Expressions.Constant(3))),
                FilterStream.Create(_eventC, "streamC").AddView(View.Create("length", Expressions.Constant(3))));

            model.FromClause  = fromClause;
            model.WhereClause = Expressions.And(
                Expressions.EqProperty("streamA.id", "streamB.id"),
                Expressions.EqProperty("streamB.id", "streamC.id"),
                Expressions.EqProperty("streamA.id", "streamC.id"));
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);

            string joinStatement = "select * from " +
                                   _eventA + "#length(3) as streamA, " +
                                   _eventB + "#length(3) as streamB, " +
                                   _eventC + "#length(3) as streamC " +
                                   "where streamA.id=streamB.id " +
                                   "and streamB.id=streamC.id " +
                                   "and streamA.id=streamC.id";

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

            joinView.AddListener(_updateListener);
            Assert.AreEqual(joinStatement, model.ToEPL());

            RunJoinUniquePerId();
        }
        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();
        }
示例#13
0
        public void TestRStreamOnly_Compile()
        {
            _epService = EPServiceProviderManager.GetDefaultProvider(SupportConfigFactory.GetConfiguration());
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, this.GetType(), this.GetType().FullName);
            }

            string stmtText = "select rstream * from " + typeof(SupportBean).FullName + "#length(3)";
            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(stmtText);

            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(model);

            Assert.AreEqual(stmtText, model.ToEPL());
            EPStatement statement = _epService.EPAdministrator.Create(model);

            statement.AddListener(_testListener);

            object theEvent = SendEvent("a");

            Assert.IsFalse(_testListener.IsInvoked);

            SendEvents(new string[] { "a", "b" });
            Assert.IsFalse(_testListener.IsInvoked);

            SendEvent("d");
            Assert.AreSame(theEvent, _testListener.LastNewData[0].Underlying); // receive 'a' as new data
            Assert.IsNull(_testListener.LastOldData);                          // receive no more old data
            _testListener.Reset();
        }
        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);
        }
示例#15
0
        private void TryString(EPStatementObjectModel model, String epl, String[] input, bool?[] result)
        {
            EPStatement selectTestCase = _epService.EPAdministrator.Create(model);

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

            EPStatementObjectModel compiled = _epService.EPAdministrator.CompileEPL(
                epl);

            compiled = (EPStatementObjectModel)SerializableObjectCopier.Copy(
                compiled);
            Assert.AreEqual(epl, compiled.ToEPL());

            selectTestCase.Events += _listener.Update;
            Assert.AreEqual(
                typeof(bool?),
                selectTestCase.EventType.GetPropertyType("result"));

            for (int i = 0; i < input.Length; i++)
            {
                SendSupportBeanEvent(input[i]);
                EventBean theEvent = _listener.AssertOneGetNewAndReset();

                Assert.AreEqual(result[i], theEvent.Get("result"), "Wrong result for " + input[i]);
            }
            selectTestCase.Stop();
        }
示例#16
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();
            }
示例#17
0
        private void TryDatetime(String dialect)
        {
            long        msecDate   = DateTimeParser.ParseDefaultMSec("2002-05-30 09:00:00.000");
            String      expression = "expression long " + dialect + ":callIt() [ " + msecDate + "]";
            String      epl        = expression + " select callIt().GetHourOfDay() as val0, callIt().GetDayOfWeek() as val1 from SupportBean";
            EPStatement stmt       = _epService.EPAdministrator.CreateEPL(epl);

            stmt.Events += _listener.Update;
            Assert.That(stmt.EventType.GetPropertyType("val0"), Is.EqualTo(typeof(int)));
            Assert.That(stmt.EventType.GetPropertyType("val1"), Is.EqualTo(typeof(DayOfWeek)));

            _epService.EPRuntime.SendEvent(new SupportBean());
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "val0,val1".Split(','), new Object[] { 9, DayOfWeek.Thursday });

            stmt.Dispose();

            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(epl);

            Assert.AreEqual(epl, model.ToEPL());
            EPStatement stmtTwo = _epService.EPAdministrator.Create(model);

            stmtTwo.Events += _listener.Update;
            Assert.AreEqual(epl, stmtTwo.Text);

            _epService.EPRuntime.SendEvent(new SupportBean());
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "val0,val1".Split(','), new Object[] { 9, DayOfWeek.Thursday });

            stmtTwo.Dispose();
        }
示例#18
0
        private void RunAssertionNotExists_Compile(EPServiceProvider epService)
        {
            string stmtText = "select id from S0 where not exists (select * from S1#length(1000))";
            EPStatementObjectModel model = epService.EPAdministrator.CompileEPL(stmtText);

            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;

            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);

            stmt.Dispose();
        }
示例#19
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"));
        }
示例#20
0
        private void RunAssertionExistsInSelectOM(EPServiceProvider epService)
        {
            var subquery = new EPStatementObjectModel();

            subquery.SelectClause = SelectClause.CreateWildcard();
            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.SubqueryExists(subquery), "value");
            model = (EPStatementObjectModel)SerializableObjectCopier.Copy(epService.Container, model);

            string stmtText = "select exists (select * 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;

            RunTestExistsInSelect(epService, listener);

            stmt.Dispose();
        }
        public void TestWindowedUnGrouped()
        {
            string epl = "select " +
                         "first(TheString) as firststring, " +
                         "last(TheString) as laststring, " +
                         "first(IntPrimitive) as firstint, " +
                         "last(IntPrimitive) as lastint, " +
                         "window(IntPrimitive) as allint " +
                         "from SupportBean.win:length(2)";
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.AddListener(_listener);

            RunAssertionUngrouped();

            stmt.Dispose();

            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(epl);

            stmt = _epService.EPAdministrator.Create(model);
            stmt.AddListener(_listener);
            Assert.AreEqual(epl, model.ToEPL());

            RunAssertionUngrouped();

            stmt.Dispose();

            // test null-value provided
            EPStatement stmtWNull = _epService.EPAdministrator.CreateEPL("select window(intBoxed).take(10) from SupportBean.win:length(2)");

            stmtWNull.AddListener(_listener);
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
        }
示例#22
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 });
        }
示例#23
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();
        }
示例#24
0
        public void TestArrayExpressions_Compile()
        {
            String stmtText = "select {\"a\",\"b\"} as stringArray, " +
                              "{} as emptyArray, " +
                              "{1} as oneEleArray, " +
                              "{1,2,3} as intArray " +
                              "from " + typeof(SupportBean).FullName;
            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(stmtText);

            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 });
        }
示例#25
0
        private void RunAssertionRStreamOnly_OM(EPServiceProvider epService)
        {
            string stmtText = "select rstream * from " + typeof(SupportBean).FullName + "#length(3)";
            var    model    = new EPStatementObjectModel();

            model.SelectClause = SelectClause.CreateWildcard(StreamSelector.RSTREAM_ONLY);
            FromClause fromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).FullName).AddView(View.Create("length", Expressions.Constant(3))));

            model.FromClause = fromClause;
            model            = (EPStatementObjectModel)SerializableObjectCopier.Copy(epService.Container, model);

            Assert.AreEqual(stmtText, model.ToEPL());
            EPStatement statement    = epService.EPAdministrator.Create(model);
            var         testListener = new SupportUpdateListener();

            statement.Events += testListener.Update;

            Object theEvent = SendEvent(epService, "a", 2);

            Assert.IsFalse(testListener.IsInvoked);

            SendEvents(epService, new string[] { "a", "b" });
            Assert.IsFalse(testListener.IsInvoked);

            SendEvent(epService, "d", 2);
            Assert.AreSame(theEvent, testListener.LastNewData[0].Underlying); // receive 'a' as new data
            Assert.IsNull(testListener.LastOldData);                          // receive no more old data

            statement.Dispose();
        }
示例#26
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);
        }
示例#27
0
        public void TestScriptUse()
        {
            _epService.EPAdministrator.CreateEPL("create expression int js:abc(p1, p2) [p1*p2*10]");
            _epService.EPAdministrator.CreateEPL("create expression int js:abc(p1) [p1*10]");

            String                epl      = "select abc(IntPrimitive, DoublePrimitive) as c0, abc(IntPrimitive) as c1 from SupportBean";
            EPStatement           stmt     = _epService.EPAdministrator.CreateEPL(epl);
            SupportUpdateListener listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            _epService.EPRuntime.SendEvent(MakeBean("E1", 10, 3.5));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "c0,c1".Split(','), new Object[] { 350, 100 });

            stmt.Dispose();

            // test SODA
            String eplExpr = "create expression somescript(i1) ['a']";
            EPStatementObjectModel modelExpr = _epService.EPAdministrator.CompileEPL(eplExpr);

            Assert.AreEqual(eplExpr, modelExpr.ToEPL());
            EPStatement stmtSODAExpr = _epService.EPAdministrator.Create(modelExpr);

            Assert.AreEqual(eplExpr, stmtSODAExpr.Text);

            String eplSelect = "select somescript(1) from SupportBean";
            EPStatementObjectModel modelSelect = _epService.EPAdministrator.CompileEPL(eplSelect);

            Assert.AreEqual(eplSelect, modelSelect.ToEPL());
            EPStatement stmtSODASelect = _epService.EPAdministrator.Create(modelSelect);

            Assert.AreEqual(eplSelect, stmtSODASelect.Text);
        }
示例#28
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);
        }
示例#29
0
        public void TestDefaultColumnsAndSODA()
        {
            string epl = "select " +
                         "case theString" +
                         " when \"A\" then new{theString=\"Q\",intPrimitive,col2=theString||\"A\"}" +
                         " when \"B\" then new{theString,intPrimitive=10,col2=theString||\"B\"} " +
                         "end as val0 from SupportBean as sb";

            EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.AddListener(_listener);
            RunAssertionDefault(stmt);

            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(epl);

            Assert.AreEqual(epl, model.ToEPL());
            stmt = _epService.EPAdministrator.Create(model);
            stmt.AddListener(_listener);
            RunAssertionDefault(stmt);

            // test to-expression string
            epl = "select " +
                  "case theString" +
                  " when \"A\" then new{theString=\"Q\",intPrimitive,col2=theString||\"A\" }" +
                  " when \"B\" then new{theString,intPrimitive = 10,col2=theString||\"B\" } " +
                  "end from SupportBean as sb";

            stmt = _epService.EPAdministrator.CreateEPL(epl);
            stmt.AddListener(_listener);
            Assert.AreEqual("case theString when \"A\" then new{theString=\"Q\",intPrimitive,col2=theString||\"A\"} when \"B\" then new{theString,intPrimitive=10,col2=theString||\"B\"} end", stmt.EventType.PropertyNames[0]);
        }
示例#30
0
        private void RunAssertionArrayExpressions_Compile()
        {
            string stmtText = "select {\"a\",\"b\"} as stringArray, " +
                              "{} as emptyArray, " +
                              "{1} as oneEleArray, " +
                              "{1,2,3} as intArray " +
                              "from " + typeof(SupportBean).Name;
            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(stmtText);

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

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

            stmt.AddListener(listener);

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

            _epService.EPRuntime.SendEvent(bean);

            EventBean theEvent = listener.AssertOneGetNewAndReset();

            EPAssertionUtil.AssertEqualsExactOrder(theEvent.Get("stringArray").UnwrapIntoArray <string>(), new string[] { "a", "b" });
            EPAssertionUtil.AssertEqualsExactOrder(theEvent.Get("emptyArray").UnwrapIntoArray <object>(), new object[0]);
            EPAssertionUtil.AssertEqualsExactOrder(theEvent.Get("oneEleArray").UnwrapIntoArray <int>(), new int[] { 1 });
            EPAssertionUtil.AssertEqualsExactOrder(theEvent.Get("intArray").UnwrapIntoArray <int>(), new int[] { 1, 2, 3 });

            stmt.Dispose();
        }