private void RunAssertionOnDemandQuery(EPServiceProvider epService)
        {
            epService.EPAdministrator.CreateEPL("create window MyWindowFour#keepall as select * from SupportBean");
            epService.EPAdministrator.CreateEPL("insert into MyWindowFour select * from SupportBean");

            epService.EPRuntime.SendEvent(new SupportBean("E1", 10));
            epService.EPRuntime.SendEvent(new SupportBean("E2", 20));
            epService.EPRuntime.SendEvent(new SupportBean("E3", 30));
            epService.EPRuntime.SendEvent(new SupportBean("E3", 31));
            epService.EPRuntime.SendEvent(new SupportBean("E1", 11));
            epService.EPRuntime.SendEvent(new SupportBean("E1", 12));

            EPOnDemandPreparedQuery q = epService.EPRuntime.PrepareQuery("select first(IntPrimitive) as f, window(IntPrimitive) as w, last(IntPrimitive) as l from MyWindowFour as s");

            EPAssertionUtil.AssertPropsPerRow(q.Execute().Array, "f,w,l".Split(','),
                                              new[] { new object[] { 10, IntArray(10, 20, 30, 31, 11, 12), 12 } });

            epService.EPRuntime.SendEvent(new SupportBean("E1", 13));
            EPAssertionUtil.AssertPropsPerRow(q.Execute().Array, "f,w,l".Split(','),
                                              new[] { new object[] { 10, IntArray(10, 20, 30, 31, 11, 12, 13), 13 } });

            q = epService.EPRuntime.PrepareQuery("select TheString as s, first(IntPrimitive) as f, window(IntPrimitive) as w, last(IntPrimitive) as l from MyWindowFour as s group by TheString order by TheString asc");
            var expected = new[]
            {
                new object[] { "E1", 10, IntArray(10, 11, 12, 13), 13 },
                new object[] { "E2", 20, IntArray(20), 20 },
                new object[] { "E3", 30, IntArray(30, 31), 31 }
            };

            EPAssertionUtil.AssertPropsPerRow(q.Execute().Array, "s,f,w,l".Split(','), expected);
            EPAssertionUtil.AssertPropsPerRow(q.Execute().Array, "s,f,w,l".Split(','), expected);

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 2
0
        public void TestOnDemandQuery()
        {
            _epService.EPAdministrator.CreateEPL("create window MyWindow.win:keepall() as select * from SupportBean");
            _epService.EPAdministrator.CreateEPL("insert into MyWindow select * from SupportBean");

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 10));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 20));
            _epService.EPRuntime.SendEvent(new SupportBean("E3", 30));
            _epService.EPRuntime.SendEvent(new SupportBean("E3", 31));
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 11));
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 12));

            EPOnDemandPreparedQuery q = _epService.EPRuntime.PrepareQuery("select first(IntPrimitive) as f, window(IntPrimitive) as w, last(IntPrimitive) as l from MyWindow as s");

            EPAssertionUtil.AssertPropsPerRow(q.Execute().Array, "f,w,l".Split(','),
                                              new object[][] { new object[] { 10, IntArray(10, 20, 30, 31, 11, 12), 12 } });

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 13));
            EPAssertionUtil.AssertPropsPerRow(q.Execute().Array, "f,w,l".Split(','),
                                              new object[][] { new object[] { 10, IntArray(10, 20, 30, 31, 11, 12, 13), 13 } });

            q = _epService.EPRuntime.PrepareQuery("select TheString as s, first(IntPrimitive) as f, window(IntPrimitive) as w, last(IntPrimitive) as l from MyWindow as s group by TheString order by TheString asc");
            object[][] expected = new object[][] {
                new object[] { "E1", 10, IntArray(10, 11, 12, 13), 13 },
                new object[] { "E2", 20, IntArray(20), 20 },
                new object[] { "E3", 30, IntArray(30, 31), 31 }
            };
            EPAssertionUtil.AssertPropsPerRow(q.Execute().Array, "s,f,w,l".Split(','), expected);
            EPAssertionUtil.AssertPropsPerRow(q.Execute().Array, "s,f,w,l".Split(','), expected);
        }
