コード例 #1
0
        public override void Apply(
            EventBean matchingEvent,
            EventBean[] eventsPerStream,
            TableStateInstance tableStateInstance,
            TableOnMergeViewChangeHandler changeHandlerAdded,
            TableOnMergeViewChangeHandler changeHandlerRemoved,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            var theEvent = _insertHelper.Process(eventsPerStream, true, true, exprEvaluatorContext);

            if (_internalEventRouter == null)
            {
                var aggs = _tableStateRowFactory.MakeAggs(exprEvaluatorContext.AgentInstanceId, null, null, tableStateInstance.AggregationServicePassThru);
                ((object[])theEvent.Underlying)[0] = aggs;
                tableStateInstance.AddEvent(theEvent);
                if (changeHandlerAdded != null)
                {
                    changeHandlerAdded.Add(theEvent, eventsPerStream, true, exprEvaluatorContext);
                }
                return;
            }

            if (_audit)
            {
                AuditPath.AuditInsertInto(_internalEventRouteDest.EngineURI, _statementHandle.StatementName, theEvent);
            }
            _internalEventRouter.Route(theEvent, _statementHandle, _internalEventRouteDest, exprEvaluatorContext, false);
        }
コード例 #2
0
        public void UpdateTable(
            ICollection <EventBean> eventsUnsafeIter,
            TableStateInstance instance,
            EventBean[] eventsPerStream,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            // update (no-copy unless original values required)
            foreach (EventBean @event in eventsUnsafeIter)
            {
                eventsPerStream[0] = @event;
                var updatedEvent = (ObjectArrayBackedEventBean)@event;

                // if "initial.property" is part of the assignment expressions, provide initial value event
                if (_updateHelper.IsRequiresStream2InitialValueEvent)
                {
                    var prev = new object[updatedEvent.Properties.Length];
                    Array.Copy(updatedEvent.Properties, 0, prev, 0, prev.Length);
                    eventsPerStream[2] = new ObjectArrayEventBean(prev, updatedEvent.EventType);
                }

                // apply in-place updates
                _updateHelper.UpdateNoCopy(updatedEvent, eventsPerStream, exprEvaluatorContext);
                instance.HandleRowUpdated(updatedEvent);
            }
        }
コード例 #3
0
        public override void Apply(EventBean matchingEvent, EventBean[] eventsPerStream, OneEventCollection newData, OneEventCollection oldData, ExprEvaluatorContext exprEvaluatorContext)
        {
            EventBean theEvent = _insertHelper.Process(eventsPerStream, true, true, exprEvaluatorContext);

            if (_insertIntoTableName != null)
            {
                TableStateInstance tableStateInstance = _tableService.GetState(_insertIntoTableName, exprEvaluatorContext.AgentInstanceId);
                if (_audit)
                {
                    AuditPath.AuditInsertInto(tableStateInstance.AgentInstanceContext.EngineURI, _statementHandle.StatementName, theEvent);
                }
                tableStateInstance.AddEventUnadorned(theEvent);
                return;
            }

            if (_internalEventRouter == null)
            {
                newData.Add(theEvent);
                return;
            }

            if (_audit)
            {
                AuditPath.AuditInsertInto(_internalEventRouteDest.EngineURI, _statementHandle.StatementName, theEvent);
            }
            _internalEventRouter.Route(theEvent, _statementHandle, _internalEventRouteDest, exprEvaluatorContext, false);
        }
コード例 #4
0
 public OutputStrategyPostProcess(OutputStrategyPostProcessFactory parent, AgentInstanceContext agentInstanceContext, TableStateInstance tableStateInstance)
 {
     _parent = parent;
     _agentInstanceContext = agentInstanceContext;
     _tableStateInstance   = tableStateInstance;
     _audit = AuditEnum.INSERT.GetAudit(agentInstanceContext.StatementContext.Annotations) != null;
 }
