/// <summary> /// Ctor. /// </summary> /// <param name="events">to dispatch</param> /// <param name="statementResultService">handles result indicate</param> public OutboundUnitRunnable( UniformPair<EventBean[]> events, StatementResultServiceImpl statementResultService) { this.events = events; this.statementResultService = statementResultService; }
private void RunAssertionJoinSortWindow(EPServiceProvider epService) { SendTimer(epService, 0); string epl = "select irstream volume, max(price) as maxVol" + " from " + typeof(SupportMarketDataBean).FullName + "#sort(1, volume desc) as s0," + typeof(SupportBean).FullName + "#keepall as s1 " + "output every 1 seconds"; EPStatement stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("JOIN_KEY", -1)); SendEvent(epService, "JOIN_KEY", 1d); SendEvent(epService, "JOIN_KEY", 2d); listener.Reset(); // moves all events out of the window, SendTimer(epService, 1000); // newdata is 2 eventa, old data is the same 2 events, therefore the sum is null UniformPair <EventBean[]> result = listener.GetDataListsFlattened(); Assert.AreEqual(2, result.First.Length); Assert.AreEqual(1.0, result.First[0].Get("maxVol")); Assert.AreEqual(2.0, result.First[1].Get("maxVol")); Assert.AreEqual(1, result.Second.Length); Assert.AreEqual(2.0, result.Second[0].Get("maxVol")); stmt.Dispose(); }
private void RunAssertionUniqueInBatch(EPServiceProvider epService) { string stmtOne = "insert into MyStream select symbol, price from " + typeof(SupportMarketDataBean).FullName + "#time_batch(1 sec)"; epService.EPAdministrator.CreateEPL(stmtOne); SendTimer(epService, 0); string epl = "select symbol " + "from MyStream#time_batch(1 sec)#unique(symbol) " + "group by symbol"; EPStatement stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendEvent(epService, "IBM", 100); SendEvent(epService, "IBM", 101); SendEvent(epService, "IBM", 102); SendTimer(epService, 1000); Assert.IsFalse(listener.IsInvoked); SendTimer(epService, 2000); UniformPair <EventBean[]> received = listener.GetDataListsFlattened(); Assert.AreEqual("IBM", received.First[0].Get("symbol")); epService.EPAdministrator.DestroyAllStatements(); }
/// <summary> /// Called once the output condition has been met. /// </summary> protected void ContinueOutputProcessingView(Boolean doOutput, Boolean forceUpdate) { if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled)) { Log.Debug(".continueOutputProcessingView"); } EventBean[] newEvents = null; EventBean[] oldEvents = null; var it = GetEnumerator(); if (it.MoveNext()) { var snapshot = new List <EventBean>(); do { snapshot.Add(it.Current); } while (it.MoveNext()); newEvents = snapshot.ToArray(); oldEvents = null; } var newOldEvents = new UniformPair <EventBean[]>(newEvents, oldEvents); if (doOutput) { Output(forceUpdate, newOldEvents); } }
public void NewResult(UniformPair <EventBean[]> result) { if (result != null) { UpdateChildren(result.First, result.Second); } }
public override void Execute(UniformPair <EventBean[]> result) { object newData; object oldData; if (result == null) { newData = null; oldData = null; } else { newData = Convert(result.First); oldData = Convert(result.Second); } object[] parameters = new object[] { _statement, newData, oldData }; try { _fastMethod.Invoke(_subscriber, parameters); } catch (TargetInvocationException e) { ResultDeliveryStrategyImpl.Handle(_statement.Name, Log, e, parameters, _subscriber, _fastMethod); } }
public UniformPair <EventBean[]> Output() { UniformPair <EventBean[]> newOldEvents = null; if (_lastEventIStreamForOutputLast != null) { var istream = new EventBean[] { _lastEventIStreamForOutputLast }; newOldEvents = new UniformPair <EventBean[]>(istream, null); } if (_lastEventRStreamForOutputLast != null) { var rstream = new EventBean[] { _lastEventRStreamForOutputLast }; if (newOldEvents == null) { newOldEvents = new UniformPair <EventBean[]>(null, rstream); } else { newOldEvents.Second = rstream; } } _lastEventIStreamForOutputLast = null; _lastEventRStreamForOutputLast = null; return(newOldEvents); }
public void TestMaxTimeWindow() { SendTimer(0); var viewExpr = "select irstream Volume, max(Price) as maxVol" + " from " + typeof(SupportMarketDataBean).FullName + "#time(1 sec) " + "output every 1 seconds"; var stmt = _epService.EPAdministrator.CreateEPL(viewExpr); stmt.AddListener(_listener); SendEvent("SYM1", 1d); SendEvent("SYM1", 2d); _listener.Reset(); // moves all events out of the window, SendTimer(1000); // newdata is 2 eventa, old data is the same 2 events, therefore the sum is null UniformPair <EventBean[]> result = _listener.GetDataListsFlattened(); Assert.AreEqual(2, result.First.Length); Assert.AreEqual(1.0, result.First[0].Get("maxVol")); Assert.AreEqual(2.0, result.First[1].Get("maxVol")); Assert.AreEqual(2, result.Second.Length); Assert.AreEqual(null, result.Second[0].Get("maxVol")); Assert.AreEqual(null, result.Second[1].Get("maxVol")); }
protected virtual void PostProcess( bool force, UniformPair<EventBean[]> newOldEvents, UpdateDispatchView childView) { OutputStrategyUtil.Output(force, newOldEvents, childView); }
public void TestUniqueInBatch() { var stmtOne = "insert into MyStream select Symbol, price from " + typeof(SupportMarketDataBean).FullName + ".win:time_batch(1 sec)"; _epService.EPAdministrator.CreateEPL(stmtOne); SendTimer(0); var viewExpr = "select Symbol " + "from MyStream.win:time_batch(1 sec).std:unique(Symbol) " + "group by Symbol"; var selectTestView = _epService.EPAdministrator.CreateEPL(viewExpr); selectTestView.AddListener(_listener); SendEvent("IBM", 100); SendEvent("IBM", 101); SendEvent("IBM", 102); SendTimer(1000); Assert.IsFalse(_listener.IsInvoked); SendTimer(2000); UniformPair <EventBean[]> received = _listener.GetDataListsFlattened(); Assert.AreEqual("IBM", received.First[0].Get("Symbol")); }
public void TestJoinSortWindow() { SendTimer(0); var viewExpr = "select irstream max(Price) as maxVol" + " from " + typeof(SupportMarketDataBean).FullName + ".ext:sort(1,Volume desc) as s0, " + typeof(SupportBean).FullName + ".win:keepall() as s1 where s1.TheString=s0.Symbol " + "output every 1.0d seconds"; var stmt = epService.EPAdministrator.CreateEPL(viewExpr); stmt.AddListener(listener); epService.EPRuntime.SendEvent(new SupportBean("JOIN_KEY", -1)); SendEvent("JOIN_KEY", 1d); SendEvent("JOIN_KEY", 2d); listener.Reset(); // moves all events out of the window, SendTimer(1000); // newdata is 2 eventa, old data is the same 2 events, therefore the sum is null UniformPair <EventBean[]> result = listener.GetDataListsFlattened(); Assert.AreEqual(2, result.First.Length); Assert.AreEqual(1.0, result.First[0].Get("maxVol")); Assert.AreEqual(2.0, result.First[1].Get("maxVol")); Assert.AreEqual(2, result.Second.Length); Assert.AreEqual(null, result.Second[0].Get("maxVol")); Assert.AreEqual(1.0, result.Second[1].Get("maxVol")); // statement object model test var model = epService.EPAdministrator.CompileEPL(viewExpr); SerializableObjectCopier.Copy(model); Assert.AreEqual(viewExpr, model.ToEPL()); }
public virtual void Execute(UniformPair <EventBean[]> result) { Object[][] newData; Object[][] oldData; if (result == null) { newData = null; oldData = null; } else { newData = Convert(result.First); oldData = Convert(result.Second); } var paramList = new Object[] { newData, oldData }; try { _fastMethod.Invoke(_subscriber, paramList); } catch (TargetInvocationException e) { ResultDeliveryStrategyImpl.Handle(_statement.Name, Log, e, paramList, _subscriber, _fastMethod); } }
private UniformPair <EventBean[]> Output(bool isGenerateSynthetic, bool isJoin) { EventBean[] oldEvents = EventBeanUtility.ToArrayNullIfEmpty(eventsOld); EventBean[] newEvents = EventBeanUtility.ToArrayNullIfEmpty(eventsNew); if (newEvents == null) { newEvents = processor.GetSelectListEvents(true, isGenerateSynthetic, isJoin); } if (oldEvents == null && processor.Prototype.IsSelectRStream) { oldEvents = processor.GetSelectListEvents(false, isGenerateSynthetic, isJoin); } UniformPair <EventBean[]> result = null; if (oldEvents != null || newEvents != null) { result = new UniformPair <EventBean[]>(newEvents, oldEvents); } eventsOld.Clear(); eventsNew.Clear(); return(result); }
/// <summary> /// Called once the output condition has been met. /// Invokes the result set processor. /// Used for non-join event data. /// </summary> /// <param name="doOutput"> /// true if the batched events should actually be output as well as processed, false if they should /// just be processed /// </param> /// <param name="forceUpdate">true if output should be made even when no updating events have arrived</param> protected void ContinueOutputProcessingView( bool doOutput, bool forceUpdate) { EventBean[] newEvents = null; EventBean[] oldEvents = null; using (var enumerator = GetEnumerator()) { if (enumerator.MoveNext()) { var snapshot = new List<EventBean>(); do { EventBean @event = enumerator.Current; snapshot.Add(@event); } while (enumerator.MoveNext()); newEvents = snapshot.ToArray(); } } var newOldEvents = new UniformPair<EventBean[]>(newEvents, oldEvents); if (doOutput) { Output(forceUpdate, newOldEvents); } }
private bool HasRelevantResults(UniformPair <EventBean[]> newOldEvents) { if (newOldEvents == null) { return(false); } if (_parent.SelectClauseStreamSelectorEnum == SelectClauseStreamSelectorEnum.ISTREAM_ONLY) { if (newOldEvents.First == null) { return(false); // nothing to indicate } } else if (_parent.SelectClauseStreamSelectorEnum == SelectClauseStreamSelectorEnum.RSTREAM_ISTREAM_BOTH) { if (newOldEvents.First == null && newOldEvents.Second == null) { return(false); // nothing to indicate } } else { if (newOldEvents.Second == null) { return(false); // nothing to indicate } } return(true); }
protected override void PostProcess( bool force, UniformPair<EventBean[]> newOldEvents, UpdateDispatchView childView) { _postProcessor.Output(force, newOldEvents, childView); }
/// <summary> /// Called once the output condition has been met. /// Invokes the result set processor. /// Used for non-join event data. /// </summary> /// <param name="doOutput">- true if the batched events should actually be output as well as processed, false if they should just be processed</param> /// <param name="forceUpdate">- true if output should be made even when no updating events have arrived</param> protected void ContinueOutputProcessingView(bool doOutput, bool forceUpdate) { if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled)) { Log.Debug(".continueOutputProcessingView"); } EventBean[] newEvents = null; EventBean[] oldEvents = null; IEnumerator <EventBean> en = GetEnumerator(); var snapshot = new List <EventBean>(); while (en.MoveNext()) { EventBean @event = en.Current; snapshot.Add(@event); } newEvents = snapshot.ToArray(); oldEvents = null; var newOldEvents = new UniformPair <EventBean[]>(newEvents, oldEvents); if (doOutput) { Output(forceUpdate, newOldEvents); } }
public EventBean Transform(EventBean theEvent) { _newData[0] = theEvent; UniformPair <EventBean[]> pair = _resultSetProcessor.ProcessViewResult(_newData, null, true); return(pair.First[0]); }
public void TestJoinSortWindow() { SendTimer(0); var viewExpr = "select irstream Volume, max(Price) as maxVol" + " from " + typeof(SupportMarketDataBean).FullName + ".ext:sort(1, Volume desc) as s0," + typeof(SupportBean).FullName + ".win:keepall() as s1 " + "output every 1 seconds"; var stmt = _epService.EPAdministrator.CreateEPL(viewExpr); stmt.AddListener(_listener); _epService.EPRuntime.SendEvent(new SupportBean("JOIN_KEY", -1)); SendEvent("JOIN_KEY", 1d); SendEvent("JOIN_KEY", 2d); _listener.Reset(); // moves all events out of the window, SendTimer(1000); // newdata is 2 eventa, old data is the same 2 events, therefore the sum is null UniformPair <EventBean[]> result = _listener.GetDataListsFlattened(); Assert.AreEqual(2, result.First.Length); Assert.AreEqual(1.0, result.First[0].Get("maxVol")); Assert.AreEqual(2.0, result.First[1].Get("maxVol")); Assert.AreEqual(1, result.Second.Length); Assert.AreEqual(2.0, result.Second[0].Get("maxVol")); }
public void TestFlattenList() { // test many arrays EventBean[] testEvents = MakeEventArray(new[] { "a1", "a2", "b1", "b2", "b3", "c1", "c2" }); var eventVector = new LinkedList <UniformPair <EventBean[]> >(); eventVector.AddLast(new UniformPair <EventBean[]>(null, new[] { testEvents[0], testEvents[1] })); eventVector.AddLast(new UniformPair <EventBean[]>(new[] { testEvents[2] }, null)); eventVector.AddLast(new UniformPair <EventBean[]>(null, new[] { testEvents[3], testEvents[4], testEvents[5] })); eventVector.AddLast(new UniformPair <EventBean[]>(new[] { testEvents[6] }, null)); UniformPair <EventBean[]> events = EventBeanUtility.FlattenList(eventVector); EPAssertionUtil.AssertEqualsExactOrder(events.First, new[] { testEvents[2], testEvents[6] }); EPAssertionUtil.AssertEqualsExactOrder(events.Second, new[] { testEvents[0], testEvents[1], testEvents[3], testEvents[4], testEvents[5] }); // test just one array eventVector.Clear(); eventVector.AddLast(new UniformPair <EventBean[]>(new[] { testEvents[2] }, null)); events = EventBeanUtility.FlattenList(eventVector); EPAssertionUtil.AssertEqualsExactOrder(events.First, new[] { testEvents[2] }); EPAssertionUtil.AssertEqualsExactOrder(null, events.Second); // test empty vector eventVector.Clear(); events = EventBeanUtility.FlattenList(eventVector); Assert.IsNull(events); }
private static String RewriteScripts(IList <UniformPair <int?> > ranges, CommonTokenStream tokens) { if (ranges.IsEmpty()) { return(tokens.GetText()); } var writer = new StringWriter(); var rangeIndex = 0; UniformPair <int?> current = ranges[rangeIndex]; for (var i = 0; i < tokens.Size; i++) { var t = tokens.Get(i); if (t.Type == EsperEPL2GrammarLexer.Eof) { break; } if (i < current.First) { writer.Write(t.Text); } else if (i == current.First) { writer.Write(t.Text); writer.Write("'"); } else if (i == current.Second) { writer.Write("'"); writer.Write(t.Text); rangeIndex++; if (ranges.Count > rangeIndex) { current = ranges[rangeIndex]; } else { current = new UniformPair <int?>(-1, -1); } } else if (t.Type == EsperEPL2GrammarParser.SL_COMMENT || t.Type == EsperEPL2GrammarParser.ML_COMMENT) { WriteCommentEscapeSingleQuote(writer, t); } else { if (t.Type == EsperEPL2GrammarParser.QUOTED_STRING_LITERAL && i > current.First && i < current.Second) { writer.Write("\\'"); writer.Write(t.Text.Substring(1, t.Text.Length - 2)); writer.Write("\\'"); } else { writer.Write(t.Text); } } } return(writer.ToString()); }
public void Join(EventBean[][] newDataPerStream, EventBean[][] oldDataPerStream) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QJoinExexStrategy(); } UniformPair <ISet <MultiKey <EventBean> > > joinSet = _composer.Join(newDataPerStream, oldDataPerStream, _staticExprEvaluatorContext); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AJoinExecStrategy(joinSet); } _filter.Process(joinSet.First, joinSet.Second, _staticExprEvaluatorContext); if ((!joinSet.First.IsEmpty()) || (!joinSet.Second.IsEmpty())) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QJoinExecProcess(joinSet); } _indicator.Process(joinSet.First, joinSet.Second, _staticExprEvaluatorContext); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AJoinExecProcess(); } } }
/// <summary>Indicate an outbound result. </summary> /// <param name="events">to indicate</param> public void ProcessDispatch(UniformPair <EventBean[]> events) { // Plain all-events delivery if (!_forClauseDelivery) { DispatchInternal(events); return; } // Discrete delivery if ((_groupDeliveryExpressions == null) || (_groupDeliveryExpressions.Length == 0)) { var todeliver = new UniformPair <EventBean[]>(null, null); if (events != null) { if (events.First != null) { foreach (EventBean theEvent in events.First) { todeliver.First = new EventBean[] { theEvent }; DispatchInternal(todeliver); } todeliver.First = null; } if (events.Second != null) { foreach (EventBean theEvent in events.Second) { todeliver.Second = new EventBean[] { theEvent }; DispatchInternal(todeliver); } todeliver.Second = null; } } return; } // Grouped delivery IDictionary <Object, UniformPair <EventBean[]> > groups; try { groups = GetGroupedResults(events); } catch (Exception ex) { Log.Error("Unexpected exception evaluating grouped-delivery expressions: " + ex.Message + ", delivering ungrouped", ex); DispatchInternal(events); return; } // Deliver each group separately foreach (var group in groups) { DispatchInternal(group.Value); } }
/// <summary> /// Returns true if the after-condition is satisfied. /// </summary> /// <param name="newOldEvents">is the new and old events pair</param> /// <param name="statementContext">The statement context.</param> /// <returns>indicator for output condition</returns> public bool CheckAfterCondition(UniformPair <EventBean[]> newOldEvents, StatementContext statementContext) { return(IsAfterConditionSatisfied || CheckAfterCondition( newOldEvents == null ? 0 : (newOldEvents.First == null ? 0 : newOldEvents.First.Length), statementContext)); }
public void ProcessView( EventBean[] newData, EventBean[] oldData, bool isGenerateSynthetic) { UniformPair<EventBean[]> pair = processor.ProcessViewResult(newData, oldData, isGenerateSynthetic); Apply(pair); }
public void QStatementResultExecute( UniformPair<EventBean[]> events, string deploymentId, int statementId, string statementName, long threadId) { }
public override void Output( bool forceUpdate, UniformPair<EventBean[]> results) { if (child != null) { _postProcessor.Output(forceUpdate, results, child); } }
public void ProcessJoin( ISet<MultiKeyArrayOfKeys<EventBean>> newEvents, ISet<MultiKeyArrayOfKeys<EventBean>> oldEvents, bool isGenerateSynthetic) { UniformPair<EventBean[]> pair = processor.ProcessJoinResult(newEvents, oldEvents, isGenerateSynthetic); Apply(pair); }
private void Output(bool forceUpdate, UniformPair <EventBean[]> results) { // Child view can be null in replay from named window if (ChildView != null) { OutputStrategyUtil.Output(forceUpdate, results, ChildView); } }
public override void Output(bool forceUpdate, UniformPair <EventBean[]> results) { // Child view can be null in replay from named window if (ChildView != null) { _postProcessor.Output(forceUpdate, results, ChildView); } }