Exemplo n.º 3
0
        private void RunFAFQuery(EPOnDemandPreparedQuery query, int?expectedValue)
        {
            var result = query.Execute();

            Assert.AreEqual(1, result.Array.Length);
            Assert.AreEqual(expectedValue, result.Array[0].Get("sumi"));
        }
        private void RunQuery(String epl, String fields, Object[][] expected, ContextPartitionSelector[] selectors)
        {
            // try FAF without prepare
            EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery(epl, selectors);

            EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields.Split(','), expected);

            // test unparameterized prepare and execute
            EPOnDemandPreparedQuery preparedQuery  = _epService.EPRuntime.PrepareQuery(epl);
            EPOnDemandQueryResult   resultPrepared = preparedQuery.Execute(selectors);

            EPAssertionUtil.AssertPropsPerRowAnyOrder(resultPrepared.Array, fields.Split(','), expected);

            // test unparameterized prepare and execute
            EPOnDemandPreparedQueryParameterized preparedParameterizedQuery = _epService.EPRuntime.PrepareQueryWithParameters(epl);
            EPOnDemandQueryResult resultPreparedParameterized = _epService.EPRuntime.ExecuteQuery(preparedParameterizedQuery, selectors);

            EPAssertionUtil.AssertPropsPerRowAnyOrder(resultPreparedParameterized.Array, fields.Split(','), expected);

            // test SODA prepare and execute
            EPStatementObjectModel  modelForPrepare     = _epService.EPAdministrator.CompileEPL(epl);
            EPOnDemandPreparedQuery preparedQueryModel  = _epService.EPRuntime.PrepareQuery(modelForPrepare);
            EPOnDemandQueryResult   resultPreparedModel = preparedQueryModel.Execute(selectors);

            EPAssertionUtil.AssertPropsPerRowAnyOrder(resultPreparedModel.Array, fields.Split(','), expected);

            // test model query
            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(epl);

            result = _epService.EPRuntime.ExecuteQuery(model, selectors);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields.Split(','), expected);
        }
        private void RunFAFAssertion(EPServiceProvider epService, string epl, int?expected)
        {
            long start = PerformanceObserver.MilliTime;
            int  loops = 500;

            EPOnDemandPreparedQuery query = epService.EPRuntime.PrepareQuery(epl);

            for (int i = 0; i < loops; i++)
            {
                RunFAFQuery(query, expected);
            }
            long end   = PerformanceObserver.MilliTime;
            long delta = end - start;

            Assert.IsTrue(delta < 1500, "delta=" + delta);
        }
        private void RunAssertionFAFKeyAndRangePerformance(EPServiceProvider epService, bool namedWindow)
        {
            // create window one
            string eplCreate = namedWindow ?
                               "create window MyInfraFAFKR#keepall as SupportBean" :
                               "create table MyInfraFAFKR (TheString string primary key, IntPrimitive int primary key)";

            epService.EPAdministrator.CreateEPL(eplCreate);
            epService.EPAdministrator.CreateEPL("insert into MyInfraFAFKR select TheString, IntPrimitive from SupportBean");
            epService.EPAdministrator.CreateEPL("create index idx1 on MyInfraFAFKR(TheString hash, IntPrimitive btree)");

            // insert X rows
            int maxRows = 10000;   //for performance testing change to int maxRows = 100000;

            for (int i = 0; i < maxRows; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBean("A", i));
            }

            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive not in [3:9997]", 1 + 2 + 9998 + 9999);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive not in [3:9997)", 1 + 2 + 9997 + 9998 + 9999);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive not in (3:9997]", 1 + 2 + 3 + 9998 + 9999);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive not in (3:9997)", 1 + 2 + 3 + 9997 + 9998 + 9999);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'B' and IntPrimitive not in (3:9997)", null);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive between 200 and 202", 603);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive between 202 and 199", 199 + 200 + 201 + 202);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive >= 200 and IntPrimitive <= 202", 603);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive >= 202 and IntPrimitive <= 200", null);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive > 9997", 9998 + 9999);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive >= 9997", 9997 + 9998 + 9999);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive < 5", 4 + 3 + 2 + 1);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive <= 5", 5 + 4 + 3 + 2 + 1);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive in [200:202]", 603);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive in [200:202)", 401);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive in (200:202]", 403);
            RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive in (200:202)", 201);

            // test no value returned
            EPOnDemandPreparedQuery query  = epService.EPRuntime.PrepareQuery("select * from MyInfraFAFKR where TheString = 'A' and IntPrimitive < 0");
            EPOnDemandQueryResult   result = query.Execute();

            Assert.AreEqual(0, result.Array.Length);

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyInfraFAFKR", false);
        }