コード例 #5
0
        public override OnExprViewResult DetermineOnExprView(AgentInstanceContext agentInstanceContext, IList <StopCallback> stopCallbacks, bool isRecoveringResilient)
        {
            var processors = new ResultSetProcessor[_splitDesc.ProcessorFactories.Length];

            for (var i = 0; i < processors.Length; i++)
            {
                var factory   = _splitDesc.ProcessorFactories[i];
                var processor = factory.ResultSetProcessorFactory.Instantiate(null, null, agentInstanceContext);
                processors[i] = processor;
            }

            var tableStateInstances = new TableStateInstance[processors.Length];

            for (var i = 0; i < _insertIntoTableNames.Length; i++)
            {
                var tableName = _insertIntoTableNames[i];
                if (tableName != null)
                {
                    tableStateInstances[i] = agentInstanceContext.StatementContext.TableService.GetState(tableName, agentInstanceContext.AgentInstanceId);
                }
            }
            var  desc = (OnTriggerSplitStreamDesc)StatementSpec.OnTriggerDesc;
            View view = new RouteResultView(
                desc.IsFirst, _activatorResultEventType, StatementContext.EpStatementHandle,
                Services.InternalEventRouter, tableStateInstances, _splitDesc.NamedWindowInsert, processors,
                _splitDesc.WhereClauses, agentInstanceContext);

            return(new OnExprViewResult(view, null));
        }
コード例 #6
0
        public override void HandleMatching(EventBean[] triggerEvents, EventBean[] matchingEvents)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QInfraOnAction(OnTriggerType.ON_DELETE, triggerEvents, matchingEvents);
            }

            if ((matchingEvents != null) && (matchingEvents.Length > 0))
            {
                foreach (EventBean @event in matchingEvents)
                {
                    TableStateInstance.DeleteEvent(@event);
                }

                // The on-delete listeners receive the events deleted, but only if there is interest
                if (parent.StatementResultService.IsMakeNatural || parent.StatementResultService.IsMakeSynthetic)
                {
                    EventBean[] posted = TableOnViewUtil.ToPublic(matchingEvents, parent.TableMetadata, triggerEvents, true, base.ExprEvaluatorContext);
                    UpdateChildren(posted, null);
                }
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AInfraOnAction();
            }
        }
コード例 #7
0
 public TableOnViewBase Make(
     SubordWMatchExprLookupStrategy lookupStrategy,
     TableStateInstance tableState,
     AgentInstanceContext agentInstanceContext,
     ResultSetProcessor resultSetProcessor)
 {
     return(new TableOnMergeView(lookupStrategy, tableState, agentInstanceContext, TableMetadata, this));
 }
コード例 #8
0
ファイル: TableOnViewBase.cs プロジェクト: qianqian888/nesper
 protected TableOnViewBase(SubordWMatchExprLookupStrategy lookupStrategy, TableStateInstance tableStateInstance, ExprEvaluatorContext exprEvaluatorContext, TableMetadata metadata, bool acquireWriteLock)
 {
     this.LookupStrategy       = lookupStrategy;
     this.TableStateInstance   = tableStateInstance;
     this.exprEvaluatorContext = exprEvaluatorContext;
     this.Metadata             = metadata;
     this.AcquireWriteLock     = acquireWriteLock;
 }
コード例 #9
0
 public NamedWindowOnSelectView(SubordWMatchExprLookupStrategy lookupStrategy, NamedWindowRootViewInstance rootView, ExprEvaluatorContext exprEvaluatorContext, NamedWindowOnSelectViewFactory parent, ResultSetProcessor resultSetProcessor, bool audit, bool isDelete, TableStateInstance tableStateInstanceInsertInto)
     : base(lookupStrategy, rootView, exprEvaluatorContext)
 {
     _parent             = parent;
     _resultSetProcessor = resultSetProcessor;
     _audit    = audit;
     _isDelete = isDelete;
     _tableStateInstanceInsertInto = tableStateInstanceInsertInto;
 }
コード例 #10
0
ファイル: TableOnSelectView.cs プロジェクト: valmac/nesper
 public TableOnSelectView(SubordWMatchExprLookupStrategy lookupStrategy, TableStateInstance rootView, ExprEvaluatorContext exprEvaluatorContext, TableMetadata metadata,
                          TableOnSelectViewFactory parent, ResultSetProcessor resultSetProcessor, bool audit, bool deleteAndSelect)
     : base(lookupStrategy, rootView, exprEvaluatorContext, metadata, deleteAndSelect)
 {
     _parent             = parent;
     _resultSetProcessor = resultSetProcessor;
     _audit           = audit;
     _deleteAndSelect = deleteAndSelect;
 }
コード例 #11
0
        public override FireAndForgetInstance GetProcessorInstanceContextById(int agentInstanceId)
        {
            TableStateInstance instance = _tableService.GetState(_tableMetadata.TableName, agentInstanceId);

            if (instance == null)
            {
                return(null);
            }
            return(new FireAndForgetInstanceTable(instance));
        }
