Exemple #1
0
        /// <summary>
        /// Add a filter callback according to the filter specification to the top node returning information to be used to remove the filter callback.
        /// </summary>
        /// <param name="filterValueSet">is the filter definition</param>
        /// <param name="filterCallback">is the callback to be added</param>
        /// <param name="topNode">node to be added to any subnode beneath it</param>
        /// <param name="lockFactory">The lock factory.</param>
        /// <returns>
        /// an encapsulation of information need to allow for safe removal of the filter tree.
        /// </returns>
        public static ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>[] Add(
            FilterValueSet filterValueSet,
            FilterHandle filterCallback,
            FilterHandleSetNode topNode,
            FilterServiceGranularLockFactory lockFactory)
        {
            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".add (" + Thread.CurrentThread.ManagedThreadId + ") Adding filter callback, " +
                          "  topNode=" + topNode +
                          "  filterCallback=" + filterCallback);
            }

            ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>[] treePathInfo;
            if (filterValueSet.Parameters.Length == 0)
            {
                treePathInfo    = AllocateTreePath(1);
                treePathInfo[0] = new ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>(1);
                AddToNode(new ArrayDeque <FilterValueSetParam>(1), filterCallback, topNode, treePathInfo[0], lockFactory);
            }
            else
            {
                treePathInfo = AllocateTreePath(filterValueSet.Parameters.Length);
                var remainingParameters = new ArrayDeque <FilterValueSetParam>(4);
                for (int i = 0; i < filterValueSet.Parameters.Length; i++)
                {
                    treePathInfo[i] = new ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>(filterValueSet.Parameters[i].Length);
                    remainingParameters.Clear();
                    remainingParameters.AddAll(filterValueSet.Parameters[i]);
                    AddToNode(remainingParameters, filterCallback, topNode, treePathInfo[i], lockFactory);
                }
            }

            return(treePathInfo);
        }
