/// <summary>Processes batched events in case of output-rate limiting.</summary>
        /// <param name="joinEventsSet">the join results</param>
        /// <param name="generateSynthetic">flag to indicate whether synthetic events must be generated</param>
        /// <param name="outputLimitLimitType">the type of output rate limiting</param>
        /// <returns>results for dispatch</returns>
        public virtual UniformPair <EventBean[]> ProcessOutputLimitedJoin(IList <UniformPair <ISet <MultiKey <EventBean> > > > joinEventsSet, bool generateSynthetic, OutputLimitLimitType outputLimitLimitType)
        {
            if (outputLimitLimitType != OutputLimitLimitType.LAST)
            {
                var flattened = EventBeanUtility.FlattenBatchJoin(joinEventsSet);
                return(ProcessJoinResult(flattened.First, flattened.Second, generateSynthetic));
            }

            throw new IllegalStateException("Output last is provided by " + typeof(OutputProcessViewConditionLastAllUnord).Name);
        }
Example #2
0
 public UniformPair<EventBean[]> OutputView(bool isSynthesize)
 {
     var pair = processor.ProcessViewResult(
         EventBeanUtility.ToArrayNullIfEmpty(eventsNewView),
         EventBeanUtility.ToArrayNullIfEmpty(eventsOldView),
         isSynthesize);
     eventsNewView.Clear();
     eventsOldView.Clear();
     return pair;
 }
Example #3
0
 public UniformPair<EventBean[]> OutputJoin(bool isSynthesize)
 {
     var pair = processor.ProcessJoinResult(
         EventBeanUtility.ToLinkedHashSetNullIfEmpty(eventsNewJoin),
         EventBeanUtility.ToLinkedHashSetNullIfEmpty(eventsOldJoin),
         isSynthesize);
     eventsNewJoin.Clear();
     eventsOldJoin.Clear();
     return pair;
 }
        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) {
                resultSetProcessor = ProcessorWithAssign(
                    select.ResultSetProcessorFactoryProvider,
                    contextPartitionResult.Context,
                    assignerSetter,
                    select.TableAccesses,
                    select.Subselects);

                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.DistinctKeyGetter);
            return new EPPreparedQueryResult(select.EventType, distinct);
        }
Example #5
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="eventType">event type to expect for lookup</param>
 /// <param name="property">The property.</param>
 /// <param name="index">index to look up in</param>
 public IndexedTableLookupStrategySingle(EventType eventType, String property, PropertyIndexedEventTableSingle index)
 {
     _eventType = eventType;
     _property  = property;
     if (index == null)
     {
         throw new ArgumentException("Unexpected null index received");
     }
     _index          = index;
     _propertyGetter = EventBeanUtility.GetAssertPropertyGetter(eventType, property);
 }
Example #6
0
 public void SaveDeclaredExpressionLastColl(
     object node,
     EventBean[] eventsPerStream,
     FlexCollection result)
 {
     var copy = EventBeanUtility.CopyArray(eventsPerStream);
     var entry = new ExpressionResultCacheEntryEventBeanArrayAndCollBean(copy, result: result);
     exprDeclCacheCollection.Put(
         node,
         new SoftReference<ExpressionResultCacheEntryEventBeanArrayAndCollBean>(entry));
 }
        public void Remove(EventBean theEvent, AnyMap parent)
        {
            Object sortable = _propertyGetter.Get(theEvent);

            if (sortable == null)
            {
                if (_nullKeys != null)
                {
                    _nullKeys.Remove(theEvent);
                }
                return;
            }

            sortable = EventBeanUtility.Coerce(sortable, _coercionType);

            // if this is a leaf, remove event
            if (_next == null)
            {
                var eventMap = parent;
                if (eventMap == null)
                {
                    return;
                }

                var events = eventMap.Get(sortable) as ICollection <EventBean>;
                if (events == null)
                {
                    return;
                }

                if (!events.Remove(theEvent))
                {
                    return;
                }

                if (events.IsEmpty())
                {
                    parent.Remove(sortable);
                }
            }
            else
            {
                var innerIndex = (AnyMap)parent.Get(sortable);
                if (innerIndex == null)
                {
                    return;
                }
                _next.Remove(theEvent, innerIndex);
                if (innerIndex.IsEmpty())
                {
                    parent.Remove(sortable);
                }
            }
        }
        public UniformPair <EventBean[]> OutputView(bool isSynthesize)
        {
            if (_outputLastIStreamBufView == null && _outputLastRStreamBufView == null)
            {
                return(null);
            }
            UniformPair <EventBean[]> pair = _processor.ProcessViewResult(EventBeanUtility.ToArrayIfNotNull(_outputLastIStreamBufView), EventBeanUtility.ToArrayIfNotNull(_outputLastRStreamBufView), isSynthesize);

            _outputLastIStreamBufView = null;
            _outputLastRStreamBufView = null;
            return(pair);
        }
