public object Call() { var selectQuery = "select * from MyWindow where TheString='" + threadKey + "' and LongPrimitive=?::int"; var compiled = env.CompileFAF(selectQuery, path); var prepared = env.Runtime.FireAndForgetService.PrepareQueryWithParameters(compiled); try { long total = 0; for (var loop = 0; loop < numRepeats; loop++) { // Insert event into named window SendMarketBean(threadKey, loop); total++; prepared.SetObject(1, loop); var queryResult = env.Runtime.FireAndForgetService.ExecuteQuery(prepared); Assert.AreEqual(1, queryResult.Array.Length); Assert.AreEqual(threadKey, queryResult.Array[0].Get("TheString")); Assert.AreEqual((long) loop, queryResult.Array[0].Get("LongPrimitive")); } } catch (Exception ex) { log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex); return false; } return true; }
public void Run(RegressionEnvironment env) { var path = new RegressionPath(); env.CompileDeploy("create context SegmentedByString partition by TheString from SupportBean", path); env.CompileDeploy("context SegmentedByString create window MyWindow#keepall as SupportBean", path); env.CompileDeploy("context SegmentedByString insert into MyWindow select * from SupportBean", path); var compiled = env.CompileFAF("select * from MyWindow", path); env.SendEventBean(new SupportBean("G1", 0)); env.Milestone(0); EPAssertionUtil.AssertPropsPerRow( env.Runtime.FireAndForgetService.ExecuteQuery(compiled).Array, new [] { "TheString" }, new[] {new object[] {"G1"}}); env.SendEventBean(new SupportBean("G2", 0)); env.Milestone(1); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Runtime.FireAndForgetService.ExecuteQuery(compiled).Array, new [] { "TheString" }, new[] {new object[] {"G1"}, new object[] {"G2"}}); env.UndeployAll(); }
public void Run(RegressionEnvironment env) { var path = new RegressionPath(); env.CompileDeploy("create window W1#unique(S1) as SupportSimpleBeanOne", path); env.CompileDeploy("insert into W1 select * from SupportSimpleBeanOne", path); env.CompileDeploy("create window W2#unique(S2) as SupportSimpleBeanTwo", path); env.CompileDeploy("insert into W2 select * from SupportSimpleBeanTwo", path); for (var i = 0; i < 1000; i++) { env.SendEventBean(new SupportSimpleBeanOne("A" + i, 0, 0, 0)); env.SendEventBean(new SupportSimpleBeanTwo("A" + i, 0, 0, 0)); } var start = PerformanceObserver.MilliTime; var compiled = env.CompileFAF("select * from W1 as w1, W2 as w2 where w1.S1 = w2.S2", path); var prepared = env.Runtime.FireAndForgetService.PrepareQuery(compiled); for (var i = 0; i < 100; i++) { var result = prepared.Execute(); Assert.AreEqual(1000, result.Array.Length); } var end = PerformanceObserver.MilliTime; var delta = end - start; Console.Out.WriteLine("Delta=" + delta); Assert.That(delta, Is.LessThan(1000), "Delta=" + delta); env.UndeployAll(); }
private static EPFireAndForgetPreparedQuery Prepare( RegressionEnvironment env, RegressionPath path, string queryText) { var compiled = env.CompileFAF(queryText, path); return env.Runtime.FireAndForgetService.PrepareQuery(compiled); }
private static EPFireAndForgetQueryResult CompileExecute( RegressionEnvironment env, RegressionPath path, string query) { var compiled = env.CompileFAF(query, path); return(env.Runtime.FireAndForgetService.ExecuteQuery(compiled)); }
private static void AssertQueryNoRows( RegressionEnvironment env, RegressionPath path, string query, Type resultType) { var compiled = env.CompileFAF(query, path); var result = env.Runtime.FireAndForgetService.ExecuteQuery(compiled); Assert.AreEqual(0, result.Array == null ? 0 : result.Array.Length); Assert.AreEqual(result.EventType.GetPropertyType("c0"), resultType); }
public void Run(RegressionEnvironment env) { var path = new RegressionPath(); var epl = "create window RectangleWindow#keepall as (Id string, Px double, Py double, Pw double, Ph double);\n" + "create index MyIndex on RectangleWindow((Px,Py,Pw,Ph) mxcifquadtree(0,0,100,100));\n" + "insert into RectangleWindow select Id, X as Px, Y as Py, Width as Pw, Height as Ph from SupportSpatialEventRectangle;\n" + "@Name('out') on SupportSpatialAABB as aabb select pt.Id as c0 from RectangleWindow as pt where rectangle(Px,Py,Pw,Ph).intersects(rectangle(X,Y,Width,Height));\n"; env.CompileDeploy(epl, path).AddListener("out"); var random = new Random(); var rectangles = RandomRectangles(random, NUM_POINTS, X, Y, WIDTH, HEIGHT); foreach (var rectangle in rectangles) { SendEventRectangle( env, rectangle.Id, rectangle.X.Value, rectangle.Y.Value, rectangle.Width.Value, rectangle.Height.Value); // Comment-me-in: log.info("Point: " + rectangle); } env.Milestone(0); for (var i = 0; i < NUM_QUERIES_AFTER_LOAD; i++) { RandomQuery(env, path, random, rectangles); } var milestone = new AtomicLong(); var deleteQuery = env.CompileFAF("delete from RectangleWindow where Id=?::string", path); var preparedDelete = env.Runtime.FireAndForgetService.PrepareQueryWithParameters(deleteQuery); while (!rectangles.IsEmpty()) { var removed = RandomRemove(random, rectangles); preparedDelete.SetObject(1, removed.Id); env.Runtime.FireAndForgetService.ExecuteQuery(preparedDelete); for (var i = 0; i < NUM_QUERIES_AFTER_EACH_REMOVE; i++) { RandomQuery(env, path, random, rectangles); } if (Array.BinarySearch(CHECKPOINT_REMAINING, rectangles.Count) >= 0) { log.Info("Checkpoint at " + rectangles.Count); env.MilestoneInc(milestone); preparedDelete = env.Runtime.FireAndForgetService.PrepareQueryWithParameters(deleteQuery); } } env.UndeployAll(); }
public void Run(RegressionEnvironment env) { var path = new RegressionPath(); var epl = "create table RectangleTable as (Id string primary key, Px double, Py double, Pw double, Ph double);\n" + "create index MyIndex on RectangleTable((Px,Py,Pw,Ph) mxcifquadtree(0,0,100,100));\n" + "insert into RectangleTable select Id, X as Px, Y as Py, Width as Pw, Height as Ph from SupportSpatialEventRectangle;\n" + "@Name('out') on SupportSpatialAABB as aabb select pt.Id as c0 from RectangleTable as pt where rectangle(Px,Py,Pw,Ph).intersects(rectangle(X,Y,Width,Height));\n"; env.CompileDeploy(epl, path).AddListener("out"); var random = new Random(); var rectangles = GenerateCoordinates(random, NUM_RECTANGLES, WIDTH, HEIGHT); foreach (var r in rectangles) { SendEventRectangle( env, r.Id, r.X.Value, r.Y.Value, r.Width.Value, r.Height.Value); } env.Milestone(0); var milestone = new AtomicLong(); var deleteQuery = env.CompileFAF("delete from RectangleTable where Id=?:Id:string", path); var preparedDelete = env.Runtime.FireAndForgetService.PrepareQueryWithParameters(deleteQuery); for (var i = 0; i < NUM_MOVES; i++) { var pointMoved = rectangles[random.Next(rectangles.Count)]; MovePoint(env, pointMoved, random, preparedDelete); var startX = pointMoved.X - 5; var startY = pointMoved.Y - 5; var bb = new BoundingBox( startX.Value, startY.Value, startX.Value + 10, startY.Value + 10); AssertBBRectangles(env, bb, rectangles); if (Array.BinarySearch(CHECKPOINT_AT, i) >= 0) { log.Info("Checkpoint at " + rectangles.Count); env.MilestoneInc(milestone); preparedDelete = env.Runtime.FireAndForgetService.PrepareQueryWithParameters(deleteQuery); } } env.UndeployAll(); }
private static void TryInvalidFAF( RegressionEnvironment env, RegressionPath path, string query, string expected) { var compiled = env.CompileFAF(query, path); try { env.Runtime.FireAndForgetService.ExecuteQuery(compiled); Assert.Fail(); } catch (EPException ex) { SupportMessageAssertUtil.AssertMessage(ex.Message, expected); } }
public void Run(RegressionEnvironment env) { var path = new RegressionPath(); var epl = "@public create window WinSB#lastevent as SupportBean;\n" + "insert into WinSB select * from SupportBean;\n"; if (namedWindow) { epl += "@public create window Infra#unique(Id) as (Id int, Value string);\n"; } else { epl += "@public create table Infra(Id int primary key, Value string);\n"; } epl += "@public create index InfraIndex on Infra(Value);\n" + "insert into Infra select Id, P00 as Value from SupportBean_S0;\n"; env.CompileDeploy(epl, path); SendSB(env, "E1", -1); for (var i = 0; i < 10000; i++) { SendS0(env, i, "v" + i); } var query = "select (select Id from Infra as i where i.Value = ?:p0:string) as c0 from WinSB"; var compiled = env.CompileFAF(query, path); var prepared = env.Runtime.FireAndForgetService.PrepareQueryWithParameters(compiled); var delta = PerformanceObserver.TimeMillis( () => { for (var i = 5000; i < 6000; i++) { prepared.SetObject("p0", "v" + i); var result = env.Runtime.FireAndForgetService.ExecuteQuery(prepared); Assert.AreEqual(1, result.Array.Length); Assert.AreEqual(i, result.Array[0].Get("c0")); } }); Assert.That(delta, Is.LessThan(1000), "delta is " + delta); env.UndeployAll(); }
private static void RunQueryAll( RegressionEnvironment env, RegressionPath path, string epl, string fields, object[][] expected, int numStreams) { var selectors = new ContextPartitionSelector[numStreams]; for (var i = 0; i < numStreams; i++) { selectors[i] = ContextPartitionSelectorAll.INSTANCE; } RunQuery(env, path, epl, fields, expected, selectors); // run same query without selector var compiled = env.CompileFAF(epl, path); var result = env.Runtime.FireAndForgetService.ExecuteQuery(compiled); EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields.SplitCsv(), expected); }
public void Run(RegressionEnvironment env) { var path = new RegressionPath(); env.CompileDeploy("create context PartitionedByString partition by TheString from SupportBean", path); env.CompileDeploy("context PartitionedByString create window MyWindow#keepall as SupportBean", path); env.CompileDeploy("insert into MyWindow select * from SupportBean", path); env.SendEventBean(new SupportBean("E1", 10)); env.SendEventBean(new SupportBean("E2", 20)); env.Milestone(0); env.SendEventBean(new SupportBean("E2", 21)); // test no context RunQueryAll( env, path, "select sum(IntPrimitive) as c1 from MyWindow", "c1", new[] {new object[] {51}}, 1); RunQueryAll( env, path, "select sum(IntPrimitive) as c1 from MyWindow where IntPrimitive > 15", "c1", new[] {new object[] {41}}, 1); RunQuery( env, path, "select sum(IntPrimitive) as c1 from MyWindow", "c1", new[] {new object[] {41}}, new ContextPartitionSelector[] {new SupportSelectorPartitioned(Collections.SingletonList(new object[] {"E2"}))}); RunQuery( env, path, "select sum(IntPrimitive) as c1 from MyWindow", "c1", new[] {new object[] {41}}, new ContextPartitionSelector[] {new SupportSelectorById(Collections.SingletonList(1))}); // test with context props RunQueryAll( env, path, "context PartitionedByString select context.key1 as c0, IntPrimitive as c1 from MyWindow", "c0,c1", new[] {new object[] {"E1", 10}, new object[] {"E2", 20}, new object[] {"E2", 21}}, 1); RunQueryAll( env, path, "context PartitionedByString select context.key1 as c0, IntPrimitive as c1 from MyWindow where IntPrimitive > 15", "c0,c1", new[] {new object[] {"E2", 20}, new object[] {"E2", 21}}, 1); // test targeted context partition RunQuery( env, path, "context PartitionedByString select context.key1 as c0, IntPrimitive as c1 from MyWindow where IntPrimitive > 15", "c0,c1", new[] {new object[] {"E2", 20}, new object[] {"E2", 21}}, new[] {new SupportSelectorPartitioned(Collections.SingletonList(new object[] {"E2"}))}); var compiled = env.CompileFAF("context PartitionedByString select * from MyWindow", path); try { env.Runtime.FireAndForgetService.ExecuteQuery( compiled, new ContextPartitionSelector[] { new ProxyContextPartitionSelectorCategory { ProcLabels = () => null } }); } catch (InvalidContextPartitionSelector ex) { Assert.IsTrue( ex.Message.StartsWith( "Invalid context partition selector, expected an implementation class of any of [ContextPartitionSelectorAll, ContextPartitionSelectorFiltered, ContextPartitionSelectorById, ContextPartitionSelectorSegmented] interfaces but received com"), "message: " + ex.Message); } env.UndeployAll(); }
public void Run(RegressionEnvironment env) { // Could have also used a mapping event however here we uses fire-and-forget to load the mapping instead: // @public @buseventtype create schema MappingEvent(foreignSymbol string, localSymbol string); // on MappingEvent merge Mapping insert select foreignSymbol, localSymbol; // The events are: // MappingEvent={foreignSymbol="ABC", localSymbol="123"} // MappingEvent={foreignSymbol="DEF", localSymbol="456"} // MappingEvent={foreignSymbol="GHI", localSymbol="789"} // MappingEvent={foreignSymbol="JKL", localSymbol="666"} // ForeignSymbols={companies={{symbol='ABC', value=500}, {symbol='DEF', value=300}, {symbol='JKL', value=400}}} // LocalSymbols={companies={{symbol='123', value=600}, {symbol='456', value=100}, {symbol='789', value=200}}} var path = new RegressionPath(); var epl = "create schema Symbol(symbol string, value double);\n" + "@public @buseventtype create schema ForeignSymbols(companies Symbol[]);\n" + "@public @buseventtype create schema LocalSymbols(companies Symbol[]);\n" + "\n" + "create table Mapping(foreignSymbol string primary key, localSymbol string primary key);\n" + "create index MappingIndexForeignSymbol on Mapping(foreignSymbol);\n" + "create index MappingIndexLocalSymbol on Mapping(localSymbol);\n" + "\n" + "insert into SymbolsPair select * from ForeignSymbols#lastevent as foreign, LocalSymbols#lastevent as local;\n" + "on SymbolsPair\n" + " insert into SymbolsPairBeginEvent select null\n" + " insert into ForeignSymbolRow select * from [foreign.companies]\n" + " insert into LocalSymbolRow select * from [local.companies]\n" + " insert into SymbolsPairOutputEvent select null" + " insert into SymbolsPairEndEvent select null" + " output all;\n" + "\n" + "create context SymbolsPairContext start SymbolsPairBeginEvent end SymbolsPairEndEvent;\n" + "context SymbolsPairContext create table Result(foreignSymbol string primary key, localSymbol string primary key, value double);\n" + "\n" + "context SymbolsPairContext on ForeignSymbolRow as fsr merge Result as result where result.foreignSymbol = fsr.symbol\n" + " when not matched then insert select fsr.symbol as foreignSymbol,\n" + " (select localSymbol from Mapping as mapping where mapping.foreignSymbol = fsr.symbol) as localSymbol, fsr.value as value\n" + " when matched and fsr.value > result.value then update set value = fsr.value;\n" + "\n" + "context SymbolsPairContext on LocalSymbolRow as lsr merge Result as result where result.localSymbol = lsr.symbol\n" + " when not matched then insert select (select foreignSymbol from Mapping as mapping where mapping.localSymbol = lsr.symbol) as foreignSymbol," + " lsr.symbol as localSymbol, lsr.value as value\n" + " when matched and lsr.value > result.value then update set value = lsr.value;\n" + "\n" + "@Name('out') context SymbolsPairContext on SymbolsPairOutputEvent select foreignSymbol, localSymbol, value from Result order by foreignSymbol asc;\n"; env.CompileDeploy(epl, path).AddListener("out"); // load mapping table var compiledFAF = env.CompileFAF("insert into Mapping select ?::string as foreignSymbol, ?::string as localSymbol", path); var preparedFAF = env.Runtime.FireAndForgetService.PrepareQueryWithParameters(compiledFAF); LoadMapping(env, preparedFAF, "ABC", "123"); LoadMapping(env, preparedFAF, "DEF", "456"); LoadMapping(env, preparedFAF, "GHI", "789"); LoadMapping(env, preparedFAF, "JKL", "666"); SendForeignSymbols(env, "ABC=500,DEF=300,JKL=400"); SendLocalSymbols(env, "123=600,456=100,789=200"); var results = env.Listener("out").GetAndResetLastNewData(); EPAssertionUtil.AssertPropsPerRow( results, "foreignSymbol,localSymbol,value".SplitCsv(), new object[][] { new object[] {"ABC", "123", 600d}, new object[] {"DEF", "456", 300d}, new object[] {"GHI", "789", 200d}, new object[] {"JKL", "666", 400d} }); env.UndeployAll(); }
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(); }