コード例 #12
0
        public OutputStrategyPostProcess Make(AgentInstanceContext agentInstanceContext)
        {
            TableStateInstance tableStateInstance = null;

            if (TableName != null)
            {
                tableStateInstance = TableService.GetState(TableName, agentInstanceContext.AgentInstanceId);
            }
            return(new OutputStrategyPostProcess(this, agentInstanceContext, tableStateInstance));
        }
コード例 #13
0
ファイル: TableOnMergeView.cs プロジェクト: valmac/nesper
 public TableOnMergeView(
     SubordWMatchExprLookupStrategy lookupStrategy,
     TableStateInstance rootView,
     ExprEvaluatorContext exprEvaluatorContext,
     TableMetadata metadata,
     TableOnMergeViewFactory parent)
     : base(lookupStrategy, rootView, exprEvaluatorContext, metadata, parent.OnMergeHelper.IsRequiresWriteLock)
 {
     this.parent = parent;
 }
コード例 #14
0
        public override NamedWindowOnExprBaseView Make(SubordWMatchExprLookupStrategy lookupStrategy, NamedWindowRootViewInstance namedWindowRootViewInstance, AgentInstanceContext agentInstanceContext, ResultSetProcessor resultSetProcessor)
        {
            bool audit = AuditEnum.INSERT.GetAudit(agentInstanceContext.StatementContext.Annotations) != null;
            TableStateInstance tableStateInstance = null;

            if (_optionalInsertIntoTableName != null)
            {
                tableStateInstance = agentInstanceContext.StatementContext.TableService.GetState(_optionalInsertIntoTableName, agentInstanceContext.AgentInstanceId);
            }
            return(new NamedWindowOnSelectView(lookupStrategy, namedWindowRootViewInstance, agentInstanceContext, this, resultSetProcessor, audit, _deleteAndSelect, tableStateInstance));
        }
コード例 #15
0
        public void UpdateTable(
            ICollection <EventBean> eventsUnsafeIter,
            TableStateInstance instance,
            EventBean[] eventsPerStream,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            // copy references to array - as it is allowed to pass an index-originating collection
            // and those same indexes are being changed now
            var events = new EventBean[eventsUnsafeIter.Count];
            int count  = 0;

            foreach (EventBean @event in eventsUnsafeIter)
            {
                events[count++] = @event;
            }

            // remove from affected indexes
            foreach (string affectedIndexName in _affectedIndexNames)
            {
                EventTable index = instance.GetIndex(affectedIndexName);
                index.Remove(events, instance.AgentInstanceContext);
            }

            // update (no-copy unless original values required)
            foreach (EventBean @event in events)
            {
                eventsPerStream[0] = @event;
                var updatedEvent = (ObjectArrayBackedEventBean)@event;

                // if "initial.property" is part of the assignment expressions, provide initial value event
                if (_updateHelper.IsRequiresStream2InitialValueEvent)
                {
                    var prev = new object[updatedEvent.Properties.Length];
                    Array.Copy(updatedEvent.Properties, 0, prev, 0, prev.Length);
                    eventsPerStream[2] = new ObjectArrayEventBean(prev, updatedEvent.EventType);
                }

                // apply in-place updates
                _updateHelper.UpdateNoCopy(updatedEvent, eventsPerStream, exprEvaluatorContext);
                instance.HandleRowUpdated(updatedEvent);
            }

            // add to affected indexes
            foreach (string affectedIndexName in _affectedIndexNames)
            {
                EventTable index = instance.GetIndex(affectedIndexName);
                index.Add(events, instance.AgentInstanceContext);
            }
        }
コード例 #16
0
	    public override void SetCurrentAccess(object groupByKey, int agentInstanceId, AggregationGroupByRollupLevel rollupLevel)
	    {
	        var key = rollupLevel.ComputeMultiKey(groupByKey, TableMetadata.KeyTypes.Length);
	        var bean = TableStateInstance.GetRowForGroupKey(key);

	        if (bean != null) {
	            var row = (AggregationRowPair) bean.Properties[0];
	            CurrentAggregatorMethods = row.Methods;
	            CurrentAggregatorStates = row.States;
	        }
	        else {
	            CurrentAggregatorMethods = null;
	        }

	        this.CurrentGroupKey = key;
	    }