Example #9
0
        public void Enter(EventBean theEvent, AnyMap parent)
        {
            var mk         = EventBeanUtility.GetMultiKey(theEvent, _propertyGetters, _keyCoercionTypes);
            var innerIndex = (AnyMap)parent.Get(mk);

            if (innerIndex == null)
            {
                innerIndex = new OrderedDictionary <Object, Object>();
                parent.Put(mk, innerIndex);
            }
            _next.Enter(theEvent, innerIndex);
        }
        protected override Object GetKey(EventBean theEvent)
        {
            var keyValue = base.GetKey(theEvent);

            if ((keyValue != null) && (keyValue.GetType() != _coercionType))
            {
                keyValue = keyValue.IsNumber()
                    ? _coercer.Invoke(keyValue)
                    : EventBeanUtility.Coerce(keyValue, _coercionType);
            }
            return(keyValue);
        }
        public ICollection <EventBean> Get(EventBean theEvent, DataMap parent, ExprEvaluatorContext context)
        {
            _events[_lookupStream] = theEvent;
            var mk         = EventBeanUtility.GetMultiKey(_events, _evaluators, context, _keyCoercionTypes);
            var innerIndex = (DataMap)parent.Get(mk);

            if (innerIndex == null)
            {
                return(null);
            }
            return(_next.Get(theEvent, innerIndex, context));
        }
        public UniformPair <EventBean[]> OutputJoin(bool isSynthesize)
        {
            if (_outputLastIStreamBufJoin == null && _outputLastRStreamBufJoin == null)
            {
                return(null);
            }
            UniformPair <EventBean[]> pair = _processor.ProcessJoinResult(EventBeanUtility.ToSingletonSetIfNotNull(_outputLastIStreamBufJoin), EventBeanUtility.ToSingletonSetIfNotNull(_outputLastRStreamBufJoin), isSynthesize);

            _outputLastIStreamBufJoin = null;
            _outputLastRStreamBufJoin = null;
            return(pair);
        }
Example #13
0
        private void PrintList(EventBean[] events)
        {
            if (events == null) {
                log.Debug(".printList : null-value events array");
                return;
            }

            log.Debug(".printList : " + events.Length + " elements...");
            for (var i = 0; i < events.Length; i++) {
                log.Debug("  " + EventBeanUtility.PrintEvent(events[i]));
            }
        }
        /// <summary>Processes batched events in case of output-rate limiting.</summary>
        /// <param name="viewEventsList">the view results</param>
        /// <param name="generateSynthetic">flag to indicate whether synthetic events must be generated</param>
        /// <param name="outputLimitLimitType">the type of output rate limiting</param>
        /// <returns>results for dispatch</returns>
        public virtual UniformPair <EventBean[]> ProcessOutputLimitedView(IList <UniformPair <EventBean[]> > viewEventsList,
                                                                          bool generateSynthetic,
                                                                          OutputLimitLimitType outputLimitLimitType)
        {
            if (outputLimitLimitType != OutputLimitLimitType.LAST)
            {
                UniformPair <EventBean[]> pair = EventBeanUtility.FlattenBatchStream(viewEventsList);
                return(ProcessViewResult(pair.First, pair.Second, generateSynthetic));
            }

            throw new IllegalStateException("Output last is provided by " + typeof(OutputProcessViewConditionLastAllUnord).Name);
        }
        // No filter and with select clause
        public virtual ICollection <object> EvaluateGetCollScalar(EventBean[] eventsPerStream, bool isNewData, ICollection <EventBean> matchingEvents, ExprEvaluatorContext context, ExprSubselectRowNode parent)
        {
            var result         = new List <Object>();
            var events         = EventBeanUtility.AllocatePerStreamShift(eventsPerStream);
            var evaluateParams = new EvaluateParams(events, isNewData, context);

            foreach (var subselectEvent in matchingEvents)
            {
                events[0] = subselectEvent;
                result.Add(parent.SelectClauseEvaluator[0].Evaluate(evaluateParams));
            }
            return(result);
        }
        public void ProcessJoin(ISet <MultiKey <EventBean> > newEvents, ISet <MultiKey <EventBean> > oldEvents, bool isGenerateSynthetic)
        {
            if (processor.Prototype.IsSelectRStream)
            {
                EventBean[] eventsX = processor.GetSelectListEvents(false, isGenerateSynthetic, true);
                EventBeanUtility.AddToCollection(eventsX, eventsOld);
            }

            ResultSetProcessorUtil.ApplyAggJoinResult(processor.AggregationService, processor._exprEvaluatorContext, newEvents, oldEvents);

            EventBean[] events = processor.GetSelectListEvents(true, isGenerateSynthetic, true);
            EventBeanUtility.AddToCollection(events, eventsNew);
        }
