Exemplo n.º 1
0
        private static IEnumerator <EventBean> DistinctEnumeration(IEnumerator <EventBean> source, EventType eventType)
        {
            EventBeanReader eventBeanReader = null;

            if (eventType is EventTypeSPI)
            {
                eventBeanReader = ((EventTypeSPI)eventType).GetReader();
            }
            if (eventBeanReader == null)
            {
                eventBeanReader = new EventBeanReaderDefaultImpl(eventType);
            }

            if (source != null)
            {
                var events = new LinkedList <EventBean>();
                while (source.MoveNext())
                {
                    events.AddLast(source.Current);
                }

                if (events.Count <= 1)
                {
                    return(events.GetEnumerator());
                }

                IList <EventBean> result = EventBeanUtility.GetDistinctByProp(events, eventBeanReader);
                return(result.GetEnumerator());
            }

            return(EnumerationHelper <EventBean> .CreateEmptyEnumerator());
        }
Exemplo n.º 2
0
        public static EventBean[] HandleDistintAndInsert(
            EventBean[] newData,
            InfraOnSelectViewFactory parent,
            AgentInstanceContext agentInstanceContext,
            TableInstance tableInstanceInsertInto,
            bool audit)
        {
            if (parent.IsDistinct) {
                newData = EventBeanUtility.GetDistinctByProp(newData, parent.DistinctKeyGetter);
            }

            if (tableInstanceInsertInto != null) {
                if (newData != null) {
                    foreach (EventBean aNewData in newData) {
                        tableInstanceInsertInto.AddEventUnadorned(aNewData);
                    }
                }
            }
            else if (parent.IsInsertInto) {
                if (newData != null) {
                    foreach (EventBean aNewData in newData) {
                        if (audit) {
                            agentInstanceContext.AuditProvider.Insert(aNewData, agentInstanceContext);
                        }

                        agentInstanceContext.InternalEventRouter.Route(
                            aNewData,
                            agentInstanceContext,
                            parent.IsAddToFront);
                    }
                }
            }

            return newData;
        }
        /// <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)
        {
            _agentInstanceContext.InstrumentationProvider.QOutputRateConditionOutputNow();

            var statementResultService = _agentInstanceContext.StatementResultService;
            var isGenerateSynthetic = statementResultService.IsMakeSynthetic;
            var isGenerateNatural = statementResultService.IsMakeNatural;

            // Process the events and get the result
            var newOldEvents = _resultSetProcessor.ProcessOutputLimitedView(
                OptionalDeltaSet.ViewEventsSet,
                isGenerateSynthetic);

            if (_parent.IsDistinct && newOldEvents != null) {
                newOldEvents.First = EventBeanUtility.GetDistinctByProp(newOldEvents.First, _parent.DistinctKeyGetter);
                newOldEvents.Second = EventBeanUtility.GetDistinctByProp(newOldEvents.Second, _parent.DistinctKeyGetter);
            }

            if (!isGenerateSynthetic && !isGenerateNatural) {
                ResetEventBatches();
                _agentInstanceContext.InstrumentationProvider.AOutputRateConditionOutputNow(false);
                return;
            }

            if (doOutput) {
                Output(forceUpdate, newOldEvents);
            }

            ResetEventBatches();

            _agentInstanceContext.InstrumentationProvider.AOutputRateConditionOutputNow(true);
        }
Exemplo n.º 4
0
        public static IEnumerator<EventBean> For(
            IEnumerator<EventBean> sourceIterator,
            EventPropertyValueGetter distinctKeyGetter)
        {
            if (sourceIterator != null && sourceIterator.MoveNext()) {
                // there is at least one event...
                var first = sourceIterator.Current;
                // but is there only one event?
                if (!sourceIterator.MoveNext()) {
                    return EnumerationHelper.Singleton(first);
                }

                // build distinct set because there are multiple events
                var events = new ArrayDeque<EventBean>();
                events.Add(first);
                events.Add(sourceIterator.Current);
                while (sourceIterator.MoveNext()) {
                    events.Add(sourceIterator.Current);
                }

                // Determine the reader that we need to use for this use case
                var unique = EventBeanUtility.GetDistinctByProp(events, distinctKeyGetter);
                return unique.GetEnumerator();
            }

            return EnumerationHelper.Empty<EventBean>();
        }