Exemplo n.º 7
0
        public void RunExample(bool isRunFromUnitTest, string engineURI)
        {
            int numEventsToLoad            = 100000;
            int numFireAndForgetExecutions = 100;
            int numOnEventQueryExecutions  = 100000;

            if (isRunFromUnitTest)
            {
                numEventsToLoad            = 1000;
                numFireAndForgetExecutions = 5;
                numOnEventQueryExecutions  = 5;
            }

            EPServiceProvider epService = EPServiceProviderManager.GetProvider(engineURI);

            // This example initializes the engine instance as it is running within an overall test suite.
            // This step would not be required unless re-using the same engine instance with different configurations.
            epService.Initialize();

            // define event type - this example uses Map event representation
            //
            IDictionary <String, Object> definition = new LinkedHashMap <String, Object>();

            definition.Put("sensor", typeof(string));
            definition.Put("temperature", typeof(double));

            epService.EPAdministrator.Configuration.AddEventType("SensorEvent", definition);

            // define a named window to hold the last 1000000 (1M) events
            //
            String stmtText = "create window SensorWindow.win:keepall() as select * from SensorEvent";

            Log.Info("Creating named window : " + stmtText);
            epService.EPAdministrator.CreateEPL(stmtText);

            stmtText = "insert into SensorWindow select * from SensorEvent";
            Log.Info("Creating insert statement for named window : " + stmtText);
            epService.EPAdministrator.CreateEPL(stmtText);

            // load 1M events
            //
            var random = new Random();

            String[] sensors = "s1,s2,s3,s4,s5,s6".Split(',');

            Log.Info("Generating " + numEventsToLoad + " sensor events for the named window");
            IList <IDictionary <String, Object> > events = new List <IDictionary <String, Object> >();

            for (int i = 0; i < numEventsToLoad; i++)
            {
                double temperature = Math.Round(random.NextDouble() * 10, 5, MidpointRounding.AwayFromZero) + 80;
                String sensor      = sensors[random.Next(sensors.Length)];

                IDictionary <String, Object> data = new LinkedHashMap <String, Object>();
                data.Put("temperature", temperature);
                data.Put("sensor", sensor);

                events.Add(data);
            }
            Log.Info("Completed generating sensor events");

            Log.Info("Sending " + events.Count + " sensor events into engine");
            foreach (var @event in events)
            {
                epService.EPRuntime.SendEvent(@event, "SensorEvent");
            }
            Log.Info("Completed sending sensor events");

            // prepare on-demand query
            //
            var sampleTemperature = (double)events[0].Get("temperature");

            stmtText = "select * from SensorWindow where temperature = " + sampleTemperature;
            Log.Info("Preparing fire-and-forget query : " + stmtText);
            EPOnDemandPreparedQuery onDemandQuery = epService.EPRuntime.PrepareQuery(stmtText);

            Log.Info("Executing fire-and-forget query " + numFireAndForgetExecutions + " times");
            long startTime = Environment.TickCount;

            for (int i = 0; i < numFireAndForgetExecutions; i++)
            {
                EPOnDemandQueryResult result = onDemandQuery.Execute();
                if (result.Array.Length != 1)
                {
                    throw new ApplicationException(
                              "Failed assertion of result, expected a single row returned from query");
                }
            }
            long   endTime  = Environment.TickCount;
            double deltaSec = (endTime - startTime) / 1000.0;

            Log.Info("Executing fire-and-forget query " + numFireAndForgetExecutions + " times took " + deltaSec +
                     " seconds");

            // prepare on-select
            //
            IDictionary <String, Object> definitionQuery = new LinkedHashMap <String, Object>();

            definitionQuery.Put("querytemp", typeof(double));
            epService.EPAdministrator.Configuration.AddEventType("SensorQueryEvent", definitionQuery);

            stmtText = "on SensorQueryEvent select sensor from SensorWindow where temperature = querytemp";
            Log.Info("Creating on-select statement for named window : " + stmtText);
            EPStatement onSelectStmt = epService.EPAdministrator.CreateEPL(stmtText);

            onSelectStmt.Subscriber = this;

            Log.Info("Executing on-select query " + numOnEventQueryExecutions + " times");
            startTime = Environment.TickCount;
            for (int i = 0; i < numOnEventQueryExecutions; i++)
            {
                IDictionary <String, Object> queryParams = new Dictionary <String, Object>();
                queryParams.Put("querytemp", sampleTemperature);

                epService.EPRuntime.SendEvent(queryParams, "SensorQueryEvent");
            }
            endTime  = Environment.TickCount;
            deltaSec = (endTime - startTime) / 1000.0;
            Log.Info("Executing on-select query " + numOnEventQueryExecutions + " times took " + deltaSec + " seconds");
        }
        private void RunAssertionFAFKeyPerformance(EPServiceProvider epService, bool namedWindow)
        {
            // create window one
            string stmtTextCreateOne = namedWindow ?
                                       "create window MyInfraOne#keepall as (f1 string, f2 int)" :
                                       "create table MyInfraOne (f1 string primary key, f2 int primary key)";

            epService.EPAdministrator.CreateEPL(stmtTextCreateOne);
            epService.EPAdministrator.CreateEPL("insert into MyInfraOne(f1, f2) select TheString, IntPrimitive from SupportBean");
            epService.EPAdministrator.CreateEPL("create index MyInfraOneIndex on MyInfraOne(f1)");

            // insert X rows
            int maxRows = 100;   //for performance testing change to int maxRows = 100000;

            for (int i = 0; i < maxRows; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBean("K" + i, i));
            }

            // fire N queries each returning 1 row
            long   start     = PerformanceObserver.MilliTime;
            string queryText = "select * from MyInfraOne where f1='K10'";
            EPOnDemandPreparedQuery query = epService.EPRuntime.PrepareQuery(queryText);
            int loops = 10000;

            for (int i = 0; i < loops; i++)
            {
                EPOnDemandQueryResult resultX = query.Execute();
                Assert.AreEqual(1, resultX.Array.Length);
                Assert.AreEqual("K10", resultX.Array[0].Get("f1"));
            }
            long end   = PerformanceObserver.MilliTime;
            long delta = end - start;

            Assert.IsTrue(delta < 500, "delta=" + delta);

            // test no value returned
            queryText = "select * from MyInfraOne where f1='KX'";
            query     = epService.EPRuntime.PrepareQuery(queryText);
            EPOnDemandQueryResult result = query.Execute();

            Assert.AreEqual(0, result.Array.Length);

            // test query null
            queryText = "select * from MyInfraOne where f1=null";
            query     = epService.EPRuntime.PrepareQuery(queryText);
            result    = query.Execute();
            Assert.AreEqual(0, result.Array.Length);

            // insert null and test null
            epService.EPRuntime.SendEvent(new SupportBean(null, -2));
            result = query.Execute();
            Assert.AreEqual(0, result.Array.Length);

            // test two values
            epService.EPRuntime.SendEvent(new SupportBean(null, -1));
            query  = epService.EPRuntime.PrepareQuery("select * from MyInfraOne where f1 is null order by f2 asc");
            result = query.Execute();
            Assert.AreEqual(2, result.Array.Length);
            Assert.AreEqual(-2, result.Array[0].Get("f2"));
            Assert.AreEqual(-1, result.Array[1].Get("f2"));

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyInfraOne", false);
        }