Example #17
0
        public ExpressionResultCacheEntryEventBeanArrayAndObj GetDeclaredExpressionLastValue(
            object node,
            EventBean[] eventsPerStream)
        {
            var cacheRef = exprDeclCacheObject.Get(node);

            var entry = cacheRef?.Get();
            if (entry == null) {
                return null;
            }

            return EventBeanUtility.CompareEventReferences(entry.Reference, eventsPerStream) ? entry : null;
        }
        // Filter and Select
        public EventBean EvaluateGetEventBean(EventBean[] eventsPerStream, bool isNewData, ICollection <EventBean> matchingEvents, ExprEvaluatorContext context, ExprSubselectRowNode parent)
        {
            var events          = EventBeanUtility.AllocatePerStreamShift(eventsPerStream);
            var subSelectResult = ExprSubselectRowNodeUtility.EvaluateFilterExpectSingleMatch(events, isNewData, matchingEvents, context, parent);

            if (subSelectResult == null)
            {
                return(null);
            }
            var row = parent.EvaluateRow(events, true, context);

            return(parent.subselectMultirowType.EventAdapterService.AdapterForTypedMap(row, parent.subselectMultirowType.EventType));
        }
        public UniformPair<EventBean[]> OutputView(bool isSynthesize)
        {
            if (outputLastIStreamBufView == null && outputLastRStreamBufView == null) {
                return null;
            }

            var pair = processor.ProcessViewResult(
                EventBeanUtility.ToArrayIfNotNull(outputLastIStreamBufView),
                EventBeanUtility.ToArrayIfNotNull(outputLastRStreamBufView),
                isSynthesize);
            outputLastIStreamBufView = null;
            outputLastRStreamBufView = null;
            return pair;
        }
        public void ProcessView(EventBean[] newData, EventBean[] oldData, bool isGenerateSynthetic)
        {
            if (processor.Prototype.IsSelectRStream)
            {
                EventBean[] eventsX = processor.GetSelectListEvents(false, isGenerateSynthetic, false);
                EventBeanUtility.AddToCollection(eventsX, eventsOld);
            }

            EventBean[] eventsPerStream = new EventBean[1];
            ResultSetProcessorUtil.ApplyAggViewResult(processor.AggregationService, processor._exprEvaluatorContext, newData, oldData, eventsPerStream);

            EventBean[] events = processor.GetSelectListEvents(true, isGenerateSynthetic, false);
            EventBeanUtility.AddToCollection(events, eventsNew);
        }
Example #21
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="streamNum">the stream number that is indexed</param>
        /// <param name="eventType">types of events indexed</param>
        /// <param name="propertyNames">The property names.</param>
        /// <param name="unique">if set to <c>true</c> [unique].</param>
        /// <param name="optionalIndexName">Name of the optional index.</param>
        public PropertyIndexedEventTableSingleArrayFactory(int streamNum, EventType eventType, String[] propertyNames, bool unique, String optionalIndexName)
        {
            StreamNum         = streamNum;
            PropertyNames     = propertyNames;
            Unique            = unique;
            OptionalIndexName = optionalIndexName;

            // Init getters
            PropertyGetters = new EventPropertyGetter[propertyNames.Length];
            for (var i = 0; i < propertyNames.Length; i++)
            {
                PropertyGetters[i] = EventBeanUtility.GetAssertPropertyGetter(eventType, propertyNames[i]);
            }
        }
