private UniformPair <EventBean[]> ProcessOutputLimitedJoinDefault(IList <UniformPair <ISet <MultiKey <EventBean> > > > joinEventsSet, 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 joinEventsSet)
            {
                var newData = pair.First;
                var oldData = pair.Second;

                if (_prototype.IsUnidirectional)
                {
                    Clear();
                }

                if (newData != null)
                {
                    // apply new data to aggregates
                    foreach (var row in newData)
                    {
                        _aggregationService.ApplyEnter(row.Array, null, _exprEvaluatorContext);
                    }
                }
                if (oldData != null)
                {
                    // apply old data to aggregates
                    foreach (var row in oldData)
                    {
                        _aggregationService.ApplyLeave(row.Array, null, _exprEvaluatorContext);
                    }
                }

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

                // generate new events using select expressions
                if (_prototype.OptionalHavingNode == null)
                {
                    if (_orderByProcessor == null)
                    {
                        ResultSetProcessorUtil.PopulateSelectJoinEventsNoHaving(_selectExprProcessor, newData, true, generateSynthetic, newEvents, _exprEvaluatorContext);
                    }
                    else
                    {
                        ResultSetProcessorUtil.PopulateSelectJoinEventsNoHavingWithOrderBy(_selectExprProcessor, _orderByProcessor, newData, true, generateSynthetic, newEvents, newEventsSortKey, _exprEvaluatorContext);
                    }
                }
                else
                {
                    if (_orderByProcessor == null)
                    {
                        ResultSetProcessorUtil.PopulateSelectJoinEventsHaving(_selectExprProcessor, newData, _prototype.OptionalHavingNode, true, generateSynthetic, newEvents, _exprEvaluatorContext);
                    }
                    else
                    {
                        ResultSetProcessorUtil.PopulateSelectJoinEventsHavingWithOrderBy(_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));
        }
Beispiel #2
0
        public UniformPair <EventBean[]> ProcessOutputLimitedJoin(IList <UniformPair <ISet <MultiKey <EventBean> > > > joinEventsSet, bool generateSynthetic, OutputLimitLimitType outputLimitLimitType)
        {
            if (outputLimitLimitType == OutputLimitLimitType.LAST)
            {
                EventBean lastOldEvent = null;
                EventBean lastNewEvent = null;

                foreach (UniformPair <ISet <MultiKey <EventBean> > > pair in joinEventsSet)
                {
                    ICollection <MultiKey <EventBean> > newData = pair.First;
                    ICollection <MultiKey <EventBean> > oldData = pair.Second;

                    if (_prototype.IsUnidirectional)
                    {
                        Clear();
                    }

                    if (newData != null)
                    {
                        // apply new data to aggregates
                        foreach (MultiKey <EventBean> eventsPerStream in newData)
                        {
                            _aggregationService.ApplyEnter(eventsPerStream.Array, null, _exprEvaluatorContext);
                        }
                    }
                    if (oldData != null)
                    {
                        // apply old data to aggregates
                        foreach (MultiKey <EventBean> eventsPerStream in oldData)
                        {
                            _aggregationService.ApplyLeave(eventsPerStream.Array, null, _exprEvaluatorContext);
                        }
                    }

                    EventBean[] selectOldEvents;
                    if (_prototype.IsSelectRStream)
                    {
                        if (_prototype.OptionalHavingNode == null)
                        {
                            selectOldEvents = ResultSetProcessorUtil.GetSelectJoinEventsNoHaving(_selectExprProcessor, oldData, false, generateSynthetic, _exprEvaluatorContext);
                        }
                        else
                        {
                            selectOldEvents = ResultSetProcessorUtil.GetSelectJoinEventsHaving(_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.GetSelectJoinEventsNoHaving(_selectExprProcessor, newData, true, generateSynthetic, _exprEvaluatorContext);
                    }
                    else
                    {
                        selectNewEvents = ResultSetProcessorUtil.GetSelectJoinEventsHaving(_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
            {
                IList <EventBean> newEvents = new List <EventBean>();
                IList <EventBean> oldEvents = null;
                if (_prototype.IsSelectRStream)
                {
                    oldEvents = new List <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 <ISet <MultiKey <EventBean> > > pair in joinEventsSet)
                {
                    ICollection <MultiKey <EventBean> > newData = pair.First;
                    ICollection <MultiKey <EventBean> > oldData = pair.Second;

                    if (_prototype.IsUnidirectional)
                    {
                        Clear();
                    }

                    if (newData != null)
                    {
                        // apply new data to aggregates
                        foreach (MultiKey <EventBean> row in newData)
                        {
                            _aggregationService.ApplyEnter(row.Array, null, _exprEvaluatorContext);
                        }
                    }
                    if (oldData != null)
                    {
                        // apply old data to aggregates
                        foreach (MultiKey <EventBean> row in oldData)
                        {
                            _aggregationService.ApplyLeave(row.Array, null, _exprEvaluatorContext);
                        }
                    }

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

                    // generate new events using select expressions
                    if (_prototype.OptionalHavingNode == null)
                    {
                        if (_orderByProcessor == null)
                        {
                            ResultSetProcessorUtil.PopulateSelectJoinEventsNoHaving(_selectExprProcessor, newData, true, generateSynthetic, newEvents, _exprEvaluatorContext);
                        }
                        else
                        {
                            ResultSetProcessorUtil.PopulateSelectJoinEventsNoHavingWithOrderBy(_selectExprProcessor, _orderByProcessor, newData, true, generateSynthetic, newEvents, newEventsSortKey, _exprEvaluatorContext);
                        }
                    }
                    else
                    {
                        if (_orderByProcessor == null)
                        {
                            ResultSetProcessorUtil.PopulateSelectJoinEventsHaving(_selectExprProcessor, newData, _prototype.OptionalHavingNode, true, generateSynthetic, newEvents, _exprEvaluatorContext);
                        }
                        else
                        {
                            ResultSetProcessorUtil.PopulateSelectJoinEventsHavingWithOrderBy(_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));
            }
        }