コード例 #17
0
        public StatementAgentInstanceFactoryResult NewContext(AgentInstanceContext agentInstanceContext, bool isRecoveringResilient)
        {
            StopCallback stopCallback;

            if (namedWindowProcessor != null)
            {
                // handle named window index
                NamedWindowProcessorInstance processorInstance = namedWindowProcessor.GetProcessorInstance(agentInstanceContext);

                if (namedWindowProcessor.IsVirtualDataWindow)
                {
                    VirtualDWView virtualDWView = processorInstance.RootViewInstance.VirtualDataWindow;
                    virtualDWView.HandleStartIndex(spec);
                    stopCallback = () => {
                        virtualDWView.HandleStopIndex(spec);
                    };
                }
                else
                {
                    try {
                        processorInstance.RootViewInstance.AddExplicitIndex(spec.IsUnique, spec.IndexName, spec.Columns);
                    }
                    catch (ExprValidationException e) {
                        throw new EPException("Failed to create index: " + e.Message, e);
                    }
                    stopCallback = () => {
                    };
                }
            }
            else
            {
                // handle table access
                try {
                    TableStateInstance instance = services.TableService.GetState(tableName, agentInstanceContext.AgentInstanceId);
                    instance.AddExplicitIndex(spec);
                }
                catch (ExprValidationException ex) {
                    throw new EPException("Failed to create index: " + ex.Message, ex);
                }
                stopCallback = () => {
                };
            }

            return(new StatementAgentInstanceFactoryCreateIndexResult(finalView, stopCallback, agentInstanceContext));
        }
コード例 #18
0
        private void Route(EventBean routed, int index, ExprEvaluatorContext exprEvaluatorContext)
        {
            if (Audit)
            {
                AuditPath.AuditInsertInto(AgentInstanceContext.EngineURI, AgentInstanceContext.StatementName, routed);
            }
            TableStateInstance tableStateInstance = _tableStateInstances[index];

            if (tableStateInstance != null)
            {
                tableStateInstance.AddEventUnadorned(routed);
            }
            else
            {
                bool isNamedWindowInsert = Items[index].IsNamedWindowInsert;
                InternalEventRouter.Route(
                    routed, EPStatementHandle, AgentInstanceContext.StatementContext.InternalEventEngineRouteDest,
                    exprEvaluatorContext, isNamedWindowInsert);
            }
        }
コード例 #19
0
        public override OnExprViewResult DetermineOnExprView(
            AgentInstanceContext agentInstanceContext,
            IList <StopCallback> stopCallbacks,
            bool isRecoveringReslient)
        {
            var processors = new ResultSetProcessor[_items.Length];

            for (int i = 0; i < processors.Length; i++)
            {
                ResultSetProcessorFactoryDesc factory   = _items[i].FactoryDesc;
                ResultSetProcessor            processor = factory.ResultSetProcessorFactory.Instantiate(
                    null, null, agentInstanceContext);
                processors[i] = processor;
            }

            var tableStateInstances = new TableStateInstance[processors.Length];

            for (int i = 0; i < _items.Length; i++)
            {
                string tableName = _items[i].InsertIntoTableNames;
                if (tableName != null)
                {
                    tableStateInstances[i] = agentInstanceContext.StatementContext.TableService.GetState(
                        tableName, agentInstanceContext.AgentInstanceId);
                }
            }

            var whereClauseEvals = new ExprEvaluator[_items.Length];

            for (int i = 0; i < _items.Length; i++)
            {
                whereClauseEvals[i] = _items[i].WhereClause == null ? null : _items[i].WhereClause.ExprEvaluator;
            }

            var desc = (OnTriggerSplitStreamDesc)base.StatementSpec.OnTriggerDesc;
            var view = new RouteResultView(
                desc.IsFirst, _activatorResultEventType, base.StatementContext.EpStatementHandle, base.Services.InternalEventRouter,
                tableStateInstances, _items, processors, whereClauseEvals, agentInstanceContext);

            return(new OnExprViewResult(view, null));
        }
