コード例 #1
0
        public ICollection <EventBean> SnapshotNoLock(FilterSpecCompiled filter, Attribute[] annotations)
        {
            if (_tailView.RevisionProcessor != null)
            {
                return(_tailView.RevisionProcessor.GetSnapshot(_agentInstanceContext.EpStatementAgentInstanceHandle, Parent));
            }

            var indexedResult = _rootViewInstance.Snapshot(filter, annotations);

            if (indexedResult != null)
            {
                return(indexedResult);
            }

            var en = Parent.GetEnumerator();

            if (!en.MoveNext())
            {
                return(Collections.GetEmptyList <EventBean>());
            }

            var list = new ArrayDeque <EventBean>(1024);

            do
            {
                list.Add(en.Current);
            } while (en.MoveNext());

            return(list);
        }
コード例 #2
0
        private static void AddAddendums(
            IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> addendums,
            IList <FilterValueSetParam> addendumFilters,
            FilterSpecCompiled filtersSpec,
            FilterValueSetParam[][] optionalPartitionFilters)
        {
            FilterValueSetParam[][] params2Dim = new FilterValueSetParam[1][];
            params2Dim[0] = addendumFilters.ToArray();

            FilterValueSetParam[][] addendum;
            FilterValueSetParam[][] existing = addendums.Get(filtersSpec);
            if (existing != null)
            {
                addendum = ContextControllerAddendumUtil.MultiplyAddendum(existing, params2Dim);
            }
            else
            {
                addendum = params2Dim;
            }

            if (optionalPartitionFilters != null)
            {
                addendum = ContextControllerAddendumUtil.MultiplyAddendum(addendum, optionalPartitionFilters);
            }

            addendums[filtersSpec] = addendum;
        }
コード例 #3
0
ファイル: StreamFactorySvcImpl.cs プロジェクト: ikvm/nesper
        /// <summary>
        /// See the method of the same name in <seealso cref="com.espertech.esper.view.stream.StreamFactoryService"/>.
        /// </summary>
        /// <param name="filterSpec">is the filter definition</param>
        /// <param name="filterService">to be used to deactivate filter when the last event stream is dropped</param>
        /// <param name="isJoin">is indicatng whether the stream will participate in a join statement, informationnecessary for stream reuse and multithreading concerns</param>
        /// <param name="hasOrderBy">if the consumer has an order-by clause</param>
        /// <param name="filterWithSameTypeSubselect"></param>
        /// <param name="stateless"></param>
        public void DropStream(
            FilterSpecCompiled filterSpec,
            FilterService filterService,
            bool isJoin,
            bool hasOrderBy,
            bool filterWithSameTypeSubselect,
            bool stateless)
        {
            StreamEntry entry;
            var         forceNewStream = isJoin || (!_isReuseViews) || hasOrderBy || filterWithSameTypeSubselect || stateless;

            if (forceNewStream)
            {
                entry = _eventStreamsIdentity.Get(filterSpec);
                if (entry == null)
                {
                    throw new IllegalStateException("Filter spec object not in collection");
                }
                _eventStreamsIdentity.Remove(filterSpec);
                filterService.Remove(entry.Callback, entry.FilterServiceEntry);
            }
            else
            {
                entry = _eventStreamsRefCounted[filterSpec];
                var isLast = _eventStreamsRefCounted.Dereference(filterSpec);
                if (isLast)
                {
                    filterService.Remove(entry.Callback, entry.FilterServiceEntry);
                }
            }
        }