Exemplo n.º 5
0
        public EPPreparedQueryResult Execute(
            FAFQueryMethodSelect select,
            ContextPartitionSelector[] contextPartitionSelectors,
            FAFQueryMethodAssignerSetter assignerSetter,
            ContextManagementService contextManagementService)
        {
            var processor = select.Processors[0];

            var singleSelector = contextPartitionSelectors != null && contextPartitionSelectors.Length > 0
                ? contextPartitionSelectors[0]
                : null;
            var agentInstanceIds = AgentInstanceIds(processor, singleSelector, contextManagementService);

            IList<ContextPartitionResult> contextPartitionResults = new List<ContextPartitionResult>();
            foreach (var agentInstanceId in agentInstanceIds) {
                var processorInstance = processor.GetProcessorInstanceContextById(agentInstanceId);
                if (processorInstance != null) {
                    var coll = processorInstance.SnapshotBestEffort(select.QueryGraph, select.Annotations);
                    contextPartitionResults.Add(
                        new ContextPartitionResult(coll, processorInstance.AgentInstanceContext));
                }
            }

            // process context partitions
            var events = new ArrayDeque<EventBean[]>();
            ResultSetProcessor resultSetProcessor = null;
            foreach (var contextPartitionResult in contextPartitionResults) {
                if (resultSetProcessor == null) {
                    resultSetProcessor = ProcessorWithAssign(
                        select.ResultSetProcessorFactoryProvider,
                        contextPartitionResult.Context,
                        assignerSetter,
                        select.TableAccesses);
                }

                var snapshot = contextPartitionResult.Events;
                if (select.WhereClause != null) {
                    snapshot = Filtered(
                        snapshot,
                        select.WhereClause,
                        contextPartitionResult.Context);
                }

                var rows = snapshot.ToArray();
                resultSetProcessor.SetAgentInstanceContext(contextPartitionResult.Context);
                var results = resultSetProcessor.ProcessViewResult(rows, null, true);
                if (results != null && results.First != null && results.First.Length > 0) {
                    events.Add(results.First);
                }
            }

            var distinct = EventBeanUtility.GetDistinctByProp(
                EventBeanUtility.Flatten(events),
                select.EventBeanReaderDistinct);
            return new EPPreparedQueryResult(select.EventType, distinct);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Called once the output condition has been met.
        /// Invokes the result set processor.
        /// Used for 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 ContinueOutputProcessingJoin(bool doOutput, bool forceUpdate)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QOutputRateConditionOutputNow();
            }

            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".continueOutputProcessingJoin");
            }

            bool isGenerateSynthetic = _parent.StatementResultService.IsMakeSynthetic;
            bool isGenerateNatural   = _parent.StatementResultService.IsMakeNatural;

            // Process the events and get the result
            UniformPair <EventBean[]> newOldEvents = ResultSetProcessor.ProcessOutputLimitedJoin(
                _deltaSet.JoinEventsSet, isGenerateSynthetic, _parent.OutputLimitLimitType);

            if (_parent.IsDistinct && newOldEvents != null)
            {
                newOldEvents.First  = EventBeanUtility.GetDistinctByProp(newOldEvents.First, _parent.EventBeanReader);
                newOldEvents.Second = EventBeanUtility.GetDistinctByProp(newOldEvents.Second, _parent.EventBeanReader);
            }

            if ((!isGenerateSynthetic) && (!isGenerateNatural))
            {
                if (AuditPath.IsAuditEnabled)
                {
                    OutputStrategyUtil.IndicateEarlyReturn(_parent.StatementContext, newOldEvents);
                }
                ResetEventBatches();
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().AOutputRateConditionOutputNow(false);
                }
                return;
            }

            if (doOutput)
            {
                Output(forceUpdate, newOldEvents);
            }
            ResetEventBatches();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AOutputRateConditionOutputNow(true);
            }
        }
        private void ContinueOutputProcessingViewAndJoin(
            bool doOutput,
            bool forceUpdate,
            UniformPair<EventBean[]> newOldEvents)
        {
            if (_parent.IsDistinct && newOldEvents != null) {
                newOldEvents.First = EventBeanUtility.GetDistinctByProp(newOldEvents.First, _parent.DistinctKeyGetter);
                newOldEvents.Second = EventBeanUtility.GetDistinctByProp(newOldEvents.Second, _parent.DistinctKeyGetter);
            }

            if (doOutput) {
                Output(forceUpdate, newOldEvents);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// The update method is called if the view does not participate in a join.
        /// </summary>
        /// <param name="newData">- new events</param>
        /// <param name="oldData">- old events</param>
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".update Received update, " +
                          "  newData.Length==" + ((newData == null) ? 0 : newData.Length) +
                          "  oldData.Length==" + ((oldData == null) ? 0 : oldData.Length));
            }

            bool isGenerateSynthetic = _parent.StatementResultService.IsMakeSynthetic;
            bool isGenerateNatural   = _parent.StatementResultService.IsMakeNatural;

            UniformPair <EventBean[]> newOldEvents = ResultSetProcessor.ProcessViewResult(newData, oldData, isGenerateSynthetic);

            if (!base.CheckAfterCondition(newOldEvents, _parent.StatementContext))
            {
                return;
            }

            if (_parent.IsDistinct && newOldEvents != null)
            {
                newOldEvents.First  = EventBeanUtility.GetDistinctByProp(newOldEvents.First, _parent.EventBeanReader);
                newOldEvents.Second = EventBeanUtility.GetDistinctByProp(newOldEvents.Second, _parent.EventBeanReader);
            }

            if ((!isGenerateSynthetic) && (!isGenerateNatural))
            {
                if (AuditPath.IsAuditEnabled)
                {
                    OutputStrategyUtil.IndicateEarlyReturn(_parent.StatementContext, newOldEvents);
                }
                return;
            }

            bool forceOutput = false;

            if ((newData == null) && (oldData == null) &&
                ((newOldEvents == null) || (newOldEvents.First == null && newOldEvents.Second == null)))
            {
                forceOutput = true;
            }

            // Child view can be null in replay from named window
            if (ChildView != null)
            {
                PostProcess(forceOutput, newOldEvents, ChildView);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// This process (update) method is for participation in a join.
        /// </summary>
        /// <param name="newEvents">- new events</param>
        /// <param name="oldEvents">- old events</param>
        /// <param name="exprEvaluatorContext">The expr evaluator context.</param>
        public override void Process(
            ISet <MultiKey <EventBean> > newEvents,
            ISet <MultiKey <EventBean> > oldEvents,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".process Received update, " +
                          "  newData.Length==" + ((newEvents == null) ? 0 : newEvents.Count) +
                          "  oldData.Length==" + ((oldEvents == null) ? 0 : oldEvents.Count));
            }

            bool isGenerateSynthetic = _parent.StatementResultService.IsMakeSynthetic;
            bool isGenerateNatural   = _parent.StatementResultService.IsMakeNatural;

            UniformPair <EventBean[]> newOldEvents = ResultSetProcessor.ProcessJoinResult(newEvents, oldEvents, isGenerateSynthetic);

            if (!CheckAfterCondition(newOldEvents, _parent.StatementContext))
            {
                return;
            }

            if (_parent.IsDistinct && newOldEvents != null)
            {
                newOldEvents.First  = EventBeanUtility.GetDistinctByProp(newOldEvents.First, _parent.EventBeanReader);
                newOldEvents.Second = EventBeanUtility.GetDistinctByProp(newOldEvents.Second, _parent.EventBeanReader);
            }

            if ((!isGenerateSynthetic) && (!isGenerateNatural))
            {
                if (AuditPath.IsAuditEnabled)
                {
                    OutputStrategyUtil.IndicateEarlyReturn(_parent.StatementContext, newOldEvents);
                }
                return;
            }

            if (newOldEvents == null)
            {
                return;
            }

            // Child view can be null in replay from named window
            if (ChildView != null)
            {
                PostProcess(false, newOldEvents, ChildView);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        ///     This process (update) method is for participation in a join.
        /// </summary>
        /// <param name="newEvents">new events</param>
        /// <param name="oldEvents">old events</param>
        /// <param name="exprEvaluatorContext">the evaluator context</param>
        public override void Process(
            ISet<MultiKeyArrayOfKeys<EventBean>> newEvents,
            ISet<MultiKeyArrayOfKeys<EventBean>> oldEvents,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            if (ExecutionPathDebugLog.IsDebugEnabled && log.IsDebugEnabled) {
                log.Debug(
                    ".process Received update, " +
                    "  newData.length==" +
                    (newEvents == null ? 0 : newEvents.Count) +
                    "  oldData.length==" +
                    (oldEvents == null ? 0 : oldEvents.Count));
            }

            var statementResultService = _agentInstanceContext.StatementResultService;
            var isGenerateSynthetic = statementResultService.IsMakeSynthetic;
            var isGenerateNatural = statementResultService.IsMakeNatural;

            var newOldEvents = _resultSetProcessor.ProcessJoinResult(newEvents, oldEvents, isGenerateSynthetic);

            if (!CheckAfterCondition(newOldEvents, _agentInstanceContext.StatementContext)) {
                return;
            }

            if (_parent.IsDistinct && newOldEvents != null) {
                newOldEvents.First = EventBeanUtility.GetDistinctByProp(newOldEvents.First, _parent.DistinctKeyGetter);
                newOldEvents.Second = EventBeanUtility.GetDistinctByProp(newOldEvents.Second, _parent.DistinctKeyGetter);
            }

            if (!isGenerateSynthetic && !isGenerateNatural) {
                if (AuditPath.isAuditEnabled) {
                    OutputStrategyUtil.IndicateEarlyReturn(_agentInstanceContext.StatementContext, newOldEvents);
                }

                return;
            }

            if (newOldEvents == null) {
                return;
            }

            // Child view can be null in replay from named window
            if (child != null) {
                PostProcess(false, newOldEvents, child);
            }
        }
        private void ContinueOutputProcessingViewAndJoin(bool doOutput, bool forceUpdate, UniformPair <EventBean[]> newOldEvents)
        {
            if (_parent.IsDistinct && newOldEvents != null)
            {
                newOldEvents.First  = EventBeanUtility.GetDistinctByProp(newOldEvents.First, _parent.EventBeanReader);
                newOldEvents.Second = EventBeanUtility.GetDistinctByProp(newOldEvents.Second, _parent.EventBeanReader);
            }

            if (doOutput)
            {
                Output(forceUpdate, newOldEvents);
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AOutputRateConditionOutputNow(true);
            }
        }
Exemplo n.º 12
0
        protected internal static EPPreparedQueryResult ProcessedNonJoin(
            ResultSetProcessor resultSetProcessor,
            ICollection<EventBean> events,
            EventBeanReader distinctHandler)
        {
            var rows = events.ToArray();
            var results = resultSetProcessor.ProcessViewResult(rows, null, true);

            EventBean[] distinct;
            if (distinctHandler == null) {
                distinct = results.First;
            }
            else {
                distinct = EventBeanUtility.GetDistinctByProp(results.First, distinctHandler);
            }

            return new EPPreparedQueryResult(resultSetProcessor.ResultEventType, distinct);
        }
Exemplo n.º 13
0
        /// <summary>
        ///     The update method is called if the view does not participate in a join.
        /// </summary>
        /// <param name="newData">new events</param>
        /// <param name="oldData">old events</param>
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            var statementResultService = _agentInstanceContext.StatementResultService;
            var isGenerateSynthetic = statementResultService.IsMakeSynthetic;
            var isGenerateNatural = statementResultService.IsMakeNatural;

            var newOldEvents = _resultSetProcessor.ProcessViewResult(newData, oldData, isGenerateSynthetic);

            if (!CheckAfterCondition(newOldEvents, _agentInstanceContext.StatementContext)) {
                return;
            }

            if (_parent.IsDistinct && newOldEvents != null) {
                newOldEvents.First = EventBeanUtility.GetDistinctByProp(newOldEvents.First, _parent.DistinctKeyGetter);
                newOldEvents.Second = EventBeanUtility.GetDistinctByProp(newOldEvents.Second, _parent.DistinctKeyGetter);
            }

            if (!isGenerateSynthetic && !isGenerateNatural) {
                if (AuditPath.isAuditEnabled) {
                    OutputStrategyUtil.IndicateEarlyReturn(_agentInstanceContext.StatementContext, newOldEvents);
                }

                return;
            }

            var forceOutput = false;
            if (newData == null &&
                oldData == null &&
                (newOldEvents == null || newOldEvents.First == null && newOldEvents.Second == null)) {
                forceOutput = true;
            }

            // Child view can be null in replay from named window
            if (child != null) {
                PostProcess(forceOutput, newOldEvents, child);
            }
        }
