private UniformPair <EventBean[]> ProcessOutputLimitedViewDefault(IList <UniformPair <EventBean[]> > viewEventsList, bool generateSynthetic)
        {
            IList <EventBean> newEvents = new List <EventBean>();
            IList <EventBean> oldEvents = null;

            if (_prototype.IsSelectRStream)
            {
                oldEvents = new List <EventBean>();
            }
            IList <object> newEventsSortKey = null;
            IList <object> oldEventsSortKey = null;

            if (_orderByProcessor != null)
            {
                newEventsSortKey = new List <object>();
                if (_prototype.IsSelectRStream)
                {
                    oldEventsSortKey = new List <object>();
                }
            }

            foreach (var pair in viewEventsList)
            {
                var newData = pair.First;
                var oldData = pair.Second;

                var eventsPerStream = new EventBean[1];
                if (newData != null)
                {
                    // apply new data to aggregates
                    foreach (var aNewData in newData)
                    {
                        eventsPerStream[0] = aNewData;
                        _aggregationService.ApplyEnter(eventsPerStream, null, _exprEvaluatorContext);
                    }
                }
                if (oldData != null)
                {
                    // apply old data to aggregates
                    foreach (var anOldData in oldData)
                    {
                        eventsPerStream[0] = anOldData;
                        _aggregationService.ApplyLeave(eventsPerStream, null, _exprEvaluatorContext);
                    }
                }

                // generate old events using select expressions
                if (_prototype.IsSelectRStream)
                {
                    if (_prototype.OptionalHavingNode == null)
                    {
                        if (_orderByProcessor == null)
                        {
                            ResultSetProcessorUtil.PopulateSelectEventsNoHaving(_selectExprProcessor, oldData, false, generateSynthetic, oldEvents, _exprEvaluatorContext);
                        }
                        else
                        {
                            ResultSetProcessorUtil.PopulateSelectEventsNoHavingWithOrderBy(_selectExprProcessor, _orderByProcessor, oldData, false, generateSynthetic, oldEvents, oldEventsSortKey, _exprEvaluatorContext);
                        }
                    }
                    // generate old events using having then select
                    else
                    {
                        if (_orderByProcessor == null)
                        {
                            ResultSetProcessorUtil.PopulateSelectEventsHaving(_selectExprProcessor, oldData, _prototype.OptionalHavingNode, false, generateSynthetic, oldEvents, _exprEvaluatorContext);
                        }
                        else
                        {
                            ResultSetProcessorUtil.PopulateSelectEventsHavingWithOrderBy(_selectExprProcessor, _orderByProcessor, oldData, _prototype.OptionalHavingNode, false, generateSynthetic, oldEvents, oldEventsSortKey, _exprEvaluatorContext);
                        }
                    }
                }

                // generate new events using select expressions
                if (_prototype.OptionalHavingNode == null)
                {
                    if (_orderByProcessor == null)
                    {
                        ResultSetProcessorUtil.PopulateSelectEventsNoHaving(_selectExprProcessor, newData, true, generateSynthetic, newEvents, _exprEvaluatorContext);
                    }
                    else
                    {
                        ResultSetProcessorUtil.PopulateSelectEventsNoHavingWithOrderBy(_selectExprProcessor, _orderByProcessor, newData, true, generateSynthetic, newEvents, newEventsSortKey, _exprEvaluatorContext);
                    }
                }
                else
                {
                    if (_orderByProcessor == null)
                    {
                        ResultSetProcessorUtil.PopulateSelectEventsHaving(_selectExprProcessor, newData, _prototype.OptionalHavingNode, true, generateSynthetic, newEvents, _exprEvaluatorContext);
                    }
                    else
                    {
                        ResultSetProcessorUtil.PopulateSelectEventsHavingWithOrderBy(_selectExprProcessor, _orderByProcessor, newData, _prototype.OptionalHavingNode, true, generateSynthetic, newEvents, newEventsSortKey, _exprEvaluatorContext);
                    }
                }
            }

            var newEventsArr = (newEvents.IsEmpty()) ? null : newEvents.ToArray();

            EventBean[] oldEventsArr = null;
            if (_prototype.IsSelectRStream)
            {
                oldEventsArr = (oldEvents.IsEmpty()) ? null : oldEvents.ToArray();
            }
            if (_orderByProcessor != null)
            {
                var sortKeysNew = (newEventsSortKey.IsEmpty()) ? null : newEventsSortKey.ToArray();
                newEventsArr = _orderByProcessor.Sort(newEventsArr, sortKeysNew, _exprEvaluatorContext);

                if (_prototype.IsSelectRStream)
                {
                    var sortKeysOld = (oldEventsSortKey.IsEmpty()) ? null : oldEventsSortKey.ToArray();
                    oldEventsArr = _orderByProcessor.Sort(oldEventsArr, sortKeysOld, _exprEvaluatorContext);
                }
            }

            if ((newEventsArr == null) && (oldEventsArr == null))
            {
                return(null);
            }
            return(new UniformPair <EventBean[]>(newEventsArr, oldEventsArr));
        }