コード例 #4
0
        public EventBean[] SnapshotUpdate(FilterSpecCompiled filter, ExprNode optionalWhereClause, EventBeanUpdateHelper updateHelper, Attribute[] annotations)
        {
            using (_agentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock.AcquireReadLock())
            {
                try
                {
                    var events = SnapshotNoLockWithFilter(filter, annotations, optionalWhereClause, _agentInstanceContext);
                    if (events.IsEmpty())
                    {
                        return(CollectionUtil.EVENTBEANARRAY_EMPTY);
                    }

                    var eventsPerStream = new EventBean[3];
                    var updated         = new EventBean[events.Count];
                    var count           = 0;
                    foreach (var @event in events)
                    {
                        updated[count++] = updateHelper.UpdateWCopy(@event, eventsPerStream, _agentInstanceContext);
                    }

                    var deleted = events.ToArray();
                    _rootViewInstance.Update(updated, deleted);
                    return(updated);
                }
                finally
                {
                    ReleaseTableLocks(_agentInstanceContext);
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Returns null when a filter cannot be applied, and a collection iterator must be used instead.
 /// Returns best-effort matching events otherwise which should still be run through any filter expressions.
 /// </summary>
 private ICollection <EventBean> SnapshotNullWhenNoIndex(FilterSpecCompiled filter, Attribute[] annotations, ExprNode optionalWhereClause, AgentInstanceContext agentInstanceContext)
 {
     // return null when filter cannot be applies
     return(FireAndForgetQueryExec.Snapshot(filter, annotations, null,
                                            _instance.IndexRepository, _instance.TableMetadata.IsQueryPlanLogging,
                                            TableServiceImpl.QueryPlanLog, _instance.TableMetadata.TableName,
                                            _instance.AgentInstanceContext));
 }
コード例 #6
0
 public EPPreparedExecuteIUDSingleStreamExecDelete(FilterSpecCompiled filter, ExprNode optionalWhereClause, Attribute[] annotations, ExprTableAccessNode[] optionalTableNodes, EPServicesContext services)
 {
     _filter = filter;
     _optionalWhereClause = optionalWhereClause;
     _annotations         = annotations;
     _optionalTableNodes  = optionalTableNodes;
     _services            = services;
 }
コード例 #7
0
 internal ViewableActivatorFilterProxy(EPServicesContext services, FilterSpecCompiled filterSpec, Attribute[] annotations, bool subSelect, InstrumentationAgent instrumentationAgent, bool isCanIterate)
 {
     _services             = services;
     _filterSpec           = filterSpec;
     _annotations          = annotations;
     _isSubSelect          = subSelect;
     _instrumentationAgent = instrumentationAgent;
     _isCanIterate         = isCanIterate;
 }
コード例 #8
0
 public CreateWindowCompileResult(
     FilterSpecCompiled filterSpecCompiled,
     SelectClauseSpecRaw selectClauseSpecRaw,
     EventType asEventType)
 {
     this.filterSpecCompiled = filterSpecCompiled;
     this.selectClauseSpecRaw = selectClauseSpecRaw;
     this.asEventType = asEventType;
 }
コード例 #9
0
        public override EPPreparedExecuteIUDSingleStreamExec GetExecutor(FilterSpecCompiled filter, string aliasName)
        {
            var services         = base.Services;
            var processor        = base.Processor;
            var statementContext = base.StatementContext;
            var statementSpec    = base.StatementSpec;
            var updateSpec       = (FireAndForgetSpecUpdate)statementSpec.FireAndForgetSpec;

            var assignmentTypeService = new StreamTypeServiceImpl(
                new EventType[] { processor.EventTypeResultSetProcessor, null, processor.EventTypeResultSetProcessor },
                new string[] { aliasName, "", EPStatementStartMethodOnTrigger.INITIAL_VALUE_STREAM_NAME },
                new bool[] { true, true, true }, services.EngineURI, true);

            assignmentTypeService.IsStreamZeroUnambigous = true;
            var evaluatorContextStmt = new ExprEvaluatorContextStatement(statementContext, true);
            var validationContext    = new ExprValidationContext(
                assignmentTypeService, statementContext.EngineImportService,
                statementContext.StatementExtensionServicesContext, null, statementContext.SchedulingService,
                statementContext.VariableService, statementContext.TableService, evaluatorContextStmt,
                statementContext.EventAdapterService, statementContext.StatementName, statementContext.StatementId,
                statementContext.Annotations, statementContext.ContextDescriptor, statementContext.ScriptingService,
                false, false, true, false, null, false);

            // validate update expressions
            try {
                foreach (OnTriggerSetAssignment assignment in updateSpec.Assignments)
                {
                    ExprNode validated = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.UPDATEASSIGN, assignment.Expression, validationContext);
                    assignment.Expression = validated;
                    EPStatementStartMethodHelperValidate.ValidateNoAggregations(validated, "Aggregation functions may not be used within an update-clause");
                }
            } catch (ExprValidationException e) {
                throw new EPException(e.Message, e);
            }

            // make updater
            EventBeanUpdateHelper updateHelper;
            TableUpdateStrategy   tableUpdateStrategy = null;

            try {
                bool copyOnWrite = !(processor is FireAndForgetProcessorTable);
                updateHelper = EventBeanUpdateHelperFactory.Make(processor.NamedWindowOrTableName,
                                                                 (EventTypeSPI)processor.EventTypeResultSetProcessor, updateSpec.Assignments, aliasName, null, copyOnWrite, statementContext.StatementName, services.EngineURI, services.EventAdapterService);

                if (processor is FireAndForgetProcessorTable)
                {
                    FireAndForgetProcessorTable tableProcessor = (FireAndForgetProcessorTable)processor;
                    tableUpdateStrategy = services.TableService.GetTableUpdateStrategy(tableProcessor.TableMetadata, updateHelper, false);
                    copyOnWrite         = false;
                }
            } catch (ExprValidationException e) {
                throw new EPException(e.Message, e);
            }

            return(new EPPreparedExecuteIUDSingleStreamExecUpdate(filter, statementSpec.FilterRootNode, statementSpec.Annotations, updateHelper, tableUpdateStrategy, statementSpec.TableNodes, services));
        }
コード例 #10
0
 public EPPreparedExecuteIUDSingleStreamExecUpdate(FilterSpecCompiled filter, ExprNode optionalWhereClause, Attribute[] annotations, EventBeanUpdateHelper updateHelper, TableUpdateStrategy tableUpdateStrategy, ExprTableAccessNode[] optionalTableNodes, EPServicesContext services)
 {
     Filter = filter;
     OptionalWhereClause = optionalWhereClause;
     Annotations         = annotations;
     UpdateHelper        = updateHelper;
     TableUpdateStrategy = tableUpdateStrategy;
     OptionalTableNodes  = optionalTableNodes;
     Services            = services;
 }
コード例 #11
0
 public CreateWindowCompileResult(
     FilterSpecCompiled filterSpecCompiled,
     SelectClauseSpecRaw selectClauseSpecRaw,
     EventType asEventType,
     IList<StmtClassForgeableFactory> additionalForgeables)
 {
     FilterSpecCompiled = filterSpecCompiled;
     SelectClauseSpecRaw = selectClauseSpecRaw;
     AsEventType = asEventType;
     AdditionalForgeables = additionalForgeables;
 }
コード例 #12
0
        /// <summary>
        /// Return a snapshot using index lookup filters.
        /// </summary>
        /// <param name="optionalFilter">to index lookup</param>
        /// <returns>events</returns>
        public ICollection <EventBean> Snapshot(FilterSpecCompiled optionalFilter, Attribute[] annotations)
        {
            VirtualDWView virtualDataWindow = null;

            if (IsVirtualDataWindow)
            {
                virtualDataWindow = VirtualDataWindow;
            }
            return(FireAndForgetQueryExec.Snapshot(optionalFilter, annotations, virtualDataWindow,
                                                   _indexRepository, _rootView.IsQueryPlanLogging, NamedWindowRootView.QueryPlanLog,
                                                   _rootView.EventType.Name, _agentInstanceContext));
        }
コード例 #13
0
        public void Run()
        {
            long currentThreadId = Thread.CurrentThread.ManagedThreadId;

            // Choose one of filter specifications, randomly, then reserve to make sure no one else has the same
            FilterSpecCompiled filterSpec     = null;
            EventBean          unmatchedEvent = null;
            EventBean          matchedEvent   = null;

            var index = 0;

            do
            {
                index          = Random.Next(_testFilterSpecs.Count);
                filterSpec     = _testFilterSpecs[index];
                unmatchedEvent = _unmatchedEvents[index];
                matchedEvent   = _matchedEvents[index];
            }while(!ObjectReservationSingleton.Instance.Reserve(filterSpec));

            // Add expression
            var          filterValues   = filterSpec.GetValueSet(null, null, null);
            FilterHandle filterCallback = new SupportFilterHandle();
            var          pathAddedTo    = IndexTreeBuilder.Add(filterValues, filterCallback, _topNode, _lockFactory);

            // Fire a no-match
            IList <FilterHandle> matches = new List <FilterHandle>();

            _topNode.MatchEvent(unmatchedEvent, matches);

            if (matches.Count != 0)
            {
                Log.Fatal(".run (" + currentThreadId + ") Got a match but expected no-match, matchCount=" + matches.Count + "  bean=" + unmatchedEvent +
                          "  match=" + matches[0].GetHashCode());
                Assert.IsFalse(true);
            }

            // Fire a match
            _topNode.MatchEvent(matchedEvent, matches);

            if (matches.Count != 1)
            {
                Log.Fatal(".run (" + currentThreadId + ") Got zero or two or more match but expected a match, count=" + matches.Count +
                          "  bean=" + matchedEvent);
                Assert.IsFalse(true);
            }

            // Remove the same expression again
            IndexTreeBuilder.Remove(_eventType, filterCallback, pathAddedTo[0].ToArray(), _topNode);
            Log.Debug(".run (" + Thread.CurrentThread.ManagedThreadId + ")" + " Completed");

            ObjectReservationSingleton.Instance.Unreserve(filterSpec);
        }
コード例 #14
0
 public ViewableActivatorFilterForge(
     FilterSpecCompiled filterSpecCompiled,
     bool canIterate,
     int? streamNumFromClause,
     bool isSubSelect,
     int subselectNumber)
 {
     this.filterSpecCompiled = filterSpecCompiled;
     this.canIterate = canIterate;
     this.streamNumFromClause = streamNumFromClause;
     this.isSubSelect = isSubSelect;
     this.subselectNumber = subselectNumber;
 }
コード例 #15
0
ファイル: BaseSubscription.cs プロジェクト: ecakirman/nesper
        /// <summary>Register an adapter. </summary>
        /// <param name="epService">engine</param>
        public void RegisterAdapter(EPServiceProvider epService)
        {
            var spi       = (EPServiceProviderSPI)epService;
            var eventType = spi.EventAdapterService.GetEventTypeByName(EventTypeName);
            var fvs       = new FilterSpecCompiled(eventType, null, new IList <FilterSpecParam> [0], null).GetValueSet(null, null, null);

            var name            = "subscription:" + SubscriptionName;
            var metricsHandle   = spi.MetricReportingService.GetStatementHandle(name, name);
            var statementHandle = new EPStatementHandle(name, name, name, StatementType.ESPERIO, name, false, metricsHandle, 0, false, false, MultiMatchHandlerFactory.DefaultHandler);
            var agentHandle     = new EPStatementAgentInstanceHandle(statementHandle, ReaderWriterLockManager.CreateDefaultLock(), -1, new StatementAgentInstanceFilterVersion());
            var registerHandle  = new EPStatementHandleCallback(agentHandle, this);

            spi.FilterService.Add(fvs, registerHandle);
        }
コード例 #16
0
        public DataFlowOpForgeInitializeResult InitializeForge(DataFlowOpForgeInitializeContext context)
        {
            if (context.OutputPorts.Count != 1) {
                throw new ArgumentException(
                    "EventBusSource operator requires one output stream but produces " +
                    context.OutputPorts.Count +
                    " streams");
            }

            var portZero = context.OutputPorts[0];
            if (portZero.OptionalDeclaredType == null || portZero.OptionalDeclaredType.EventType == null) {
                throw new ArgumentException(
                    "EventBusSource operator requires an event type declated for the output stream");
            }

            var eventType = portZero.OptionalDeclaredType.EventType;
            if (!portZero.OptionalDeclaredType.IsUnderlying) {
                submitEventBean = true;
            }

            DataFlowParameterValidation.Validate("filter", filter, eventType, typeof(bool), context);

            try {
                IList<ExprNode> filters = EmptyList<ExprNode>.Instance;
                if (filter != null) {
                    filters = Collections.SingletonList(filter);
                }

                var streamTypeService = new StreamTypeServiceImpl(eventType, eventType.Name, true);
                var compiledDesc = FilterSpecCompiler.MakeFilterSpec(
                    eventType,
                    eventType.Name,
                    filters,
                    null,
                    null,
                    null,
                    null,
                    streamTypeService,
                    null,
                    context.StatementRawInfo,
                    context.Services);
                FilterSpecCompiled = compiledDesc.FilterSpecCompiled;
            }
            catch (ExprValidationException ex) {
                throw new ExprValidationException("Failed to obtain filter parameters: " + ex.Message, ex);
            }

            return null;
        }
コード例 #17
0
        public static FilterValueSetParam[][] GetAddendumFilters(
            FilterSpecCompiled filterSpecCompiled,
            int hashCode,
            ContextDetailHash hashSpec,
            ContextControllerStatementDesc statementDesc)
        {
            // determine whether create-named-window
            var isCreateWindow = statementDesc != null && statementDesc.Statement.StatementSpec.CreateWindowDesc != null;
            ContextDetailHashItem foundPartition = null;

            if (!isCreateWindow)
            {
                foundPartition = FindHashItemSpec(hashSpec, filterSpecCompiled);
            }
            else
            {
                string declaredAsName = statementDesc.Statement.StatementSpec.CreateWindowDesc.AsEventTypeName;
                foreach (var partitionItem in hashSpec.Items)
                {
                    if (partitionItem.FilterSpecCompiled.FilterForEventType.Name.Equals(declaredAsName))
                    {
                        foundPartition = partitionItem;
                        break;
                    }
                }
            }

            if (foundPartition == null)
            {
                return(null);
            }

            var filter = new FilterValueSetParamImpl(foundPartition.Lookupable, FilterOperator.EQUAL, hashCode);

            var addendum = new FilterValueSetParam[1][];

            addendum[0] = new FilterValueSetParam[]
            {
                filter
            };

            var partitionFilters = foundPartition.ParametersCompiled;

            if (partitionFilters != null)
            {
                addendum = ContextControllerAddendumUtil.AddAddendum(partitionFilters, filter);
            }
            return(addendum);
        }
コード例 #18
0
 public static void AssignFilterSpecIds(FilterSpecCompiled filterSpec, FilterSpecCompiled[] filterSpecsAll)
 {
     for (int path = 0; path < filterSpec.Parameters.Length; path++)
     {
         foreach (FilterSpecParam param in filterSpec.Parameters[path])
         {
             if (param is FilterSpecParamExprNode)
             {
                 var index    = filterSpec.GetFilterSpecIndexAmongAll(filterSpecsAll);
                 var exprNode = (FilterSpecParamExprNode)param;
                 exprNode.FilterSpecId           = index;
                 exprNode.FilterSpecParamPathNum = path;
             }
         }
     }
 }
コード例 #19
0
        public ICollection <EventBean> SnapshotNoLockWithFilter(FilterSpecCompiled filter, Attribute[] annotations, ExprNode filterExpr, ExprEvaluatorContext exprEvaluatorContext)
        {
            if (_tailView.RevisionProcessor != null)
            {
                return(_tailView.RevisionProcessor.GetSnapshot(_agentInstanceContext.EpStatementAgentInstanceHandle, Parent));
            }

            var indexedResult = _rootViewInstance.Snapshot(filter, annotations);

            if (indexedResult != null)
            {
                if (indexedResult.IsEmpty())
                {
                    return(indexedResult);
                }
                if (filterExpr == null)
                {
                    return(indexedResult);
                }
                var deque = new ArrayDeque <EventBean>(Math.Min(indexedResult.Count, 16));
                ExprNodeUtility.ApplyFilterExpressionIterable(indexedResult.GetEnumerator(), filterExpr.ExprEvaluator, exprEvaluatorContext, deque);
                return(deque);
            }

            // fall back to window operator if snapshot doesn't resolve successfully
            var en = Parent.GetEnumerator();

            if (!en.MoveNext())
            {
                return(Collections.GetEmptyList <EventBean>());
            }
            var list = new ArrayDeque <EventBean>();

            if (filterExpr != null)
            {
                en = Parent.GetEnumerator();
                ExprNodeUtility.ApplyFilterExpressionIterable(en, filterExpr.ExprEvaluator, _agentInstanceContext, list);
            }
            else
            {
                do
                {
                    list.Add(en.Current);
                } while (en.MoveNext());
            }
            return(list);
        }
コード例 #20
0
        /// <summary>
        /// Returns a snapshot of window contents, thread-safely
        /// </summary>
        /// <param name="filter">filters if any</param>
        /// <param name="annotations">The annotations.</param>
        /// <returns>
        /// window contents
        /// </returns>
        public ICollection <EventBean> Snapshot(FilterSpecCompiled filter, Attribute[] annotations)
        {
            if (_tailView.RevisionProcessor != null)
            {
                return(_tailView.RevisionProcessor.GetSnapshot(_agentInstanceContext.EpStatementAgentInstanceHandle, Parent));
            }

            using (_agentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock.AcquireReadLock())
            {
                try
                {
                    return(SnapshotNoLock(filter, annotations));
                }
                finally
                {
                    ReleaseTableLocks(_agentInstanceContext);
                }
            }
        }
コード例 #21
0
        public CodegenExpression MakeCodegen(
            CodegenMethodScope parent,
            SAIFFInitializeSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(ContextControllerDetailHashItem), GetType(), classScope);
            method.Block.DeclareVar<EventType>(
                "eventType",
                EventTypeUtility.ResolveTypeCodegen(
                    FilterSpecCompiled.FilterForEventType,
                    symbols.GetAddInitSvc(method)));

            var symbolsWithType = new SAIFFInitializeSymbolWEventType();
            var methodLookupableMake = parent.MakeChildWithScope(
                    typeof(ExprFilterSpecLookupable),
                    GetType(),
                    symbolsWithType,
                    classScope)
                .AddParam(typeof(EventType), "eventType")
                .AddParam(typeof(EPStatementInitServices), SAIFFInitializeSymbol.REF_STMTINITSVC.Ref);
            var methodLookupable = Lookupable.MakeCodegen(methodLookupableMake, symbolsWithType, classScope);
            methodLookupableMake.Block.MethodReturn(LocalMethod(methodLookupable));

            method.Block
                .DeclareVar<ContextControllerDetailHashItem>(
                    "item",
                    NewInstance(typeof(ContextControllerDetailHashItem)))
                .DeclareVar<ExprFilterSpecLookupable>(
                    "lookupable",
                    LocalMethod(methodLookupableMake, Ref("eventType"), symbols.GetAddInitSvc(method)))
                .SetProperty(
                    Ref("item"),
                    "FilterSpecActivatable",
                    LocalMethod(FilterSpecCompiled.MakeCodegen(method, symbols, classScope)))
                .SetProperty(Ref("item"), "Lookupable", Ref("lookupable"))
                .Expression(
                    ExprDotMethodChain(symbols.GetAddInitSvc(method))
                        .Get(EPStatementInitServicesConstants.FILTERSHAREDLOOKUPABLEREGISTERY)
                        .Add("RegisterLookupable", Ref("eventType"), Ref("lookupable")))
                .MethodReturn(Ref("item"));

            return LocalMethod(method);
        }
コード例 #22
0
        private static void AddAddendums(
            IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> addendums,
            FilterSpecCompiled filtersSpec,
            ContextDetailCategoryItem category,
            ContextDetailCategory categorySpec)
        {
            FilterValueSetParam[][] categoryEventFilters = categorySpec.FilterParamsCompiled;
            FilterValueSetParam[][] categoryItemFilters  = category.CompiledFilterParam;

            FilterValueSetParam[][] addendum = ContextControllerAddendumUtil.MultiplyAddendum(categoryEventFilters, categoryItemFilters);

            FilterValueSetParam[][] existingFilters = addendums.Get(filtersSpec);
            if (existingFilters != null)
            {
                addendum = ContextControllerAddendumUtil.MultiplyAddendum(existingFilters, addendum);
            }

            addendums[filtersSpec] = addendum;
        }
コード例 #23
0
 public EventBean[] SnapshotDelete(FilterSpecCompiled filter, ExprNode filterExpr, Attribute[] annotations)
 {
     using (_agentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock.AcquireReadLock())
     {
         try
         {
             var events = SnapshotNoLockWithFilter(filter, annotations, filterExpr, _agentInstanceContext);
             if (events.IsEmpty())
             {
                 return(CollectionUtil.EVENTBEANARRAY_EMPTY);
             }
             var eventsDeleted = events.ToArray();
             _rootViewInstance.Update(null, eventsDeleted);
             return(eventsDeleted);
         }
         finally
         {
             ReleaseTableLocks(_agentInstanceContext);
         }
     }
 }
コード例 #24
0
        public ViewableActivator CreateFilterProxy(
            EPServicesContext services,
            FilterSpecCompiled filterSpec,
            Attribute[] annotations,
            bool subselect,
            InstrumentationAgent instrumentationAgentSubquery,
            bool isCanIterate)
        {
            if (ProcCreateActivatorProxy == null)
            {
                throw new NotSupportedException();
            }

            return(ProcCreateActivatorProxy.Invoke(
                       services,
                       filterSpec,
                       annotations,
                       subselect,
                       instrumentationAgentSubquery,
                       isCanIterate));
        }
コード例 #25
0
        private ICollection <EventBean> SnapshotAndApplyFilter(FilterSpecCompiled filter, Attribute[] annotations, ExprNode filterExpr, AgentInstanceContext agentInstanceContext)
        {
            var indexedResult = SnapshotNullWhenNoIndex(filter, annotations, null, null);

            if (indexedResult != null)
            {
                if (indexedResult.IsEmpty() || filterExpr == null)
                {
                    return(indexedResult);
                }
                var dequeX = new ArrayDeque <EventBean>(Math.Min(indexedResult.Count, 16));
                ExprNodeUtility.ApplyFilterExpressionIterable(indexedResult.GetEnumerator(), filterExpr.ExprEvaluator, agentInstanceContext, dequeX);
                return(dequeX);
            }

            // fall back to window operator if snapshot doesn't resolve successfully
            var sourceCollection = _instance.EventCollection;
            var it = sourceCollection.GetEnumerator();

            if (it.MoveNext() == false)
            {
                return(Collections.GetEmptyList <EventBean>());
            }
            var deque = new ArrayDeque <EventBean>(sourceCollection.Count);

            if (filterExpr != null)
            {
                ExprNodeUtility.ApplyFilterExpressionIterable(sourceCollection.GetEnumerator(), filterExpr.ExprEvaluator, agentInstanceContext, deque);
            }
            else
            {
                do
                {
                    deque.Add(it.Current);
                } while (it.MoveNext());
            }
            return(deque);
        }
コード例 #26
0
        public static FilterValueSetParam[][] GetAddendumFilters(
            object keyValue,
            FilterSpecCompiled filtersSpec,
            ContextDetailPartitioned segmentedSpec,
            StatementSpecCompiled optionalStatementSpecCompiled)
        {
            // determine whether create-named-window
            var isCreateWindow = optionalStatementSpecCompiled != null &&
                                 optionalStatementSpecCompiled.CreateWindowDesc != null;
            ContextDetailPartitionItem foundPartition = null;

            if (!isCreateWindow)
            {
                foreach (var partitionItem in segmentedSpec.Items)
                {
                    var typeOrSubtype = EventTypeUtility.IsTypeOrSubTypeOf(
                        filtersSpec.FilterForEventType, partitionItem.FilterSpecCompiled.FilterForEventType);
                    if (typeOrSubtype)
                    {
                        foundPartition = partitionItem;
                    }
                }
            }
            else
            {
                var declaredAsName = optionalStatementSpecCompiled.CreateWindowDesc.AsEventTypeName;
                if (declaredAsName == null)
                {
                    return(null);
                }
                foreach (var partitionItem in segmentedSpec.Items)
                {
                    if (partitionItem.FilterSpecCompiled.FilterForEventType.Name.Equals(declaredAsName))
                    {
                        foundPartition = partitionItem;
                        break;
                    }
                }
            }

            if (foundPartition == null)
            {
                return(null);
            }

            var addendumFilters = new List <FilterValueSetParam>(foundPartition.PropertyNames.Count);

            if (foundPartition.PropertyNames.Count == 1)
            {
                var propertyName           = foundPartition.PropertyNames[0];
                var getter                 = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(propertyName);
                var resultType             = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(propertyName);
                var lookupable             = new FilterSpecLookupable(propertyName, getter, resultType, false);
                FilterValueSetParam filter = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keyValue);
                addendumFilters.Add(filter);
            }
            else
            {
                var keys = ((MultiKeyUntyped)keyValue).Keys;
                for (var i = 0; i < foundPartition.PropertyNames.Count; i++)
                {
                    var partitionPropertyName = foundPartition.PropertyNames[i];
                    var getter                 = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(partitionPropertyName);
                    var resultType             = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(partitionPropertyName);
                    var lookupable             = new FilterSpecLookupable(partitionPropertyName, getter, resultType, false);
                    FilterValueSetParam filter = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keys[i]);
                    addendumFilters.Add(filter);
                }
            }

            var addendum = new FilterValueSetParam[1][];

            addendum[0] = addendumFilters.ToArray();

            var partitionFilters = foundPartition.ParametersCompiled;

            if (partitionFilters != null)
            {
                addendum = ContextControllerAddendumUtil.AddAddendum(partitionFilters, addendum[0]);
            }

            return(addendum);
        }