Exemplo n.º 14
0
        public override void HandleMatching(EventBean[] triggerEvents, EventBean[] matchingEvents)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QInfraOnAction(OnTriggerType.ON_SELECT, triggerEvents, matchingEvents);
            }

            EventBean[] newData;

            // clear state from prior results
            _resultSetProcessor.Clear();

            // build join result
            // use linked hash set to retain order of join results for last/first/window to work most intuitively
            var newEvents = BuildJoinResult(triggerEvents, matchingEvents);

            // process matches
            var pair = _resultSetProcessor.ProcessJoinResult(newEvents, _oldEvents, false);

            newData = (pair != null ? pair.First : null);

            if (_parent.IsDistinct)
            {
                newData = EventBeanUtility.GetDistinctByProp(newData, _parent.EventBeanReader);
            }

            if (_tableStateInstanceInsertInto != null)
            {
                if (newData != null)
                {
                    foreach (var aNewData in newData)
                    {
                        if (_audit)
                        {
                            AuditPath.AuditInsertInto(ExprEvaluatorContext.EngineURI, ExprEvaluatorContext.StatementName, aNewData);
                        }
                        _tableStateInstanceInsertInto.AddEventUnadorned(aNewData);
                    }
                }
            }
            else if (_parent.InternalEventRouter != null)
            {
                if (newData != null)
                {
                    foreach (var aNewData in newData)
                    {
                        if (_audit)
                        {
                            AuditPath.AuditInsertInto(ExprEvaluatorContext.EngineURI, ExprEvaluatorContext.StatementName, aNewData);
                        }
                        _parent.InternalEventRouter.Route(aNewData, _parent.StatementHandle, _parent.InternalEventRouteDest, ExprEvaluatorContext, _parent.IsAddToFront);
                    }
                }
            }

            // The on-select listeners receive the events selected
            if ((newData != null) && (newData.Length > 0))
            {
                // And post only if we have listeners/subscribers that need the data
                if (_parent.StatementResultService.IsMakeNatural || _parent.StatementResultService.IsMakeSynthetic)
                {
                    UpdateChildren(newData, null);
                }
            }
            _lastResult = newData;

            // clear state from prior results
            _resultSetProcessor.Clear();

            // Events to delete are indicated via old data
            if (_isDelete)
            {
                RootView.Update(null, matchingEvents);
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AInfraOnAction();
            }
        }