コード例 #20
0
ファイル: TableOnMergeMatch.cs プロジェクト: ikvm/nesper
        public void Apply(EventBean matchingEvent,
                          EventBean[] eventsPerStream,
                          TableStateInstance stateInstance,
                          TableOnMergeViewChangeHandler changeHandlerAdded,
                          TableOnMergeViewChangeHandler changeHandlerRemoved,
                          ExprEvaluatorContext context)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QInfraMergeWhenThenActions(actions.Count);
            }

            int count = -1;

            foreach (TableOnMergeAction action in actions)
            {
                count++;

                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().QInfraMergeWhenThenActionItem(count, action.Name);
                    bool applies = action.IsApplies(eventsPerStream, context);
                    if (applies)
                    {
                        action.Apply(matchingEvent, eventsPerStream, stateInstance, changeHandlerAdded, changeHandlerRemoved, context);
                    }
                    InstrumentationHelper.Get().AInfraMergeWhenThenActionItem(applies);
                    continue;
                }

                if (action.IsApplies(eventsPerStream, context))
                {
                    action.Apply(matchingEvent, eventsPerStream, stateInstance, changeHandlerAdded, changeHandlerRemoved, context);
                }
            }
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AInfraMergeWhenThenActions();
            }
        }
コード例 #21
0
        public SubSelectStrategyRealization Instantiate(
            EPServicesContext services,
            Viewable viewableRoot,
            AgentInstanceContext agentInstanceContext,
            IList <StopCallback> stopCallbackList,
            int subqueryNumber,
            bool isRecoveringResilient)
        {
            SubselectAggregationPreprocessorBase subselectAggregationPreprocessor = null;

            AggregationService aggregationService = null;

            if (_aggregationServiceFactory != null)
            {
                aggregationService = _aggregationServiceFactory.AggregationServiceFactory.MakeService(
                    agentInstanceContext, agentInstanceContext.StatementContext.EngineImportService, true, subqueryNumber);
                if (_groupByKeys == null)
                {
                    if (_filterExprEval == null)
                    {
                        subselectAggregationPreprocessor =
                            new SubselectAggregationPreprocessorUnfilteredUngrouped(
                                aggregationService, _filterExprEval, null);
                    }
                    else
                    {
                        subselectAggregationPreprocessor =
                            new SubselectAggregationPreprocessorFilteredUngrouped(aggregationService, _filterExprEval, null);
                    }
                }
                else
                {
                    if (_filterExprEval == null)
                    {
                        subselectAggregationPreprocessor =
                            new SubselectAggregationPreprocessorUnfilteredGrouped(
                                aggregationService, _filterExprEval, _groupByKeys);
                    }
                    else
                    {
                        subselectAggregationPreprocessor =
                            new SubselectAggregationPreprocessorFilteredGrouped(
                                aggregationService, _filterExprEval, _groupByKeys);
                    }
                }
            }

            SubordTableLookupStrategy subqueryLookup;

            if (_optionalNamedWindowProcessor != null)
            {
                NamedWindowProcessorInstance instance =
                    _optionalNamedWindowProcessor.GetProcessorInstance(agentInstanceContext);
                if (_queryPlan == null)
                {
                    if (instance.RootViewInstance.IsQueryPlanLogging && NamedWindowRootView.QueryPlanLog.IsInfoEnabled)
                    {
                        NamedWindowRootView.QueryPlanLog.Info("shared, full table scan");
                    }
                    subqueryLookup =
                        new SubordFullTableScanLookupStrategyLocking(
                            instance.RootViewInstance.DataWindowContents,
                            agentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock);
                }
                else
                {
                    EventTable[] tables = null;
                    if (!_optionalNamedWindowProcessor.IsVirtualDataWindow)
                    {
                        tables = SubordinateQueryPlannerUtil.RealizeTables(
                            _queryPlan.IndexDescs, instance.RootViewInstance.EventType,
                            instance.RootViewInstance.IndexRepository,
                            instance.RootViewInstance.DataWindowContents, agentInstanceContext,
                            isRecoveringResilient);
                    }
                    SubordTableLookupStrategy strategy = _queryPlan.LookupStrategyFactory.MakeStrategy(
                        tables, instance.RootViewInstance.VirtualDataWindow);
                    subqueryLookup = new SubordIndexedTableLookupStrategyLocking(
                        strategy, instance.TailViewInstance.AgentInstanceContext.AgentInstanceLock);
                }
            }
            else
            {
                TableStateInstance state = _tableService.GetState(
                    _optionalTableMetadata.TableName, agentInstanceContext.AgentInstanceId);
                ILockable iLock = agentInstanceContext.StatementContext.IsWritesToTables
                    ? state.TableLevelRWLock.WriteLock
                    : state.TableLevelRWLock.ReadLock;
                if (_queryPlan == null)
                {
                    subqueryLookup = new SubordFullTableScanTableLookupStrategy(iLock, state.IterableTableScan);
                }
                else
                {
                    EventTable[] indexes = new EventTable[_queryPlan.IndexDescs.Length];
                    for (int i = 0; i < indexes.Length; i++)
                    {
                        indexes[i] = state.IndexRepository.GetIndexByDesc(_queryPlan.IndexDescs[i].IndexMultiKey);
                    }
                    subqueryLookup = _queryPlan.LookupStrategyFactory.MakeStrategy(indexes, null);
                    subqueryLookup = new SubordIndexedTableLookupTableStrategy(subqueryLookup, iLock);
                }
            }

            return(new SubSelectStrategyRealization(
                       subqueryLookup, subselectAggregationPreprocessor, aggregationService,
                       Collections.GetEmptyMap <ExprPriorNode, ExprPriorEvalStrategy>(),
                       Collections.GetEmptyMap <ExprPreviousNode, ExprPreviousEvalStrategy>(),
                       null, null));
        }