Пример #2
0
        public UniformPair <EventBean[]> ProcessOutputLimitedView(IList <UniformPair <EventBean[]> > viewEventsList, bool generateSynthetic, OutputLimitLimitType outputLimitLimitType)
        {
            if (outputLimitLimitType == OutputLimitLimitType.LAST)
            {
                EventBean   lastOldEvent    = null;
                EventBean   lastNewEvent    = null;
                EventBean[] eventsPerStream = new EventBean[1];

                foreach (UniformPair <EventBean[]> pair in viewEventsList)
                {
                    EventBean[] newData = pair.First;
                    EventBean[] oldData = pair.Second;

                    if (newData != null)
                    {
                        // apply new data to aggregates
                        foreach (EventBean aNewData in newData)
                        {
                            eventsPerStream[0] = aNewData;
                            _aggregationService.ApplyEnter(eventsPerStream, null, _exprEvaluatorContext);
                        }
                    }
                    if (oldData != null)
                    {
                        // apply old data to aggregates
                        foreach (EventBean anOldData in oldData)
                        {
                            eventsPerStream[0] = anOldData;
                            _aggregationService.ApplyLeave(eventsPerStream, null, _exprEvaluatorContext);
                        }
                    }

                    EventBean[] selectOldEvents;
                    if (_prototype.IsSelectRStream)
                    {
                        if (_prototype.OptionalHavingNode == null)
                        {
                            selectOldEvents = ResultSetProcessorUtil.GetSelectEventsNoHaving(_selectExprProcessor, oldData, false, generateSynthetic, _exprEvaluatorContext);
                        }
                        else
                        {
                            selectOldEvents = ResultSetProcessorUtil.GetSelectEventsHaving(_selectExprProcessor, oldData, _prototype.OptionalHavingNode, false, generateSynthetic, _exprEvaluatorContext);
                        }
                        if ((selectOldEvents != null) && (selectOldEvents.Length > 0))
                        {
                            lastOldEvent = selectOldEvents[selectOldEvents.Length - 1];
                        }
                    }

                    // generate new events using select expressions
                    EventBean[] selectNewEvents;
                    if (_prototype.OptionalHavingNode == null)
                    {
                        selectNewEvents = ResultSetProcessorUtil.GetSelectEventsNoHaving(_selectExprProcessor, newData, true, generateSynthetic, _exprEvaluatorContext);
                    }
                    else
                    {
                        selectNewEvents = ResultSetProcessorUtil.GetSelectEventsHaving(_selectExprProcessor, newData, _prototype.OptionalHavingNode, true, generateSynthetic, _exprEvaluatorContext);
                    }
                    if ((selectNewEvents != null) && (selectNewEvents.Length > 0))
                    {
                        lastNewEvent = selectNewEvents[selectNewEvents.Length - 1];
                    }
                }

                EventBean[] lastNew = (lastNewEvent != null) ? new EventBean[] { lastNewEvent } : null;
                EventBean[] lastOld = (lastOldEvent != null) ? new EventBean[] { lastOldEvent } : null;

                if ((lastNew == null) && (lastOld == null))
                {
                    return(null);
                }
                return(new UniformPair <EventBean[]>(lastNew, lastOld));
            }
            else
            {
                ICollection <EventBean> newEvents = new List <EventBean>();
                ICollection <EventBean> oldEvents = null;
                if (_prototype.IsSelectRStream)
                {
                    oldEvents = new LinkedList <EventBean>();
                }
                ICollection <Object> newEventsSortKey = null;
                ICollection <Object> oldEventsSortKey = null;
                if (_orderByProcessor != null)
                {
                    newEventsSortKey = new LinkedList <Object>();
                    if (_prototype.IsSelectRStream)
                    {
                        oldEventsSortKey = new LinkedList <Object>();
                    }
                }

                foreach (UniformPair <EventBean[]> pair in viewEventsList)
                {
                    EventBean[] newData = pair.First;
                    EventBean[] oldData = pair.Second;

                    EventBean[] eventsPerStream = new EventBean[1];
                    if (newData != null)
                    {
                        // apply new data to aggregates
                        foreach (EventBean aNewData in newData)
                        {
                            eventsPerStream[0] = aNewData;
                            _aggregationService.ApplyEnter(eventsPerStream, null, _exprEvaluatorContext);
                        }
                    }
                    if (oldData != null)
                    {
                        // apply old data to aggregates
                        foreach (EventBean anOldData in oldData)
                        {
                            eventsPerStream[0] = anOldData;
                            _aggregationService.ApplyLeave(eventsPerStream, null, _exprEvaluatorContext);
                        }
                    }

                    // generate old events using select expressions
                    if (_prototype.IsSelectRStream)
                    {
                        if (_prototype.OptionalHavingNode == null)
                        {
                            if (_orderByProcessor == null)
                            {
                                ResultSetProcessorUtil.PopulateSelectEventsNoHaving(_selectExprProcessor, oldData, false, generateSynthetic, oldEvents, _exprEvaluatorContext);
                            }
                            else
                            {
                                ResultSetProcessorUtil.PopulateSelectEventsNoHavingWithOrderBy(_selectExprProcessor, _orderByProcessor, oldData, false, generateSynthetic, oldEvents, oldEventsSortKey, _exprEvaluatorContext);
                            }
                        }
                        // generate old events using having then select
                        else
                        {
                            if (_orderByProcessor == null)
                            {
                                ResultSetProcessorUtil.PopulateSelectEventsHaving(_selectExprProcessor, oldData, _prototype.OptionalHavingNode, false, generateSynthetic, oldEvents, _exprEvaluatorContext);
                            }
                            else
                            {
                                ResultSetProcessorUtil.PopulateSelectEventsHavingWithOrderBy(_selectExprProcessor, _orderByProcessor, oldData, _prototype.OptionalHavingNode, false, generateSynthetic, oldEvents, oldEventsSortKey, _exprEvaluatorContext);
                            }
                        }
                    }

                    // generate new events using select expressions
                    if (_prototype.OptionalHavingNode == null)
                    {
                        if (_orderByProcessor == null)
                        {
                            ResultSetProcessorUtil.PopulateSelectEventsNoHaving(_selectExprProcessor, newData, true, generateSynthetic, newEvents, _exprEvaluatorContext);
                        }
                        else
                        {
                            ResultSetProcessorUtil.PopulateSelectEventsNoHavingWithOrderBy(_selectExprProcessor, _orderByProcessor, newData, true, generateSynthetic, newEvents, newEventsSortKey, _exprEvaluatorContext);
                        }
                    }
                    else
                    {
                        if (_orderByProcessor == null)
                        {
                            ResultSetProcessorUtil.PopulateSelectEventsHaving(_selectExprProcessor, newData, _prototype.OptionalHavingNode, true, generateSynthetic, newEvents, _exprEvaluatorContext);
                        }
                        else
                        {
                            ResultSetProcessorUtil.PopulateSelectEventsHavingWithOrderBy(_selectExprProcessor, _orderByProcessor, newData, _prototype.OptionalHavingNode, true, generateSynthetic, newEvents, newEventsSortKey, _exprEvaluatorContext);
                        }
                    }
                }

                EventBean[] newEventsArr = (newEvents.IsEmpty()) ? null : newEvents.ToArray();
                EventBean[] oldEventsArr = null;
                if (_prototype.IsSelectRStream)
                {
                    oldEventsArr = (oldEvents.IsEmpty()) ? null : oldEvents.ToArray();
                }
                if (_orderByProcessor != null)
                {
                    Object[] sortKeysNew = (newEventsSortKey.IsEmpty()) ? null : newEventsSortKey.ToArray();
                    newEventsArr = _orderByProcessor.Sort(newEventsArr, sortKeysNew, _exprEvaluatorContext);

                    if (_prototype.IsSelectRStream)
                    {
                        Object[] sortKeysOld = (oldEventsSortKey.IsEmpty()) ? null : oldEventsSortKey.ToArray();
                        oldEventsArr = _orderByProcessor.Sort(oldEventsArr, sortKeysOld, _exprEvaluatorContext);
                    }
                }

                if ((newEventsArr == null) && (oldEventsArr == null))
                {
                    return(null);
                }
                return(new UniformPair <EventBean[]>(newEventsArr, oldEventsArr));
            }
        }