Exemplo n.º 15
0
        /// <summary>The Update method is called if the view does not participate in a join. </summary>
        /// <param name="newData">new events</param>
        /// <param name="oldData">old events</param>
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".Update Received Update, " +
                          "  newData.Length==" + ((newData == null) ? 0 : newData.Length) +
                          "  oldData.Length==" + ((oldData == null) ? 0 : oldData.Length));
            }

            if (!CheckAfterCondition(newData, _parent.StatementContext))
            {
                return;
            }

            if (!_witnessedFirst)
            {
                var isGenerateSynthetic = _parent.StatementResultService.IsMakeSynthetic;

                // Process the events and get the result
                _viewEventsList.Add(new UniformPair <EventBean[]>(newData, oldData));
                UniformPair <EventBean[]> newOldEvents = ResultSetProcessor.ProcessOutputLimitedView(_viewEventsList, isGenerateSynthetic, OutputLimitLimitType.FIRST);
                _viewEventsList.Clear();

                if (!HasRelevantResults(newOldEvents))
                {
                    return;
                }

                _witnessedFirst = true;

                if (_parent.IsDistinct)
                {
                    newOldEvents.First  = EventBeanUtility.GetDistinctByProp(newOldEvents.First, _parent.EventBeanReader);
                    newOldEvents.Second = EventBeanUtility.GetDistinctByProp(newOldEvents.Second, _parent.EventBeanReader);
                }

                var isGenerateNatural = _parent.StatementResultService.IsMakeNatural;
                if ((!isGenerateSynthetic) && (!isGenerateNatural))
                {
                    if (AuditPath.IsAuditEnabled)
                    {
                        OutputStrategyUtil.IndicateEarlyReturn(_parent.StatementContext, newOldEvents);
                    }
                    return;
                }

                Output(true, newOldEvents);
            }
            else
            {
                _viewEventsList.Add(new UniformPair <EventBean[]>(newData, oldData));
                ResultSetProcessor.ProcessOutputLimitedView(_viewEventsList, false, OutputLimitLimitType.FIRST);
                _viewEventsList.Clear();
            }

            int newDataLength = 0;
            int oldDataLength = 0;

            if (newData != null)
            {
                newDataLength = newData.Length;
            }
            if (oldData != null)
            {
                oldDataLength = oldData.Length;
            }

            _outputCondition.UpdateOutputCondition(newDataLength, oldDataLength);
        }
        public EPPreparedQueryResult Execute(
            FAFQueryMethodSelect select,
            ContextPartitionSelector[] contextPartitionSelectors,
            FAFQueryMethodAssignerSetter assignerSetter,
            ContextManagementService contextManagementService)
        {
            int numStreams = select.Processors.Length;
            ICollection<EventBean>[] snapshots = new ICollection<EventBean>[numStreams];

            AgentInstanceContext agentInstanceContext = null;
            Viewable[] viewablePerStream = new Viewable[numStreams];

            for (int i = 0; i < numStreams; i++) {
                FireAndForgetProcessor processor = select.Processors[i];
                FireAndForgetInstance processorInstance = processor.ProcessorInstanceNoContext;
                snapshots[i] = Snapshot(
                    select.ConsumerFilters[i],
                    processorInstance,
                    select.QueryGraph,
                    select.Annotations);
                agentInstanceContext = processorInstance.AgentInstanceContext;
                viewablePerStream[i] = processorInstance.TailViewInstance;
            }

            // get RSP
            ResultSetProcessor resultSetProcessor = ProcessorWithAssign(
                select.ResultSetProcessorFactoryProvider,
                agentInstanceContext,
                assignerSetter,
                select.TableAccesses,
                select.Subselects);

            // determine join
            JoinSetComposerDesc joinSetComposerDesc = select.JoinSetComposerPrototype.Create(
                viewablePerStream,
                true,
                agentInstanceContext,
                false);
            JoinSetComposer joinComposer = joinSetComposerDesc.JoinSetComposer;

            EventBean[][] oldDataPerStream = new EventBean[numStreams][];
            EventBean[][] newDataPerStream = new EventBean[numStreams][];
            for (int i = 0; i < numStreams; i++) {
                newDataPerStream[i] = snapshots[i].ToArray();
            }

            UniformPair<ISet<MultiKeyArrayOfKeys<EventBean>>> result = joinComposer.Join(
                newDataPerStream,
                oldDataPerStream,
                agentInstanceContext);
            if (joinSetComposerDesc.PostJoinFilterEvaluator != null) {
                JoinSetComposerUtil.Filter(
                    joinSetComposerDesc.PostJoinFilterEvaluator,
                    result.First,
                    true,
                    agentInstanceContext);
            }

            UniformPair<EventBean[]> results = resultSetProcessor.ProcessJoinResult(result.First, null, true);

            EventBean[] distinct = EventBeanUtility.GetDistinctByProp(results.First, select.DistinctKeyGetter);

            return new EPPreparedQueryResult(resultSetProcessor.ResultEventType, distinct);
        }
        private EPPreparedQueryResult Process(ICollection <EventBean>[] snapshots)
        {
            var numStreams = _processors.Length;

            UniformPair <EventBean[]> results;

            if (numStreams == 1)
            {
                if (_statementSpec.FilterRootNode != null)
                {
                    snapshots[0] = GetFiltered(snapshots[0], _statementSpec.FilterRootNode.AsSingleton());
                }
                EventBean[] rows = snapshots[0].ToArray();
                results = _resultSetProcessor.ProcessViewResult(rows, null, true);
            }
            else
            {
                var viewablePerStream = new Viewable[numStreams];
                for (var i = 0; i < numStreams; i++)
                {
                    var instance = _processors[i].GetProcessorInstance(_agentInstanceContext);
                    if (instance == null)
                    {
                        throw new UnsupportedOperationException("Joins against named windows that are under context are not supported");
                    }
                    viewablePerStream[i] = instance.TailViewInstance;
                }

                var           joinSetComposerDesc = _joinSetComposerPrototype.Create(viewablePerStream, true, _agentInstanceContext);
                var           joinComposer        = joinSetComposerDesc.JoinSetComposer;
                JoinSetFilter joinFilter;
                if (joinSetComposerDesc.PostJoinFilterEvaluator != null)
                {
                    joinFilter = new JoinSetFilter(joinSetComposerDesc.PostJoinFilterEvaluator);
                }
                else
                {
                    joinFilter = null;
                }

                var oldDataPerStream = new EventBean[numStreams][];
                var newDataPerStream = new EventBean[numStreams][];
                for (var i = 0; i < numStreams; i++)
                {
                    newDataPerStream[i] = snapshots[i].ToArray();
                }
                var result = joinComposer.Join(newDataPerStream, oldDataPerStream, _agentInstanceContext);
                if (joinFilter != null)
                {
                    joinFilter.Process(result.First, null, _agentInstanceContext);
                }
                results = _resultSetProcessor.ProcessJoinResult(result.First, null, true);
            }

            if (_statementSpec.SelectClauseSpec.IsDistinct)
            {
                results.First = EventBeanUtility.GetDistinctByProp(results.First, _eventBeanReader);
            }

            return(new EPPreparedQueryResult(_resultSetProcessor.ResultEventType, results.First));
        }