Example #22
0
 // No filter and no select-clause: return underlying event
 public virtual Object Evaluate(
     EventBean[] eventsPerStream,
     bool newData,
     ICollection <EventBean> matchingEvents,
     ExprEvaluatorContext exprEvaluatorContext,
     ExprSubselectRowNode parent)
 {
     if (matchingEvents.Count > 1)
     {
         Log.Warn(parent.GetMultirowMessage());
         return(null);
     }
     return(EventBeanUtility.GetNonemptyFirstEventUnderlying(matchingEvents));
 }
        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);
            }
        }
        private void GetGroupedResults(
            IDictionary<object, UniformPair<EventBean[]>> groups,
            EventBean[] events,
            bool insertStream,
            EventBean[] eventsPerStream)
        {
            if (events == null) {
                return;
            }

            foreach (var theEvent in events) {
                var evalEvent = theEvent;
                if (evalEvent is NaturalEventBean) {
                    evalEvent = ((NaturalEventBean) evalEvent).OptionalSynthetic;
                }

                eventsPerStream[0] = evalEvent;
                var key = _groupDeliveryExpressions.Evaluate(eventsPerStream, true, _epStatement.StatementContext);

                var groupEntry = groups.Get(key);
                if (groupEntry == null) {
                    if (insertStream) {
                        groupEntry = new UniformPair<EventBean[]>(new[] {theEvent}, null);
                    }
                    else {
                        groupEntry = new UniformPair<EventBean[]>(null, new[] {theEvent});
                    }

                    groups.Put(key, groupEntry);
                }
                else {
                    if (insertStream) {
                        if (groupEntry.First == null) {
                            groupEntry.First = new[] {theEvent};
                        }
                        else {
                            groupEntry.First = EventBeanUtility.AddToArray(groupEntry.First, theEvent);
                        }
                    }
                    else {
                        if (groupEntry.Second == null) {
                            groupEntry.Second = new[] {theEvent};
                        }
                        else {
                            groupEntry.Second = EventBeanUtility.AddToArray(groupEntry.Second, theEvent);
                        }
                    }
                }
            }
        }
Example #25
0
        // No filter and with select clause
        public virtual EventBean EvaluateGetEventBean(
            EventBean[] eventsPerStream,
            bool newData,
            ICollection <EventBean> matchingEvents,
            ExprEvaluatorContext context,
            ExprSubselectRowNode parent)
        {
            EventBean[] events = EventBeanUtility.AllocatePerStreamShift(eventsPerStream);
            events[0] = EventBeanUtility.GetNonemptyFirstEvent(matchingEvents);
            var row = parent.EvaluateRow(events, true, context);

            return(parent.subselectMultirowType.EventAdapterService.AdapterForTypedMap(
                       row, parent.subselectMultirowType.EventType));
        }
        public UniformPair<EventBean[]> Output()
        {
            EventBean[] oldEvents = EventBeanUtility.ToArrayNullIfEmpty(eventsOld);
            EventBean[] newEvents = EventBeanUtility.ToArrayNullIfEmpty(eventsNew);

            UniformPair<EventBean[]> result = null;
            if (oldEvents != null || newEvents != null) {
                result = new UniformPair<EventBean[]>(newEvents, oldEvents);
            }

            eventsOld.Clear();
            eventsNew.Clear();
            return result;
        }
        public ISet <EventBean> GetCollectKeys(EventBean theEvent, DataMap parent, ExprEvaluatorContext context, IList <Object> keys)
        {
            _events[_lookupStream] = theEvent;
            var mk = EventBeanUtility.GetMultiKey(_events, _evaluators, context, _keyCoercionTypes);

            keys.AddAll(mk.Keys);
            var innerIndex = (DataMap)parent.Get(mk);

            if (innerIndex == null)
            {
                return(null);
            }
            return(_next.GetCollectKeys(theEvent, innerIndex, context, keys));
        }
Example #28
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);
            }
        }
        public UniformPair<EventBean[]> OutputJoin(bool isSynthesize)
        {
            if (outputLastIStreamBufJoin == null && outputLastRStreamBufJoin == null) {
                return null;
            }

            var pair = processor.ProcessJoinResult(
                EventBeanUtility.ToSingletonSetIfNotNull(outputLastIStreamBufJoin),
                EventBeanUtility.ToSingletonSetIfNotNull(outputLastRStreamBufJoin),
                isSynthesize);
            outputLastIStreamBufJoin = null;
            outputLastRStreamBufJoin = null;
            return pair;
        }
Example #30
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="streamNum">the stream number that is indexed</param>
        /// <param name="eventType">types of events indexed</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="unique">if set to <c>true</c> [unique].</param>
        /// <param name="optionalIndexName">Name of the optional index.</param>
        public PropertyIndexedEventTableSingleFactory(
            int streamNum,
            EventType eventType,
            String propertyName,
            bool unique,
            String optionalIndexName)
        {
            StreamNum         = streamNum;
            PropertyName      = propertyName;
            Unique            = unique;
            OptionalIndexName = optionalIndexName;

            // Init getters
            PropertyGetter = EventBeanUtility.GetAssertPropertyGetter(eventType, propertyName);
        }