예제 #1
0
        public override void Run(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType(typeof(BankTxn));
            epService.EPAdministrator.Configuration.AddEventType(typeof(LoginEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(LogoutEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(SecurityEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(SensorEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(TrafficEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(TrainEnterEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(TrainLeaveEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(CumulativePrice));
            epService.EPAdministrator.Configuration.AddEventType(typeof(PassengerScanEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(MyStartEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(MyEndEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(MyInitEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(MyTermEvent));
            epService.EPAdministrator.Configuration.AddEventType(typeof(MyEvent));
            epService.EPAdministrator.Configuration.AddEventType("StartEventOne", typeof(MyStartEvent));
            epService.EPAdministrator.Configuration.AddEventType("StartEventTwo", typeof(MyStartEvent));
            epService.EPAdministrator.Configuration.AddEventType("MyOtherEvent", typeof(MyStartEvent));
            epService.EPAdministrator.Configuration.AddEventType("EndEventOne", typeof(MyEndEvent));
            epService.EPAdministrator.Configuration.AddEventType("EndEventTwo", typeof(MyEndEvent));

            Create(epService, "create context SegmentedByCustomer partition by custId from BankTxn");
            Create(
                epService,
                "context SegmentedByCustomer select custId, account, sum(amount) from BankTxn group by account");
            Create(
                epService, "context SegmentedByCustomer\n" +
                           "select * from pattern [\n" +
                           "every a=BankTxn(amount > 400) -> b=BankTxn(amount > 400) where timer:within(10 minutes)\n" +
                           "]");
            epService.EPAdministrator.DestroyAllStatements();
            Create(
                epService, "create context SegmentedByCustomer partition by\n" +
                           "custId from BankTxn, loginId from LoginEvent, loginId from LogoutEvent");
            epService.EPAdministrator.DestroyAllStatements();
            Create(
                epService, "create context SegmentedByCustomer partition by\n" +
                           "custId from BankTxn, loginId from LoginEvent(IsFailed=false)");
            epService.EPAdministrator.DestroyAllStatements();
            Create(epService, "create context ByCustomerAndAccount partition by custId and account from BankTxn");
            Create(epService, "context ByCustomerAndAccount select custId, account, sum(amount) from BankTxn");
            Create(
                epService, "context ByCustomerAndAccount\n" +
                           "  select context.name, context.id, context.key1, context.key2 from BankTxn");
            epService.EPAdministrator.DestroyAllStatements();
            Create(epService, "create context ByCust partition by custId from BankTxn");
            Create(
                epService, "context ByCust\n" +
                           "select * from BankTxn as t1 unidirectional, BankTxn#time(30) t2\n" +
                           "where t1.amount = t2.amount");
            Create(
                epService, "context ByCust\n" +
                           "select * from SecurityEvent as t1 unidirectional, BankTxn#time(30) t2\n" +
                           "where t1.customerName = t2.customerName");
            epService.EPAdministrator.DestroyAllStatements();
            Create(
                epService, "create context CategoryByTemp\n" +
                           "group temp < 65 as cold,\n" +
                           "group temp between 65 and 85 as normal,\n" +
                           "group temp > 85 as large\n" +
                           "from SensorEvent");
            Create(epService, "context CategoryByTemp select context.label, count(*) from SensorEvent");
            Create(
                epService, "context CategoryByTemp\n" +
                           "select context.name, context.id, context.label from SensorEvent");
            Create(epService, "create context NineToFive start (0, 9, *, *, *) end (0, 17, *, *, *)");
            Create(epService, "context NineToFive select * from TrafficEvent(speed >= 100)");
            Create(
                epService, "context NineToFive\n" +
                           "select context.name, context.startTime, context.endTime from TrafficEvent(speed >= 100)");
            Create(
                epService, "create context CtxTrainEnter\n" +
                           "initiated by TrainEnterEvent as te\n" +
                           "terminated after 5 minutes");
            Create(
                epService, "context CtxTrainEnter\n" +
                           "select *, context.te.trainId, context.id, context.name from TrainLeaveEvent(trainId = context.te.trainId)");
            Create(
                epService, "context CtxTrainEnter\n" +
                           "select t1 from pattern [\n" +
                           "t1=TrainEnterEvent -> timer:interval(5 min) and not TrainLeaveEvent(trainId = context.te.trainId)]");
            Create(
                epService, "create context CtxEachMinute\n" +
                           "initiated by pattern [every timer:interval(1 minute)]\n" +
                           "terminated after 1 minutes");
            Create(epService, "context CtxEachMinute select avg(temp) from SensorEvent");
            Create(
                epService, "context CtxEachMinute\n" +
                           "select context.id, avg(temp) from SensorEvent output snapshot when terminated");
            Create(
                epService, "context CtxEachMinute\n" +
                           "select context.id, avg(temp) from SensorEvent output snapshot every 1 minute and when terminated");
            Create(
                epService, "select venue, ccyPair, side, sum(qty)\n" +
                           "from CumulativePrice\n" +
                           "where side='O'\n" +
                           "group by venue, ccyPair, side");
            Create(
                epService, "create context MyContext partition by venue, ccyPair, side from CumulativePrice(side='O')");
            Create(epService, "context MyContext select venue, ccyPair, side, sum(qty) from CumulativePrice");

            Create(
                epService, "create context SegmentedByCustomerHash\n" +
                           "coalesce by consistent_hash_crc32(custId) from BankTxn granularity 16 preallocate");
            Create(
                epService, "context SegmentedByCustomerHash\n" +
                           "select custId, account, sum(amount) from BankTxn group by custId, account");
            Create(
                epService, "create context HashedByCustomer as coalesce\n" +
                           "consistent_hash_crc32(custId) from BankTxn,\n" +
                           "consistent_hash_crc32(loginId) from LoginEvent,\n" +
                           "consistent_hash_crc32(loginId) from LogoutEvent\n" +
                           "granularity 32 preallocate");

            epService.EPAdministrator.DestroyAllStatements();
            Create(
                epService, "create context HashedByCustomer\n" +
                           "coalesce consistent_hash_crc32(loginId) from LoginEvent(IsFailed = false)\n" +
                           "granularity 1024 preallocate");
            Create(
                epService,
                "create context ByCustomerHash coalesce consistent_hash_crc32(custId) from BankTxn granularity 1024");
            Create(
                epService, "context ByCustomerHash\n" +
                           "select context.name, context.id from BankTxn");

            Create(
                epService, "create context NineToFiveSegmented\n" +
                           "context NineToFive start (0, 9, *, *, *) end (0, 17, *, *, *),\n" +
                           "context SegmentedByCustomer partition by custId from BankTxn");
            Create(
                epService, "context NineToFiveSegmented\n" +
                           "select custId, account, sum(amount) from BankTxn group by account");
            Create(
                epService, "create context CtxNestedTrainEnter\n" +
                           "context InitCtx initiated by TrainEnterEvent as te terminated after 5 minutes,\n" +
                           "context HashCtx coalesce by consistent_hash_crc32(tagId) from PassengerScanEvent\n" +
                           "granularity 16 preallocate");
            Create(
                epService, "context CtxNestedTrainEnter\n" +
                           "select context.InitCtx.te.trainId, context.HashCtx.id,\n" +
                           "tagId, count(*) from PassengerScanEvent group by tagId");
            Create(
                epService, "context NineToFiveSegmented\n" +
                           "select context.NineToFive.startTime, context.SegmentedByCustomer.key1 from BankTxn");
            Create(epService, "context NineToFiveSegmented select context.name, context.id from BankTxn");

            Create(epService, "create context MyContext start MyStartEvent end MyEndEvent");
            Create(epService, "create context MyContext2 initiated MyEvent(level > 0) terminated after 10 seconds");
            Create(
                epService, "create context MyContext3 \n" +
                           "start MyEvent as myevent\n" +
                           "end MyEvent(id=myevent.id)");
            Create(
                epService, "create context MyContext4 \n" +
                           "initiated by MyInitEvent as e1 \n" +
                           "terminated by MyTermEvent(id=e1.id, level <> e1.level)");
            Create(
                epService,
                "create context MyContext5 start pattern [StartEventOne or StartEventTwo] end after 5 seconds");
            Create(
                epService,
                "create context MyContext6 initiated by pattern [every MyInitEvent -> MyOtherEvent where timer:within(5)] terminated by MyTermEvent");
            Create(
                epService, "create context MyContext7 \n" +
                           "  start pattern [a=StartEventOne or  b=StartEventTwo]\n" +
                           "  end pattern [EndEventOne(id=a.id) or EndEventTwo(id=b.id)]");
            Create(epService, "create context MyContext8 initiated (*, *, *, *, *) terminated after 10 seconds");
            Create(epService, "create context NineToFive start after 10 seconds end after 1 minute");
            Create(epService, "create context Overlap5SecFor1Min initiated after 5 seconds terminated after 1 minute");
            Create(
                epService, "create context CtxSample\n" +
                           "initiated by MyStartEvent as startevent\n" +
                           "terminated by MyEndEvent(id = startevent.id) as endevent");
            Create(
                epService,
                "context CtxSample select context.endevent.id, count(*) from MyEvent output snapshot when terminated");

            Create(
                epService, "create context TxnCategoryContext \n" +
                           "  group by amount < 100 as small, \n" +
                           "  group by amount between 100 and 1000 as medium, \n" +
                           "  group by amount > 1000 as large from BankTxn");
            var stmt = Create(epService, "context TxnCategoryContext select * from BankTxn#time(1 minute)");
            var categorySmall = new ProxyContextPartitionSelectorCategory(() => Collections.SingletonList("small"));

            stmt.GetEnumerator(categorySmall);

            var categorySmallMed = new ProxyContextPartitionSelectorCategory(
                () => new HashSet<string>(Collections.List("small", "medium")));

            Create(epService, "context TxnCategoryContext create window BankTxnWindow#time(1 min) as BankTxn");
            epService.EPRuntime.ExecuteQuery(
                "select count(*) from BankTxnWindow", new ContextPartitionSelector[] {categorySmallMed});

            epService.EPAdministrator.Configuration.AddEventType(typeof(MyTwoKeyInit));
            epService.EPAdministrator.Configuration.AddEventType(typeof(MyTwoKeyTerm));
            Create(
                epService, "create context CtxPerKeysAndExternallyControlled\n" +
                           "context PartitionedByKeys " +
                           "  partition by " +
                           "    key1, key2 from MyTwoKeyInit\n," +
                           "    key1, key2 from SensorEvent\n," +
                           "context InitiateAndTerm initiated by MyTwoKeyInit as e1 terminated by MyTwoKeyTerm(key1=e1.key1 and key2=e1.key2)");
            Create(
                epService, "context CtxPerKeysAndExternallyControlled\n" +
                           "select key1, key2, avg(temp) as avgTemp, count(*) as cnt\n" +
                           "from SensorEvent\n" +
                           "output snapshot when terminated\n" +
                           "// note: no group-by needed since \n");
        }
예제 #2
0
        public void Run(RegressionEnvironment env)
        {
            var path = new RegressionPath();
            Create(env, path, "create context SegmentedByCustomer partition by CustId from BankTxn");
            Create(
                env,
                path,
                "context SegmentedByCustomer select CustId, Account, sum(Amount) from BankTxn group by Account");
            Create(
                env,
                path,
                "context SegmentedByCustomer\n" +
                "select * from pattern [\n" +
                "every a=BankTxn(Amount > 400) -> b=BankTxn(Amount > 400) where timer:within(10 minutes)\n" +
                "]");
            UndeployClearPath(env, path);
            Create(
                env,
                path,
                "create context SegmentedByCustomer partition by\n" +
                "CustId from BankTxn, LoginId from LoginEvent, LoginId from LogoutEvent");
            UndeployClearPath(env, path);
            Create(
                env,
                path,
                "create context SegmentedByCustomer partition by\n" +
                "CustId from BankTxn, LoginId from LoginEvent(IsFailed=false)");
            UndeployClearPath(env, path);
            Create(env, path, "create context ByCustomerAndAccount partition by CustId and Account from BankTxn");
            Create(env, path, "context ByCustomerAndAccount select CustId, Account, sum(Amount) from BankTxn");
            Create(
                env,
                path,
                "context ByCustomerAndAccount\n" +
                "  select context.name, context.id, context.key1, context.key2 from BankTxn");
            UndeployClearPath(env, path);
            Create(env, path, "create context ByCust partition by CustId from BankTxn");
            Create(
                env,
                path,
                "context ByCust\n" +
                "select * from BankTxn as t1 unidirectional, BankTxn#time(30) t2\n" +
                "where t1.Amount = t2.Amount");
            Create(
                env,
                path,
                "context ByCust\n" +
                "select * from SecurityEvent as t1 unidirectional, BankTxn#time(30) t2\n" +
                "where t1.CustomerName = t2.CustomerName");
            UndeployClearPath(env, path);
            Create(
                env,
                path,
                "create context CategoryByTemp\n" +
                "group Temp < 65 as cold,\n" +
                "group Temp between 65 and 85 as normal,\n" +
                "group Temp > 85 as large\n" +
                "from SensorEvent");
            Create(env, path, "context CategoryByTemp select context.label, count(*) from SensorEvent");
            Create(
                env,
                path,
                "context CategoryByTemp\n" +
                "select context.name, context.id, context.label from SensorEvent");
            Create(env, path, "create context NineToFive start (0, 9, *, *, *) end (0, 17, *, *, *)");
            Create(env, path, "context NineToFive select * from TrafficEvent(Speed >= 100)");
            Create(
                env,
                path,
                "context NineToFive\n" +
                "select context.name, context.startTime, context.endTime from TrafficEvent(Speed >= 100)");
            Create(
                env,
                path,
                "create context CtxTrainEnter\n" +
                "initiated by TrainEnterEvent as te\n" +
                "terminated after 5 minutes");
            Create(
                env,
                path,
                "context CtxTrainEnter\n" +
                "select *, context.te.TrainId, context.id, context.name from TrainLeaveEvent(TrainId = context.te.TrainId)");
            Create(
                env,
                path,
                "context CtxTrainEnter\n" +
                "select t1 from pattern [\n" +
                "t1=TrainEnterEvent -> timer:interval(5 min) and not TrainLeaveEvent(TrainId = context.te.TrainId)]");
            Create(
                env,
                path,
                "create context CtxEachMinute\n" +
                "initiated by pattern [every timer:interval(1 minute)]\n" +
                "terminated after 1 minutes");
            Create(env, path, "context CtxEachMinute select avg(Temp) from SensorEvent");
            Create(
                env,
                path,
                "context CtxEachMinute\n" +
                "select context.id, avg(Temp) from SensorEvent output snapshot when terminated");
            Create(
                env,
                path,
                "context CtxEachMinute\n" +
                "select context.id, avg(Temp) from SensorEvent output snapshot every 1 minute and when terminated");
            Create(
                env,
                path,
                "select Venue, CcyPair, Side, sum(Qty)\n" +
                "from CumulativePrice\n" +
                "where Side='O'\n" +
                "group by Venue, CcyPair, Side");
            Create(
                env,
                path,
                "create context MyContext partition by Venue, CcyPair, Side from CumulativePrice(Side='O')");
            Create(env, path, "context MyContext select Venue, CcyPair, Side, sum(Qty) from CumulativePrice");

            Create(
                env,
                path,
                "create context SegmentedByCustomerHash\n" +
                "coalesce by consistent_hash_crc32(CustId) from BankTxn granularity 16 preallocate");
            Create(
                env,
                path,
                "context SegmentedByCustomerHash\n" +
                "select CustId, Account, sum(Amount) from BankTxn group by CustId, Account");
            Create(
                env,
                path,
                "create context HashedByCustomer as coalesce\n" +
                "consistent_hash_crc32(CustId) from BankTxn,\n" +
                "consistent_hash_crc32(LoginId) from LoginEvent,\n" +
                "consistent_hash_crc32(LoginId) from LogoutEvent\n" +
                "granularity 32 preallocate");

            UndeployClearPath(env, path);
            Create(
                env,
                path,
                "create context HashedByCustomer\n" +
                "coalesce consistent_hash_crc32(LoginId) from LoginEvent(IsFailed = false)\n" +
                "granularity 1024 preallocate");
            Create(
                env,
                path,
                "create context ByCustomerHash coalesce consistent_hash_crc32(CustId) from BankTxn granularity 1024");
            Create(
                env,
                path,
                "context ByCustomerHash\n" +
                "select context.name, context.id from BankTxn");

            Create(
                env,
                path,
                "create context NineToFiveSegmented\n" +
                "context NineToFive start (0, 9, *, *, *) end (0, 17, *, *, *),\n" +
                "context SegmentedByCustomer partition by CustId from BankTxn");
            Create(
                env,
                path,
                "context NineToFiveSegmented\n" +
                "select CustId, Account, sum(Amount) from BankTxn group by Account");
            Create(
                env,
                path,
                "create context CtxNestedTrainEnter\n" +
                "context InitCtx initiated by TrainEnterEvent as te terminated after 5 minutes,\n" +
                "context HashCtx coalesce by consistent_hash_crc32(TagId) from PassengerScanEvent\n" +
                "granularity 16 preallocate");
            Create(
                env,
                path,
                "context CtxNestedTrainEnter\n" +
                "select context.InitCtx.te.TrainId, context.HashCtx.id,\n" +
                "TagId, count(*) from PassengerScanEvent group by TagId");
            Create(
                env,
                path,
                "context NineToFiveSegmented\n" +
                "select context.NineToFive.startTime, context.SegmentedByCustomer.key1 from BankTxn");
            Create(env, path, "context NineToFiveSegmented select context.name, context.id from BankTxn");

            Create(env, path, "create context MyContext start MyStartEvent end MyEndEvent");
            Create(env, path, "create context MyContext2 initiated MyEvent(Level > 0) terminated after 10 seconds");
            Create(
                env,
                path,
                "create context MyContext3 \n" +
                "start MyEvent as myevent\n" +
                "end MyEvent(Id=myevent.Id)");
            Create(
                env,
                path,
                "create context MyContext4 \n" +
                "initiated by MyInitEvent as e1 \n" +
                "terminated by MyTermEvent(Id=e1.Id, Level <> e1.Level)");
            Create(
                env,
                path,
                "create context MyContext5 start pattern [StartEventOne or StartEventTwo] end after 5 seconds");
            Create(
                env,
                path,
                "create context MyContext6 initiated by pattern [every MyInitEvent -> MyOtherEvent where timer:within(5)] terminated by MyTermEvent");
            Create(
                env,
                path,
                "create context MyContext7 \n" +
                "  start pattern [a=StartEventOne or  b=StartEventTwo]\n" +
                "  end pattern [EndEventOne(Id=a.Id) or EndEventTwo(Id=b.Id)]");
            Create(env, path, "create context MyContext8 initiated (*, *, *, *, *) terminated after 10 seconds");
            Create(env, path, "create context NineToFive start after 10 seconds end after 1 minute");
            Create(env, path, "create context Overlap5SecFor1Min initiated after 5 seconds terminated after 1 minute");
            Create(
                env,
                path,
                "create context CtxSample\n" +
                "initiated by MyStartEvent as startevent\n" +
                "terminated by MyEndEvent(Id = startevent.Id) as endevent");
            Create(
                env,
                path,
                "context CtxSample select context.endevent.Id, count(*) from MyEvent output snapshot when terminated");

            Create(
                env,
                path,
                "create context TxnCategoryContext \n" +
                "  group by Amount < 100 as small, \n" +
                "  group by Amount between 100 and 1000 as medium, \n" +
                "  group by Amount > 1000 as large from BankTxn");
            Create(env, path, "@Name('s0') context TxnCategoryContext select * from BankTxn#time(1 minute)");
            ContextPartitionSelectorCategory categorySmall = new ProxyContextPartitionSelectorCategory {
                ProcLabels = () => Collections.SingletonList("small")
            };
            env.Statement("s0").GetEnumerator(categorySmall);
            ContextPartitionSelectorCategory categorySmallMed = new ProxyContextPartitionSelectorCategory {
                ProcLabels = () => new HashSet<string>(Arrays.AsList("small", "medium"))
            };
            Create(env, path, "context TxnCategoryContext create window BankTxnWindow#time(1 min) as BankTxn");
            var faf = env.CompileFAF("select count(*) from BankTxnWindow", path);
            env.Runtime.FireAndForgetService.ExecuteQuery(faf, new ContextPartitionSelector[] {categorySmallMed});

            Create(
                env,
                path,
                "create context CtxPerKeysAndExternallyControlled\n" +
                "context PartitionedByKeys " +
                "  partition by " +
                "    Key1, Key2 from MyTwoKeyInit\n," +
                "    Key1, Key2 from SensorEvent\n," +
                "context InitiateAndTerm initiated by MyTwoKeyInit as e1 terminated by MyTwoKeyTerm(Key1=e1.Key1 and Key2=e1.Key2)");
            Create(
                env,
                path,
                "context CtxPerKeysAndExternallyControlled\n" +
                "select Key1, Key2, avg(Temp) as avgTemp, count(*) as cnt\n" +
                "from SensorEvent\n" +
                "output snapshot when terminated\n" +
                "// note: no group-by needed since \n");

            Create(
                env,
                path,
                "create context PerCustId_TriggeredByLargeAmount\n" +
                "  partition by CustId from BankTxn \n" +
                "  initiated by BankTxn(Amount>100) as largeTxn");
            Create(
                env,
                path,
                "context PerCustId_TriggeredByLargeAmount select context.largeTxn, CustId, sum(Amount) from BankTxn");
            Create(
                env,
                path,
                "create context PerCustId_UntilExpired\n" +
                "  partition by CustId from BankTxn \n" +
                "  terminated by BankTxn(IsExpired=true)");
            Create(
                env,
                path,
                "context PerCustId_UntilExpired select CustId, sum(Amount) from BankTxn output last when terminated");
            Create(
                env,
                path,
                "create context PerCustId_TriggeredByLargeAmount_UntilExpired\n" +
                "  partition by CustId from BankTxn \n" +
                "  initiated by BankTxn(Amount>100) as txn\n" +
                "  terminated by BankTxn(IsExpired=true and User=txn.User)");
            Create(
                env,
                path,
                "create context PerCust_AmountGreater100\n" +
                "  partition by CustId from BankTxn(Amount>100)\n" +
                "  initiated by BankTxn");
            Create(env, path, "context PerCust_AmountGreater100 select CustId, sum(Amount) from BankTxn");
            Create(
                env,
                path,
                "create context PerCust_TriggeredByLargeTxn\n" +
                "  partition by CustId from BankTxn\n" +
                "  initiated by BankTxn(Amount>100)");
            Create(env, path, "context PerCust_TriggeredByLargeTxn select CustId, sum(Amount) from BankTxn");

            env.UndeployAll();
        }