コード例 #22
0
ファイル: TableOnSelectView.cs プロジェクト: valmac/nesper
        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();
            }
        }
コード例 #23
0
        public void UpdateTable(ICollection <EventBean> eventsUnsafeIter, TableStateInstance instance, EventBean[] eventsPerStream, ExprEvaluatorContext exprEvaluatorContext)
        {
            // copy references to array - as it is allowed to pass an index-originating collection
            // and those same indexes are being changed now
            var events = new EventBean[eventsUnsafeIter.Count];
            var count  = 0;

            foreach (var @event in eventsUnsafeIter)
            {
                events[count++] = @event;
            }

            // remove from affected indexes
            foreach (var affectedIndexName in _affectedIndexNames)
            {
                var index = instance.GetIndex(affectedIndexName);
                index.Remove(events);
            }

            // copy event data, since we are updating unique keys and must guarantee rollback (no half update)
            var previousData = new object[events.Length][];

            // copy and then update
            for (var i = 0; i < events.Length; i++)
            {
                eventsPerStream[0] = events[i];

                // copy non-aggregated value references
                var updatedEvent = (ObjectArrayBackedEventBean)events[i];
                var prev         = new object[updatedEvent.Properties.Length];
                Array.Copy(updatedEvent.Properties, 0, prev, 0, prev.Length);
                previousData[i] = prev;

                // if "initial.property" is part of the assignment expressions, provide initial value event
                if (_updateHelper.IsRequiresStream2InitialValueEvent)
                {
                    eventsPerStream[2] = new ObjectArrayEventBean(prev, updatedEvent.EventType);
                }

                // apply in-place updates
                instance.HandleRowUpdateKeyBeforeUpdate(updatedEvent);
                _updateHelper.UpdateNoCopy(updatedEvent, eventsPerStream, exprEvaluatorContext);
                instance.HandleRowUpdateKeyAfterUpdate(updatedEvent);
            }

            // add to affected indexes
            try {
                foreach (var affectedIndexName in _affectedIndexNames)
                {
                    var index = instance.GetIndex(affectedIndexName);
                    index.Add(events);
                }
            }
            catch (EPException ex) {
                // rollback
                // remove updated events
                foreach (var affectedIndexName in _affectedIndexNames)
                {
                    var index = instance.GetIndex(affectedIndexName);
                    index.Remove(events);
                }
                // rollback change to events
                for (var i = 0; i < events.Length; i++)
                {
                    var oa = (ObjectArrayBackedEventBean)events[i];
                    oa.PropertyValues = previousData[i];
                }
                // add old events
                foreach (var affectedIndexName in _affectedIndexNames)
                {
                    var index = instance.GetIndex(affectedIndexName);
                    index.Add(events);
                }
                throw ex;
            }
        }
コード例 #24
0
 public TableOnViewBase Make(SubordWMatchExprLookupStrategy lookupStrategy, TableStateInstance tableState, AgentInstanceContext agentInstanceContext, ResultSetProcessor resultSetProcessor)
 {
     bool audit = AuditEnum.INSERT.GetAudit(agentInstanceContext.StatementContext.Annotations) != null;
     return new TableOnSelectView(lookupStrategy, tableState, agentInstanceContext, _tableMetadata, this, resultSetProcessor, audit, _deleteAndSelect);
 }