Exemplo n.º 18
0
        /// <summary>
        /// This process (Update) method is for participation in a join.
        /// </summary>
        /// <param name="newEvents">new events</param>
        /// <param name="oldEvents">old events</param>
        /// <param name="exprEvaluatorContext">expression evaluation context</param>
        public override void Process(ISet <MultiKey <EventBean> > newEvents, ISet <MultiKey <EventBean> > oldEvents, ExprEvaluatorContext exprEvaluatorContext)
        {
            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".process Received Update, " +
                          "  newData.Length==" + ((newEvents == null) ? 0 : newEvents.Count) +
                          "  oldData.Length==" + ((oldEvents == null) ? 0 : oldEvents.Count));
            }

            if (!CheckAfterCondition(newEvents, _parent.StatementContext))
            {
                return;
            }

            // add the incoming events to the event batches
            if (!_witnessedFirst)
            {
                AddToChangeSet(_joinEventsSet, newEvents, oldEvents);
                var isGenerateSynthetic = _parent.StatementResultService.IsMakeSynthetic;

                var newOldEvents = ResultSetProcessor.ProcessOutputLimitedJoin(_joinEventsSet, isGenerateSynthetic, OutputLimitLimitType.FIRST);
                _joinEventsSet.Clear();

                if (!HasRelevantResults(newOldEvents))
                {
                    return;
                }

                _witnessedFirst = true;

                if (_parent.IsDistinct)
                {
                    newOldEvents.First  = EventBeanUtility.GetDistinctByProp(newOldEvents.First, _parent.EventBeanReader);
                    newOldEvents.Second = EventBeanUtility.GetDistinctByProp(newOldEvents.Second, _parent.EventBeanReader);
                }

                bool isGenerateNatural = _parent.StatementResultService.IsMakeNatural;
                if ((!isGenerateSynthetic) && (!isGenerateNatural))
                {
                    if (AuditPath.IsAuditEnabled)
                    {
                        OutputStrategyUtil.IndicateEarlyReturn(_parent.StatementContext, newOldEvents);
                    }
                    return;
                }

                Output(true, newOldEvents);
            }
            else
            {
                AddToChangeSet(_joinEventsSet, newEvents, oldEvents);

                // Process the events and get the result
                ResultSetProcessor.ProcessOutputLimitedJoin(_joinEventsSet, false, OutputLimitLimitType.FIRST);
                _joinEventsSet.Clear();
            }

            int newEventsSize = 0;

            if (newEvents != null)
            {
                newEventsSize = newEvents.Count;
            }

            int oldEventsSize = 0;

            if (oldEvents != null)
            {
                oldEventsSize = oldEvents.Count;
            }

            _outputCondition.UpdateOutputCondition(newEventsSize, oldEventsSize);
        }
        /// <summary>
        ///     This process (update) method is for participation in a join.
        /// </summary>
        /// <param name="newEvents">new events</param>
        /// <param name="oldEvents">old events</param>
        /// <param name="exprEvaluatorContext">the evaluator context</param>
        public override void Process(
            ISet<MultiKeyArrayOfKeys<EventBean>> newEvents,
            ISet<MultiKeyArrayOfKeys<EventBean>> oldEvents,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            if (ExecutionPathDebugLog.IsDebugEnabled && Log.IsDebugEnabled) {
                Log.Debug(
                    ".process Received update, " +
                    "  newData.length==" +
                    (newEvents == null ? 0 : newEvents.Count) +
                    "  oldData.length==" +
                    (oldEvents == null ? 0 : oldEvents.Count));
            }

            if (!CheckAfterCondition(newEvents, _agentInstanceContext.StatementContext)) {
                return;
            }

            // add the incoming events to the event batches
            if (!_witnessedFirstHelper.WitnessedFirst) {
                var statementResultService = _agentInstanceContext.StatementResultService;

                AddToChangeSet(_joinEventsSet, newEvents, oldEvents);
                var isGenerateSynthetic = statementResultService.IsMakeSynthetic;
                var newOldEvents = _resultSetProcessor
                    .ProcessOutputLimitedJoin(_joinEventsSet, isGenerateSynthetic);
                _joinEventsSet.Clear();

                if (!HasRelevantResults(newOldEvents)) {
                    return;
                }

                _witnessedFirstHelper.WitnessedFirst = true;

                if (_parent.IsDistinct) {
                    newOldEvents.First = EventBeanUtility.GetDistinctByProp(
                        newOldEvents.First,
                        _parent.DistinctKeyGetter);
                    newOldEvents.Second = EventBeanUtility.GetDistinctByProp(
                        newOldEvents.Second,
                        _parent.DistinctKeyGetter);
                }

                var isGenerateNatural = statementResultService.IsMakeNatural;
                if (!isGenerateSynthetic && !isGenerateNatural) {
                    if (AuditPath.isAuditEnabled) {
                        OutputStrategyUtil.IndicateEarlyReturn(_agentInstanceContext.StatementContext, newOldEvents);
                    }

                    return;
                }

                Output(true, newOldEvents);
            }
            else {
                AddToChangeSet(_joinEventsSet, newEvents, oldEvents);

                // Process the events and get the result
                _resultSetProcessor.ProcessOutputLimitedJoin(_joinEventsSet, false);
                _joinEventsSet.Clear();
            }

            var newEventsSize = 0;
            if (newEvents != null) {
                newEventsSize = newEvents.Count;
            }

            var oldEventsSize = 0;
            if (oldEvents != null) {
                oldEventsSize = oldEvents.Count;
            }

            _outputCondition.UpdateOutputCondition(newEventsSize, oldEventsSize);
        }