コード例 #27
0
 public FilterValueSetParam[][] GetFilterAddendum(FilterSpecCompiled filterSpecCompiled)
 {
     return(_filterAddendum.Get(filterSpecCompiled));
 }
コード例 #28
0
        protected override StatementAgentInstanceFactoryResult NewContextInternal(AgentInstanceContext agentInstanceContext, bool isRecoveringResilient)
        {
            IList <StopCallback> stopCallbacks = new List <StopCallback>(2);

            Viewable finalView;
            var      viewableActivationResult = new ViewableActivationResult[_eventStreamParentViewableActivators.Length];
            IDictionary <ExprSubselectNode, SubSelectStrategyHolder> subselectStrategies;
            AggregationService aggregationService;

            Viewable[] streamViews;
            Viewable[] eventStreamParentViewable;
            Viewable[] topViews;
            IDictionary <ExprPriorNode, ExprPriorEvalStrategy>             priorNodeStrategies;
            IDictionary <ExprPreviousNode, ExprPreviousEvalStrategy>       previousNodeStrategies;
            IDictionary <ExprTableAccessNode, ExprTableAccessEvalStrategy> tableAccessStrategies;
            RegexExprPreviousEvalStrategy         regexExprPreviousEvalStrategy = null;
            IList <StatementAgentInstancePreload> preloadList = new List <StatementAgentInstancePreload>();

            EvalRootState[] patternRoots;
            StatementAgentInstancePostLoad postLoadJoin = null;
            var suppressSameEventMatches = false;
            var discardPartialsOnMatch   = false;
            EvalRootMatchRemover evalRootMatchRemover = null;

            try {
                // create root viewables
                eventStreamParentViewable = new Viewable[_numStreams];
                patternRoots = new EvalRootState[_numStreams];

                for (var stream = 0; stream < _eventStreamParentViewableActivators.Length; stream++)
                {
                    var activationResult = _eventStreamParentViewableActivators[stream].Activate(agentInstanceContext, false, isRecoveringResilient);
                    viewableActivationResult[stream] = activationResult;
                    stopCallbacks.Add(activationResult.StopCallback);
                    suppressSameEventMatches = activationResult.IsSuppressSameEventMatches;
                    discardPartialsOnMatch   = activationResult.IsDiscardPartialsOnMatch;

                    // add stop callback for any stream-level viewable when applicable
                    if (activationResult.Viewable is StopCallback)
                    {
                        stopCallbacks.Add((StopCallback)activationResult.Viewable);
                    }

                    eventStreamParentViewable[stream] = activationResult.Viewable;
                    patternRoots[stream] = activationResult.OptionalPatternRoot;
                    if (stream == 0)
                    {
                        evalRootMatchRemover = activationResult.OptEvalRootMatchRemover;
                    }

                    if (activationResult.OptionalLock != null)
                    {
                        agentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock = activationResult.OptionalLock;
                        _statementContext.DefaultAgentInstanceLock = activationResult.OptionalLock;
                    }
                }

                // compile view factories adding "prior" as necessary
                var viewFactoryChains = new IList <ViewFactory> [_numStreams];
                for (var i = 0; i < _numStreams; i++)
                {
                    var viewFactoryChain = _unmaterializedViewChain[i].FactoryChain;

                    // add "prior" view factory
                    var hasPrior = _viewResourceDelegate.PerStream[i].PriorRequests != null && !_viewResourceDelegate.PerStream[i].PriorRequests.IsEmpty();
                    if (hasPrior)
                    {
                        var priorEventViewFactory = EPStatementStartMethodHelperPrior.GetPriorEventViewFactory(
                            agentInstanceContext.StatementContext, i, viewFactoryChain.IsEmpty(), false, -1);
                        viewFactoryChain = new List <ViewFactory>(viewFactoryChain);
                        viewFactoryChain.Add(priorEventViewFactory);
                    }
                    viewFactoryChains[i] = viewFactoryChain;
                }

                // create view factory chain context: holds stream-specific services
                var viewFactoryChainContexts = new AgentInstanceViewFactoryChainContext[_numStreams];
                for (var i = 0; i < _numStreams; i++)
                {
                    viewFactoryChainContexts[i] = AgentInstanceViewFactoryChainContext.Create(viewFactoryChains[i], agentInstanceContext, _viewResourceDelegate.PerStream[i]);
                }

                // handle "prior" nodes and their strategies
                priorNodeStrategies = EPStatementStartMethodHelperPrior.CompilePriorNodeStrategies(_viewResourceDelegate, viewFactoryChainContexts);

                // handle "previous" nodes and their strategies
                previousNodeStrategies = EPStatementStartMethodHelperPrevious.CompilePreviousNodeStrategies(_viewResourceDelegate, viewFactoryChainContexts);

                // materialize views
                streamViews = new Viewable[_numStreams];
                topViews    = new Viewable[_numStreams];
                for (var i = 0; i < _numStreams; i++)
                {
                    var hasPreviousNode = _viewResourceDelegate.PerStream[i].PreviousRequests != null && !_viewResourceDelegate.PerStream[i].PreviousRequests.IsEmpty();

                    var createResult = _services.ViewService.CreateViews(eventStreamParentViewable[i], viewFactoryChains[i], viewFactoryChainContexts[i], hasPreviousNode);
                    topViews[i]    = createResult.TopViewable;
                    streamViews[i] = createResult.FinalViewable;

                    var isReuseableView = _eventStreamParentViewableActivators[i] is ViewableActivatorStreamReuseView;
                    if (isReuseableView)
                    {
                        var viewsCreated = createResult.NewViews;
                        var stopCallback = new ProxyStopCallback(() => {
                            ViewServiceHelper.RemoveFirstUnsharedView(viewsCreated);
                        });
                        stopCallbacks.Add(stopCallback);
                    }

                    // add views to stop callback if applicable
                    AddViewStopCallback(stopCallbacks, createResult.NewViews);
                }

                // determine match-recognize "previous"-node strategy (none if not present, or one handling and number of nodes)
                var matchRecognize = EventRowRegexHelper.RecursiveFindRegexService(topViews[0]);
                if (matchRecognize != null)
                {
                    regexExprPreviousEvalStrategy = matchRecognize.PreviousEvaluationStrategy;
                    stopCallbacks.Add(new ProxyStopCallback(matchRecognize.Stop));
                }

                // start subselects
                subselectStrategies = EPStatementStartMethodHelperSubselect.StartSubselects(_services, _subSelectStrategyCollection, agentInstanceContext, stopCallbacks, isRecoveringResilient);

                // plan table access
                tableAccessStrategies = EPStatementStartMethodHelperTableAccess.AttachTableAccess(_services, agentInstanceContext, _statementSpec.TableNodes);

                // obtain result set processor and aggregation services
                var processorPair      = EPStatementStartMethodHelperUtil.StartResultSetAndAggregation(_resultSetProcessorFactoryDesc, agentInstanceContext, false, null);
                var resultSetProcessor = processorPair.First;
                aggregationService = processorPair.Second;
                stopCallbacks.Add(aggregationService);
                stopCallbacks.Add(resultSetProcessor);

                // for just 1 event stream without joins, handle the one-table process separately.
                JoinPreloadMethod   joinPreloadMethod;
                JoinSetComposerDesc joinSetComposer = null;
                if (streamViews.Length == 1)
                {
                    finalView         = HandleSimpleSelect(streamViews[0], resultSetProcessor, agentInstanceContext, evalRootMatchRemover, suppressSameEventMatches, discardPartialsOnMatch);
                    joinPreloadMethod = null;
                }
                else
                {
                    var joinPlanResult = HandleJoin(_typeService.StreamNames, streamViews, resultSetProcessor,
                                                    agentInstanceContext, stopCallbacks, _joinAnalysisResult, isRecoveringResilient);
                    finalView         = joinPlanResult.Viewable;
                    joinPreloadMethod = joinPlanResult.PreloadMethod;
                    joinSetComposer   = joinPlanResult.JoinSetComposerDesc;
                }

                // for stoppable final views, add callback
                if (finalView is StopCallback)
                {
                    stopCallbacks.Add((StopCallback)finalView);
                }

                // Replay any named window data, for later consumers of named data windows
                if (_services.EventTableIndexService.AllowInitIndex(isRecoveringResilient))
                {
                    var hasNamedWindow             = false;
                    var namedWindowPostloadFilters = new FilterSpecCompiled[_statementSpec.StreamSpecs.Length];
                    var namedWindowTailViews       = new NamedWindowTailViewInstance[_statementSpec.StreamSpecs.Length];
                    var namedWindowFilters         = new IList <ExprNode> [_statementSpec.StreamSpecs.Length];

                    for (var i = 0; i < _statementSpec.StreamSpecs.Length; i++)
                    {
                        var streamNum  = i;
                        var streamSpec = _statementSpec.StreamSpecs[i];

                        if (streamSpec is NamedWindowConsumerStreamSpec)
                        {
                            hasNamedWindow = true;
                            var namedSpec = (NamedWindowConsumerStreamSpec)streamSpec;
                            NamedWindowProcessor processor = _services.NamedWindowMgmtService.GetProcessor(namedSpec.WindowName);
                            var processorInstance          = processor.GetProcessorInstance(agentInstanceContext);
                            if (processorInstance != null)
                            {
                                var consumerView = processorInstance.TailViewInstance;
                                namedWindowTailViews[i] = consumerView;
                                var view = (NamedWindowConsumerView)viewableActivationResult[i].Viewable;

                                // determine preload/postload filter for index access
                                if (!namedSpec.FilterExpressions.IsEmpty())
                                {
                                    namedWindowFilters[streamNum] = namedSpec.FilterExpressions;
                                    try {
                                        var streamName = streamSpec.OptionalStreamName != null ? streamSpec.OptionalStreamName : consumerView.EventType.Name;
                                        var types      = new StreamTypeServiceImpl(consumerView.EventType, streamName, false, _services.EngineURI);
                                        var tagged     = new LinkedHashMap <string, Pair <EventType, string> >();
                                        namedWindowPostloadFilters[i] = FilterSpecCompiler.MakeFilterSpec(types.EventTypes[0], types.StreamNames[0],
                                                                                                          namedSpec.FilterExpressions, null, tagged, tagged, types, null, _statementContext, Collections.SingletonSet(0));
                                    }
                                    catch (Exception ex) {
                                        Log.Warn("Unexpected exception analyzing filter paths: " + ex.Message, ex);
                                    }
                                }

                                // preload view for stream unless the expiry policy is batch window
                                var preload = !consumerView.TailView.IsParentBatchWindow && consumerView.HasFirst();
                                if (preload)
                                {
                                    if (isRecoveringResilient && _numStreams < 2)
                                    {
                                        preload = false;
                                    }
                                }
                                if (preload)
                                {
                                    var yesRecoveringResilient = isRecoveringResilient;
                                    var preloadFilterSpec      = namedWindowPostloadFilters[i];
                                    preloadList.Add(new ProxyStatementAgentInstancePreload()
                                    {
                                        ProcExecutePreload = () => {
                                            var snapshot       = consumerView.Snapshot(preloadFilterSpec, _statementContext.Annotations);
                                            var eventsInWindow = new List <EventBean>(snapshot.Count);
                                            ExprNodeUtility.ApplyFilterExpressionsIterable(snapshot, namedSpec.FilterExpressions, agentInstanceContext, eventsInWindow);
                                            EventBean[] newEvents = eventsInWindow.ToArray();
                                            view.Update(newEvents, null);
                                            if (!yesRecoveringResilient && joinPreloadMethod != null && !joinPreloadMethod.IsPreloading && agentInstanceContext.EpStatementAgentInstanceHandle.OptionalDispatchable != null)
                                            {
                                                agentInstanceContext.EpStatementAgentInstanceHandle.OptionalDispatchable.Execute();
                                            }
                                        },
                                    });
                                }
                            }
                            else
                            {
                                Log.Info("Named window access is out-of-context, the named window '" + namedSpec.WindowName + "' has been declared for a different context then the current statement, the aggregation and join state will not be initialized for statement expression [" + _statementContext.Expression + "]");
                            }

                            preloadList.Add(new ProxyStatementAgentInstancePreload()
                            {
                                ProcExecutePreload = () => {
                                    // in a join, preload indexes, if any
                                    if (joinPreloadMethod != null)
                                    {
                                        joinPreloadMethod.PreloadFromBuffer(streamNum);
                                    }
                                    else
                                    {
                                        if (agentInstanceContext.EpStatementAgentInstanceHandle.OptionalDispatchable != null)
                                        {
                                            agentInstanceContext.EpStatementAgentInstanceHandle.OptionalDispatchable.Execute();
                                        }
                                    }
                                },
                            });
                        }
                    }

                    // last, for aggregation we need to send the current join results to the result set processor
                    if ((hasNamedWindow) && (joinPreloadMethod != null) && (!isRecoveringResilient) && _resultSetProcessorFactoryDesc.ResultSetProcessorFactory.HasAggregation)
                    {
                        preloadList.Add(new ProxyStatementAgentInstancePreload()
                        {
                            ProcExecutePreload = () => {
                                joinPreloadMethod.PreloadAggregation(resultSetProcessor);
                            },
                        });
                    }

                    if (isRecoveringResilient)
                    {
                        postLoadJoin = new StatementAgentInstancePostLoadSelect(streamViews, joinSetComposer, namedWindowTailViews, namedWindowPostloadFilters, namedWindowFilters, _statementContext.Annotations, agentInstanceContext);
                    }
                    else if (joinSetComposer != null)
                    {
                        postLoadJoin = new StatementAgentInstancePostLoadIndexVisiting(joinSetComposer.JoinSetComposer);
                    }
                }
            }
            catch (Exception) {
                var stopCallback = StatementAgentInstanceUtil.GetStopCallback(stopCallbacks, agentInstanceContext);
                StatementAgentInstanceUtil.StopSafe(stopCallback, _statementContext);
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().AContextPartitionAllocate();
                }
                throw;
            }

            var selectResult = new StatementAgentInstanceFactorySelectResult(finalView, null, agentInstanceContext, aggregationService, subselectStrategies, priorNodeStrategies, previousNodeStrategies, regexExprPreviousEvalStrategy, tableAccessStrategies, preloadList, patternRoots, postLoadJoin, topViews, eventStreamParentViewable, viewableActivationResult);

            if (_statementContext.StatementExtensionServicesContext != null)
            {
                _statementContext.StatementExtensionServicesContext.ContributeStopCallback(selectResult, stopCallbacks);
            }
            var stopCallbackX = StatementAgentInstanceUtil.GetStopCallback(stopCallbacks, agentInstanceContext);

            selectResult.StopCallback = stopCallbackX;

            return(selectResult);
        }
コード例 #29
0
 public FilterValueSetParam[][] GetAddendumFilters(FilterSpecCompiled filterSpec)
 {
     return(_addendumMap.Get(filterSpec));
 }
コード例 #30
0
        public static ContextDetailHashItem FindHashItemSpec(ContextDetailHash hashSpec, FilterSpecCompiled filterSpec)
        {
            ContextDetailHashItem foundPartition = null;

            foreach (var partitionItem in hashSpec.Items)
            {
                var typeOrSubtype = EventTypeUtility.IsTypeOrSubTypeOf(filterSpec.FilterForEventType, partitionItem.FilterSpecCompiled.FilterForEventType);
                if (typeOrSubtype)
                {
                    foundPartition = partitionItem;
                }
            }

            return(foundPartition);
        }