コード例 #25
0
 public AggregationServiceTable(TableStateInstance tableState)
 {
     this._tableState = tableState;
 }
コード例 #26
0
 public FireAndForgetInstanceTable(TableStateInstance instance)
 {
     _instance = instance;
 }
コード例 #27
0
ファイル: ViewableActivatorTable.cs プロジェクト: ikvm/nesper
        public ViewableActivationResult Activate(AgentInstanceContext agentInstanceContext, bool isSubselect, bool isRecoveringResilient)
        {
            TableStateInstance state = agentInstanceContext.StatementContext.TableService.GetState(_tableMetadata.TableName, agentInstanceContext.AgentInstanceId);

            return(new ViewableActivationResult(new TableStateViewableInternal(_tableMetadata, state, _optionalTableFilters), CollectionUtil.STOP_CALLBACK_NONE, null, null, null, false, false, null));
        }
コード例 #28
0
 public override void Apply(EventBean matchingEvent, EventBean[] eventsPerStream, TableStateInstance tableStateInstance, TableOnMergeViewChangeHandler changeHandlerAdded, TableOnMergeViewChangeHandler changeHandlerRemoved, ExprEvaluatorContext exprEvaluatorContext)
 {
     tableStateInstance.DeleteEvent(matchingEvent);
     if (changeHandlerRemoved != null)
     {
         changeHandlerRemoved.Add(matchingEvent, eventsPerStream, false, exprEvaluatorContext);
     }
 }
コード例 #29
0
        public StatementAgentInstanceFactoryResult NewContext(AgentInstanceContext agentInstanceContext, bool isRecoveringResilient)
        {
            StopCallback stopCallback;

            int agentInstanceId = agentInstanceContext.AgentInstanceId;

            if (namedWindowProcessor != null)
            {
                // handle named window index
                NamedWindowProcessorInstance processorInstance = namedWindowProcessor.GetProcessorInstance(agentInstanceContext);

                if (namedWindowProcessor.IsVirtualDataWindow)
                {
                    VirtualDWView virtualDWView = processorInstance.RootViewInstance.VirtualDataWindow;
                    virtualDWView.HandleStartIndex(spec);
                    stopCallback = new ProxyStopCallback(() => virtualDWView.HandleStopIndex(spec));
                }
                else
                {
                    try {
                        processorInstance.RootViewInstance.AddExplicitIndex(spec.IsUnique, spec.IndexName, spec.Columns, isRecoveringResilient);
                    }
                    catch (ExprValidationException e) {
                        throw new EPException("Failed to create index: " + e.Message, e);
                    }
                    stopCallback = new ProxyStopCallback(() => {
                        // we remove the index when context partitioned.
                        // when not context partition the index gets removed when the last reference to the named window gets destroyed.
                        if (contextName != null)
                        {
                            var instance = namedWindowProcessor.GetProcessorInstance(agentInstanceId);
                            if (instance != null)
                            {
                                instance.RemoveExplicitIndex(spec.IndexName);
                            }
                        }
                    });
                }
            }
            else
            {
                // handle table access
                try {
                    TableStateInstance instance = services.TableService.GetState(tableName, agentInstanceContext.AgentInstanceId);
                    instance.AddExplicitIndex(spec, isRecoveringResilient, contextName != null);
                }
                catch (ExprValidationException ex) {
                    throw new EPException("Failed to create index: " + ex.Message, ex);
                }
                stopCallback = new ProxyStopCallback(() => {
                    // we remove the index when context partitioned.
                    // when not context partition the index gets removed when the last reference to the table gets destroyed.
                    if (contextName != null)
                    {
                        TableStateInstance instance = services.TableService.GetState(tableName, agentInstanceId);
                        if (instance != null)
                        {
                            instance.RemoveExplicitIndex(spec.IndexName);
                        }
                    }
                });
            }

            return(new StatementAgentInstanceFactoryCreateIndexResult(finalView, stopCallback, agentInstanceContext));
        }
コード例 #30
0
 public TableOnDeleteView(SubordWMatchExprLookupStrategy lookupStrategy, TableStateInstance rootView, ExprEvaluatorContext exprEvaluatorContext, TableMetadata metadata, TableOnDeleteViewFactory parent)
     : base(lookupStrategy, rootView, exprEvaluatorContext, metadata, true)
 {
     this.parent = parent;
 }