Exemple #2
0
        /// <summary>
        ///     NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="sort">sorted</param>
        /// <param name="hasColl">collection flag</param>
        /// <param name="descending">true for descending</param>
        /// <returns>collection</returns>
        public static ICollection<object> EnumOrderBySortEval(
            OrderedDictionary<object, object> sort,
            bool hasColl,
            bool descending)
        {
            IDictionary<object, object> sorted;
            if (descending) {
                sorted = sort.Invert();
            }
            else {
                sorted = sort;
            }

            if (!hasColl) {
                return sorted.Values;
            }

            Deque<object> coll = new ArrayDeque<object>();
            foreach (var entry in sorted) {
                if (entry.Value.GetType().IsGenericCollection()) {
                    coll.AddAll(entry.Value.Unwrap<object>());
                }
                else {
                    coll.Add(entry.Value);
                }
            }

            return coll;
        }
        /// <summary>
        ///     Add a filter callback according to the filter specification to the top node returning
        ///     information to be used to remove the filter callback.
        /// </summary>
        /// <param name="valueSet">is the filter definition</param>
        /// <param name="filterCallback">is the callback to be added</param>
        /// <param name="topNode">node to be added to any subnode beneath it</param>
        /// <param name="lockFactory">lock factory</param>
        public static void Add(
            FilterValueSetParam[][] valueSet,
            FilterHandle filterCallback,
            FilterHandleSetNode topNode,
            FilterServiceGranularLockFactory lockFactory)
        {
            if (ExecutionPathDebugLog.IsDebugEnabled && log.IsDebugEnabled) {
                log.Debug(
                    ".add (" + Thread.CurrentThread.ManagedThreadId + ") Adding filter callback, " +
                    "  topNode=" + topNode +
                    "  filterCallback=" + filterCallback);
            }

            if (valueSet.Length == 0) {
                AddToNode(new ArrayDeque<FilterValueSetParam>(1), filterCallback, topNode, lockFactory);
            }
            else {
                var remainingParameters = new ArrayDeque<FilterValueSetParam>();
                for (var i = 0; i < valueSet.Length; i++) {
                    remainingParameters.Clear();
                    remainingParameters.AddAll(valueSet[i]);
                    AddToNode(remainingParameters, filterCallback, topNode, lockFactory);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Return and remove events in time-slots earlier (less) then the timestamp passed in, returning the list of events expired.
        /// </summary>
        /// <param name="expireBefore">is the timestamp from which on to keep events in the window</param>
        /// <returns>
        /// a list of events expired and removed from the window, or null if none expired
        /// </returns>
        public ArrayDeque <EventBean> ExpireEvents(long expireBefore)
        {
            if (_window.IsEmpty())
            {
                return(null);
            }

            var pair = _window.First;

            // If the first entry's timestamp is after the expiry date, nothing to expire
            if (pair.Timestamp >= expireBefore)
            {
                return(null);
            }

            var resultBeans = new ArrayDeque <EventBean>();

            // Repeat until the window is empty or the timestamp is above the expiry time
            do
            {
                if (pair.EventHolder != null)
                {
                    if (pair.EventHolder is EventBean)
                    {
                        resultBeans.Add((EventBean)pair.EventHolder);
                    }
                    else
                    {
                        resultBeans.AddAll((IList <EventBean>)pair.EventHolder);
                    }
                }

                _window.RemoveFirst();

                if (_window.IsEmpty())
                {
                    break;
                }

                pair = _window.First;
            } while (pair.Timestamp < expireBefore);

            if (_reverseIndex != null)
            {
                foreach (var expired in resultBeans)
                {
                    _reverseIndex.Remove(expired);
                }
            }

            _size -= resultBeans.Count;
            return(resultBeans);
        }
        internal static ICollection <EventBean> NormalizeCollection(IDictionary <object, ISet <EventBean> > submapOne, IDictionary <object, ISet <EventBean> > submapTwo)
        {
            if (submapOne.Count == 0)
            {
                return(NormalizeCollection(submapTwo));
            }
            if (submapTwo.Count == 0)
            {
                return(NormalizeCollection(submapOne));
            }
            var result = new ArrayDeque <EventBean>();

            foreach (var entry in submapOne)
            {
                result.AddAll(entry.Value);
            }
            foreach (var entry in submapTwo)
            {
                result.AddAll(entry.Value);
            }
            return(result);
        }
        protected internal static ICollection<EventBean> NormalizeCollection(
            IDictionary<object, ISet<EventBean>> submapOne,
            IDictionary<object, ISet<EventBean>> submapTwo)
        {
            if (submapOne.Count == 0) {
                return NormalizeCollection(submapTwo);
            }

            if (submapTwo.Count == 0) {
                return NormalizeCollection(submapOne);
            }

            ArrayDeque<EventBean> result = new ArrayDeque<EventBean>();
            foreach (KeyValuePair<object, ISet<EventBean>> entry in submapOne) {
                result.AddAll(entry.Value);
            }

            foreach (KeyValuePair<object, ISet<EventBean>> entry in submapTwo) {
                result.AddAll(entry.Value);
            }

            return result;
        }
        public static void CheckedPayloadAddAll(
            ArrayDeque <EventBean> events,
            object value)
        {
            if (value is EventBean)
            {
                events.Add((EventBean)value);
                return;
            }

            var q = (ArrayDeque <EventBean>)value;

            events.AddAll(q);
        }
        protected internal static ICollection<EventBean> NormalizeCollection(
            IDictionary<object, ISet<EventBean>> submap)
        {
            if (submap.Count == 0) {
                return null;
            }

            if (submap.Count == 1) {
                return submap.Get(submap.Keys.First());
            }

            Deque<EventBean> result = new ArrayDeque<EventBean>();
            foreach (KeyValuePair<object, ISet<EventBean>> entry in submap) {
                result.AddAll(entry.Value);
            }

            return result;
        }
        internal static ICollection <EventBean> NormalizeCollection(IDictionary <object, ISet <EventBean> > submap)
        {
            if (submap.Count == 0)
            {
                return(null);
            }
            if (submap.Count == 1)
            {
                return(submap.Get(submap.Keys.First()));
            }
            var result = new ArrayDeque <EventBean>();

            foreach (var entry in submap)
            {
                result.AddAll(entry.Value);
            }
            return(result);
        }
        private ICollection <EventBean> GetStreamFilterSnapshot(int streamNum, ContextPartitionSelector contextPartitionSelector)
        {
            var streamSpec = _statementSpec.StreamSpecs[streamNum];
            IList <ExprNode> filterExpressions = Collections.GetEmptyList <ExprNode>();

            if (streamSpec is NamedWindowConsumerStreamSpec)
            {
                var namedSpec = (NamedWindowConsumerStreamSpec)streamSpec;
                filterExpressions = namedSpec.FilterExpressions;
            }
            else
            {
                var tableSpec = (TableQueryStreamSpec)streamSpec;
                filterExpressions = tableSpec.FilterExpressions;
            }

            var fireAndForgetProcessor = _processors[streamNum];

            // handle the case of a single or matching agent instance
            var processorInstance = fireAndForgetProcessor.GetProcessorInstance(_agentInstanceContext);

            if (processorInstance != null)
            {
                EPPreparedExecuteTableHelper.AssignTableAccessStrategies(_services, _statementSpec.TableNodes, _agentInstanceContext);
                return(GetStreamSnapshotInstance(streamNum, filterExpressions, processorInstance));
            }

            // context partition runtime query
            var contextPartitions = EPPreparedExecuteMethodHelper.GetAgentInstanceIds(fireAndForgetProcessor, contextPartitionSelector, _services.ContextManagementService, fireAndForgetProcessor.ContextName);

            // collect events
            var events = new ArrayDeque <EventBean>();

            foreach (int agentInstanceId in contextPartitions)
            {
                processorInstance = fireAndForgetProcessor.GetProcessorInstanceContextById(agentInstanceId);
                if (processorInstance != null)
                {
                    var coll = processorInstance.SnapshotBestEffort(this, _filters[streamNum], _statementSpec.Annotations);
                    events.AddAll(coll);
                }
            }
            return(events);
        }
Exemple #11
0
        /// <summary>
        /// NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="sort">sorted</param>
        /// <param name="hasColl">collection flag</param>
        /// <param name="descending">true for descending</param>
        /// <returns>collection</returns>
        public static ICollection <T> EnumOrderBySortEval <T>(
            IOrderedDictionary <object, ICollection <T> > sort,
            bool hasColl,
            bool descending)
        {
            IDictionary <object, ICollection <T> > sorted = descending ? sort.Invert() : sort;

            // if (!hasColl) {
            //  return sorted.Values;
            // }

            var coll = new ArrayDeque <T>();

            foreach (var entry in sorted)
            {
                coll.AddAll(entry.Value);
            }

            return(coll);
        }
Exemple #12
0
        protected internal static FilterSpecParamForge[] SortRemoveDups(IList<FilterSpecParamForge> parameters)
        {
            if (parameters.IsEmpty()) {
                return FilterSpecParamForge.EMPTY_PARAM_ARRAY;
            }

            if (parameters.Count == 1) {
                return new FilterSpecParamForge[] {parameters[0]};
            }

            ArrayDeque<FilterSpecParamForge> result = new ArrayDeque<FilterSpecParamForge>();
            OrderedDictionary<FilterOperator, IList<FilterSpecParamForge>> map =
                new OrderedDictionary<FilterOperator, IList<FilterSpecParamForge>>(COMPARATOR_PARAMETERS);
            foreach (var parameter in parameters) {
                var list = map.Get(parameter.FilterOperator);
                if (list == null) {
                    list = new List<FilterSpecParamForge>();
                    map.Put(parameter.FilterOperator, list);
                }

                var hasDuplicate = false;
                foreach (var existing in list) {
                    if (existing.Lookupable.Equals(parameter.Lookupable)) {
                        hasDuplicate = true;
                        break;
                    }
                }

                if (hasDuplicate) {
                    continue;
                }

                list.Add(parameter);
            }

            foreach (KeyValuePair<FilterOperator, IList<FilterSpecParamForge>> entry in map) {
                result.AddAll(entry.Value);
            }

            return result.ToArray();
        }
Exemple #13
0
        public EPPreparedQueryResult Execute(
            FAFQueryMethodSelect select,
            ContextPartitionSelector[] contextPartitionSelectors,
            FAFQueryMethodAssignerSetter assignerSetter,
            ContextManagementService contextManagementService)
        {
            FireAndForgetProcessor processor = select.Processors[0];

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

            ICollection<EventBean> events = new ArrayDeque<EventBean>();
            AgentInstanceContext agentInstanceContext = null;
            foreach (int agentInstanceId in agentInstanceIds) {
                FireAndForgetInstance processorInstance = processor.GetProcessorInstanceContextById(agentInstanceId);
                if (processorInstance != null) {
                    agentInstanceContext = processorInstance.AgentInstanceContext;
                    ICollection<EventBean> coll = processorInstance.SnapshotBestEffort(
                        select.QueryGraph,
                        select.Annotations);
                    events.AddAll(coll);
                }
            }

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

            if (select.WhereClause != null) {
                events = Filtered(events, select.WhereClause, agentInstanceContext);
            }

            return ProcessedNonJoin(resultSetProcessor, events, select.DistinctKeyGetter);
        }
Exemple #14
0
        internal static FilterSpecParam[] SortRemoveDups(IList <FilterSpecParam> parameters)
        {
            if (parameters.IsEmpty())
            {
                return(FilterSpecParam.EMPTY_PARAM_ARRAY);
            }

            if (parameters.Count == 1)
            {
                return(new FilterSpecParam[] { parameters[0] });
            }

            var result = new ArrayDeque <FilterSpecParam>();
            var map    = new SortedDictionary <FilterOperator, List <FilterSpecParam> >(COMPARATOR_PARAMETERS);

            foreach (var parameter in parameters)
            {
                var list = map.Get(parameter.FilterOperator);
                if (list == null)
                {
                    list = new List <FilterSpecParam>();
                    map.Put(parameter.FilterOperator, list);
                }

                var hasDuplicate = list.Any(existing => existing.Lookupable.Equals(parameter.Lookupable));
                if (hasDuplicate)
                {
                    continue;
                }

                list.Add(parameter);
            }

            foreach (var entry in map)
            {
                result.AddAll(entry.Value);
            }
            return(FilterSpecParam.ToArray(result));
        }
        /// <summary>
        /// Executes the prepared query.
        /// </summary>
        /// <returns>query results</returns>
        public EPPreparedQueryResult Execute(ContextPartitionSelector[] contextPartitionSelectors)
        {
            try {
                if (contextPartitionSelectors != null && contextPartitionSelectors.Length != 1)
                {
                    throw new ArgumentException("Number of context partition selectors must be one");
                }
                var optionalSingleSelector = contextPartitionSelectors != null && contextPartitionSelectors.Length > 0 ? contextPartitionSelectors[0] : null;

                // validate context
                if (Processor.ContextName != null &&
                    StatementSpec.OptionalContextName != null &&
                    !Processor.ContextName.Equals(StatementSpec.OptionalContextName))
                {
                    throw new EPException("Context for named window is '" + Processor.ContextName + "' and query specifies context '" + StatementSpec.OptionalContextName + "'");
                }

                // handle non-specified context
                if (StatementSpec.OptionalContextName == null)
                {
                    FireAndForgetInstance processorInstance = Processor.GetProcessorInstanceNoContext();
                    if (processorInstance != null)
                    {
                        var rows = Executor.Execute(processorInstance);
                        if (rows != null && rows.Length > 0)
                        {
                            Dispatch();
                        }
                        return(new EPPreparedQueryResult(Processor.EventTypePublic, rows));
                    }
                }

                // context partition runtime query
                var agentInstanceIds = EPPreparedExecuteMethodHelper.GetAgentInstanceIds(Processor, optionalSingleSelector, Services.ContextManagementService, Processor.ContextName);

                // collect events and agent instances
                if (agentInstanceIds.IsEmpty())
                {
                    return(new EPPreparedQueryResult(Processor.EventTypeResultSetProcessor, CollectionUtil.EVENTBEANARRAY_EMPTY));
                }

                if (agentInstanceIds.Count == 1)
                {
                    int agentInstanceId   = agentInstanceIds.First();
                    var processorInstance = Processor.GetProcessorInstanceContextById(agentInstanceId);
                    var rows = Executor.Execute(processorInstance);
                    if (rows.Length > 0)
                    {
                        Dispatch();
                    }
                    return(new EPPreparedQueryResult(Processor.EventTypeResultSetProcessor, rows));
                }

                var allRows = new ArrayDeque <EventBean>();
                foreach (int agentInstanceId in agentInstanceIds)
                {
                    var processorInstance = Processor.GetProcessorInstanceContextById(agentInstanceId);
                    if (processorInstance != null)
                    {
                        var rows = Executor.Execute(processorInstance);
                        allRows.AddAll(rows);
                    }
                }
                if (allRows.Count > 0)
                {
                    Dispatch();
                }
                return(new EPPreparedQueryResult(Processor.EventTypeResultSetProcessor, allRows.ToArray()));
            }
            finally {
                if (HasTableAccess)
                {
                    Services.TableService.TableExprEvaluatorContext.ReleaseAcquiredLocks();
                }
            }
        }