Exemplo n.º 20
0
        public override void HandleMatching(EventBean[] triggerEvents, EventBean[] matchingEvents)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QInfraOnAction(OnTriggerType.ON_SELECT, triggerEvents, matchingEvents);
            }

            EventBean[] newData;

            // clear state from prior results
            _resultSetProcessor.Clear();

            // build join result
            // use linked hash set to retain order of join results for last/first/window to work most intuitively
            ISet <MultiKey <EventBean> > newEvents = NamedWindowOnSelectView.BuildJoinResult(triggerEvents, matchingEvents);

            // process matches
            UniformPair <EventBean[]> pair = _resultSetProcessor.ProcessJoinResult(newEvents, Collections.GetEmptySet <MultiKey <EventBean> >(), false);

            newData = (pair != null ? pair.First : null);

            if (_parent.IsDistinct)
            {
                newData = EventBeanUtility.GetDistinctByProp(newData, _parent.EventBeanReader);
            }

            if (_parent.InternalEventRouter != null)
            {
                if (newData != null)
                {
                    for (int i = 0; i < newData.Length; i++)
                    {
                        if (_audit)
                        {
                            AuditPath.AuditInsertInto(ExprEvaluatorContext.EngineURI, ExprEvaluatorContext.StatementName, newData[i]);
                        }
                        _parent.InternalEventRouter.Route(newData[i], _parent.StatementHandle, _parent.InternalEventRouteDest, ExprEvaluatorContext, false);
                    }
                }
            }

            // The on-select listeners receive the events selected
            if ((newData != null) && (newData.Length > 0))
            {
                // And post only if we have listeners/subscribers that need the data
                if (_parent.StatementResultService.IsMakeNatural || _parent.StatementResultService.IsMakeSynthetic)
                {
                    UpdateChildren(newData, null);
                }
            }

            // clear state from prior results
            _resultSetProcessor.Clear();

            // Events to delete are indicated via old data
            if (_deleteAndSelect)
            {
                foreach (EventBean @event in matchingEvents)
                {
                    TableStateInstance.DeleteEvent(@event);
                }
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AInfraOnAction();
            }
        }
        /// <summary>
        ///     The update method is called if the view does not participate in a join.
        /// </summary>
        /// <param name="newData">new events</param>
        /// <param name="oldData">old events</param>
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            if (ExecutionPathDebugLog.IsDebugEnabled && Log.IsDebugEnabled) {
                Log.Debug(
                    ".update Received update, " +
                    "  newData.length==" +
                    (newData == null ? 0 : newData.Length) +
                    "  oldData.length==" +
                    (oldData == null ? 0 : oldData.Length));
            }

            if (!CheckAfterCondition(newData, _agentInstanceContext.StatementContext)) {
                return;
            }

            if (!_witnessedFirstHelper.WitnessedFirst) {
                var statementResultService = _agentInstanceContext.StatementResultService;
                var isGenerateSynthetic = statementResultService.IsMakeSynthetic;

                // Process the events and get the result
                _viewEventsList.Add(new UniformPair<EventBean[]>(newData, oldData));
                var newOldEvents =
                    _resultSetProcessor.ProcessOutputLimitedView(_viewEventsList, isGenerateSynthetic);
                _viewEventsList.Clear();

                if (!HasRelevantResults(newOldEvents)) {
                    return;
                }

                _witnessedFirstHelper.WitnessedFirst = true;

                if (_parent.IsDistinct) {
                    newOldEvents.First = EventBeanUtility.GetDistinctByProp(
                        newOldEvents.First,
                        _parent.DistinctKeyGetter);
                    newOldEvents.Second = EventBeanUtility.GetDistinctByProp(
                        newOldEvents.Second,
                        _parent.DistinctKeyGetter);
                }

                var isGenerateNatural = statementResultService.IsMakeNatural;
                if (!isGenerateSynthetic && !isGenerateNatural) {
                    if (AuditPath.isAuditEnabled) {
                        OutputStrategyUtil.IndicateEarlyReturn(_agentInstanceContext.StatementContext, newOldEvents);
                    }

                    return;
                }

                Output(true, newOldEvents);
            }
            else {
                _viewEventsList.Add(new UniformPair<EventBean[]>(newData, oldData));
                _resultSetProcessor.ProcessOutputLimitedView(_viewEventsList, false);
                _viewEventsList.Clear();
            }

            var newDataLength = 0;
            var oldDataLength = 0;
            if (newData != null) {
                newDataLength = newData.Length;
            }

            if (oldData != null) {
                oldDataLength = oldData.Length;
            }

            _outputCondition.UpdateOutputCondition(newDataLength, oldDataLength);
        }