public static CompositeIndexQuery MakeSubordinate(
            bool isNWOnTrigger,
            int numOuterStreams,
            ExprEvaluator hashEval,
            QueryGraphValueEntryRange[] rangeEvals)
        {
            // construct chain
            IList<CompositeIndexQuery> queries = new List<CompositeIndexQuery>();
            if (hashEval != null) {
                queries.Add(new CompositeIndexQueryKeyed(isNWOnTrigger, -1, numOuterStreams, hashEval));
            }

            foreach (QueryGraphValueEntryRange rangeProp in rangeEvals) {
                queries.Add(new CompositeIndexQueryRange(isNWOnTrigger, -1, numOuterStreams, rangeProp));
            }

            // Hook up as chain for remove
            CompositeIndexQuery last = null;
            foreach (CompositeIndexQuery action in queries) {
                last?.SetNext(action);

                last = action;
            }

            return queries[0];
        }
        public ICollection<EventBean> Lookup(
            EventBean[] eventPerStream,
            IDictionary<object, CompositeIndexEntry> parent,
            ICollection<EventBean> result,
            CompositeIndexQuery next,
            ExprEvaluatorContext context,
            ICollection<object> optionalKeyCollector,
            CompositeIndexQueryResultPostProcessor postProcessor)
        {
            var index = (IOrderedDictionary<object, CompositeIndexEntry>) parent;
            var comparable = base.EvaluatePerStream(eventPerStream, context);
            optionalKeyCollector?.Add(comparable);

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

            return CompositeIndexQueryRange.Handle(
                eventPerStream,
                index.Tail(comparable),
                null,
                result,
                next,
                postProcessor);
        }
        public static CompositeIndexQuery MakeJoinSingleLookupStream(
            bool isNWOnTrigger,
            int lookupStream,
            ExprEvaluator hashGetter,
            QueryGraphValueEntryRange[] rangeProps)
        {
            // construct chain
            IList<CompositeIndexQuery> queries = new List<CompositeIndexQuery>();
            if (hashGetter != null) {
                queries.Add(new CompositeIndexQueryKeyed(false, lookupStream, -1, hashGetter));
            }

            foreach (QueryGraphValueEntryRange rangeProp in rangeProps) {
                queries.Add(new CompositeIndexQueryRange(isNWOnTrigger, lookupStream, -1, rangeProp));
            }

            // Hook up as chain for remove
            CompositeIndexQuery last = null;
            foreach (CompositeIndexQuery action in queries) {
                last?.SetNext(action);

                last = action;
            }

            return queries[0];
        }
Example #4
0
        public ICollection<EventBean> Lookup(
            EventBean[] eventsPerStream,
            IDictionary<object, CompositeIndexEntry> parent,
            ICollection<EventBean> result,
            CompositeIndexQuery next,
            ExprEvaluatorContext context,
            ICollection<object> optionalKeyCollector,
            CompositeIndexQueryResultPostProcessor postProcessor)
        {
            var comparableStart = EvaluatePerStreamStart(eventsPerStream, context);
            optionalKeyCollector?.Add(comparableStart);

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

            var comparableEnd = EvaluatePerStreamEnd(eventsPerStream, context);
            optionalKeyCollector?.Add(comparableEnd);

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

            var index = (IOrderedDictionary<object, CompositeIndexEntry>) parent;
            var submapOne = index.Head(comparableStart, !includeStart);
            var submapTwo = index.Tail(comparableEnd, !includeEnd);
            return CompositeIndexQueryRange.Handle(eventsPerStream, submapOne, submapTwo, result, next, postProcessor);
        }
Example #5
0
 public CompositeTableLookupStrategy(
     EventType eventType,
     int lookupStream,
     ExprEvaluator hashKeys,
     QueryGraphValueEntryRange[] rangeKeyPairs,
     PropertyCompositeEventTable index)
 {
     this._eventType = eventType;
     this._index = index;
     _chain = CompositeIndexQueryFactory.MakeJoinSingleLookupStream(false, lookupStream, hashKeys, rangeKeyPairs);
 }
Example #6
0
 public SubordCompositeTableLookupStrategyFactory(
     bool isNWOnTrigger,
     int numStreams,
     string[] expressions,
     ExprEvaluator hashEval,
     QueryGraphValueEntryRange[] rangeEvals)
 {
     _expressions = expressions;
     InnerIndexQuery = CompositeIndexQueryFactory.MakeSubordinate(
         isNWOnTrigger,
         numStreams,
         hashEval,
         rangeEvals);
 }
Example #7
0
        public SubordCompositeTableLookupStrategyFactory(
            bool isNWOnTrigger,
            int numStreams,
            ICollection <SubordPropHashKey> keyExpr,
            Type[] coercionKeyTypes,
            ICollection <SubordPropRangeKey> rangeProps,
            Type[] coercionRangeTypes)
        {
            _rangeDescs = rangeProps;
            var expressionTexts = new List <String>();

            _innerIndexQuery = CompositeIndexQueryFactory.MakeSubordinate(
                isNWOnTrigger, numStreams, keyExpr, coercionKeyTypes, rangeProps, coercionRangeTypes, expressionTexts);
            _strategyDesc = new LookupStrategyDesc(LookupStrategyType.COMPOSITE, expressionTexts.ToArray());
        }
Example #8
0
        internal static ISet <EventBean> Handle(
            EventBean[] eventsPerStream,
            IDictionary <object, object> sortedMapOne,
            IDictionary <object, object> sortedMapTwo,
            ISet <EventBean> result,
            CompositeIndexQuery next)
        {
            if (next == null)
            {
                if (result == null)
                {
                    result = new HashSet <EventBean>();
                }

                AddResults(
                    sortedMapOne != null ?
                    sortedMapOne.Select(entry => new KeyValuePair <object, ICollection <EventBean> >(entry.Key, entry.Value as ICollection <EventBean>)) :
                    null,
                    sortedMapTwo != null ?
                    sortedMapTwo.Select(entry => new KeyValuePair <object, ICollection <EventBean> >(entry.Key, entry.Value as ICollection <EventBean>)) :
                    null,
                    result);

                return(result);
            }
            else
            {
                if (result == null)
                {
                    result = new HashSet <EventBean>();
                }
                var map = sortedMapOne;
                foreach (var entry in map)
                {
                    next.Add(eventsPerStream, (Map)entry.Value, result);
                }
                if (sortedMapTwo != null)
                {
                    map = sortedMapTwo;
                    foreach (var entry in map)
                    {
                        next.Add(eventsPerStream, (Map)entry.Value, result);
                    }
                }
                return(result);
            }
        }
Example #9
0
        internal static ISet <EventBean> Handle(
            EventBean theEvent,
            IDictionary <object, object> sortedMapOne,
            IDictionary <object, object> sortedMapTwo,
            ISet <EventBean> result,
            CompositeIndexQuery next)
        {
            if (next == null)
            {
                if (result == null)
                {
                    result = new HashSet <EventBean>();
                }

                AddResults(
                    sortedMapOne != null ?
                    sortedMapOne.Select(entry => new KeyValuePair <object, ICollection <EventBean> >(entry.Key, entry.Value as ICollection <EventBean>)) :
                    null,
                    sortedMapTwo != null ?
                    sortedMapTwo.Select(entry => new KeyValuePair <object, ICollection <EventBean> >(entry.Key, entry.Value as ICollection <EventBean>)) :
                    null,
                    result);

                return(result);
            }
            else
            {
                if (result == null)
                {
                    result = new HashSet <EventBean>();
                }

                foreach (var entry in sortedMapOne)
                {
                    next.Add(theEvent, entry.Value as Map, result);
                }
                if (sortedMapTwo != null)
                {
                    foreach (var entry in sortedMapTwo)
                    {
                        next.Add(theEvent, entry.Value as Map, result);
                    }
                }
                return(result);
            }
        }
Example #10
0
        protected internal static ICollection <EventBean> Handle(
            EventBean[] eventsPerStream,
            IDictionary <object, object> sortedMapOne,
            IDictionary <object, object> sortedMapTwo,
            ICollection <EventBean> result,
            CompositeIndexQuery next,
            CompositeIndexQueryResultPostProcessor postProcessor)
        {
            if (next == null)
            {
                if (result == null)
                {
                    result = new HashSet <EventBean>();
                }
                AddResults(
                    sortedMapOne != null ?
                    sortedMapOne.Select(entry => new KeyValuePair <object, ICollection <EventBean> >(entry.Key, entry.Value as ICollection <EventBean>)) :
                    null,
                    sortedMapTwo != null ?
                    sortedMapTwo.Select(entry => new KeyValuePair <object, ICollection <EventBean> >(entry.Key, entry.Value as ICollection <EventBean>)) :
                    null,
                    result,
                    postProcessor);

                return(result);
            }
            else
            {
                if (result == null)
                {
                    result = new HashSet <EventBean>();
                }
                foreach (var entry in sortedMapOne)
                {
                    next.Add(eventsPerStream, entry.Value as IDictionary <object, object>, result, postProcessor);
                }
                if (sortedMapTwo != null)
                {
                    foreach (var entry in sortedMapTwo)
                    {
                        next.Add(eventsPerStream, entry.Value as IDictionary <object, object>, result, postProcessor);
                    }
                }
                return(result);
            }
        }
Example #11
0
        public static CompositeIndexQuery MakeSubordinate(
            bool isNWOnTrigger,
            int numOuterStreams,
            ICollection <SubordPropHashKey> keyExpr,
            Type[] coercionKeyTypes,
            ICollection <SubordPropRangeKey> rangeProps,
            Type[] rangeCoercionTypes,
            IList <String> expressionTexts)
        {
            // construct chain
            IList <CompositeIndexQuery> queries = new List <CompositeIndexQuery>();

            if (keyExpr.Count > 0)
            {
                IList <QueryGraphValueEntryHashKeyed> hashKeys = new List <QueryGraphValueEntryHashKeyed>();
                foreach (SubordPropHashKey keyExp in keyExpr)
                {
                    expressionTexts.Add(ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(keyExp.HashKey.KeyExpr));
                    hashKeys.Add(keyExp.HashKey);
                }
                queries.Add(new CompositeIndexQueryKeyed(isNWOnTrigger, -1, numOuterStreams, hashKeys, coercionKeyTypes));
            }
            int count = 0;

            foreach (SubordPropRangeKey rangeProp in rangeProps)
            {
                Type coercionType = rangeCoercionTypes == null ? null : rangeCoercionTypes[count];
                queries.Add(new CompositeIndexQueryRange(isNWOnTrigger, -1, numOuterStreams, rangeProp, coercionType, expressionTexts));
                count++;
            }

            // Hook up as chain for remove
            CompositeIndexQuery last = null;

            foreach (CompositeIndexQuery action in queries)
            {
                if (last != null)
                {
                    last.SetNext(action);
                }
                last = action;
            }
            return(queries[0]);
        }
        public CompositeTableLookupStrategy(EventType eventType, int lookupStream, IList <QueryGraphValueEntryHashKeyed> hashKeys, IList <QueryGraphValueEntryRange> rangeKeyPairs, PropertyCompositeEventTable index)
        {
            _eventType     = eventType;
            _index         = index;
            _rangeKeyPairs = rangeKeyPairs;
            _chain         = CompositeIndexQueryFactory.MakeJoinSingleLookupStream(false, lookupStream, hashKeys, index.OptKeyCoercedTypes, rangeKeyPairs, index.OptRangeCoercedTypes);

            var expressionTexts = new ArrayDeque <string>();

            foreach (QueryGraphValueEntryRange pair in rangeKeyPairs)
            {
                ExprNode[] expressions = pair.Expressions;
                foreach (ExprNode node in expressions)
                {
                    expressionTexts.Add(ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(node));
                }
            }
            _lookupStrategyDesc = new LookupStrategyDesc(LookupStrategyType.COMPOSITE, expressionTexts.ToArray());
        }
Example #13
0
        public ICollection<EventBean> Lookup(
            EventBean theEvent,
            IDictionary<object, CompositeIndexEntry> parent,
            ICollection<EventBean> result,
            CompositeIndexQuery next,
            ExprEvaluatorContext context,
            ICollection<object> optionalKeyCollector,
            CompositeIndexQueryResultPostProcessor postProcessor)
        {
            object comparableStart = base.EvaluateLookupStart(theEvent, context);
            optionalKeyCollector?.Add(comparableStart);

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

            object comparableEnd = base.EvaluateLookupEnd(theEvent, context);
            optionalKeyCollector?.Add(comparableEnd);

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

            IOrderedDictionary<object, CompositeIndexEntry> index =
                (IOrderedDictionary<object, CompositeIndexEntry>) parent;

            
            IDictionary<object, CompositeIndexEntry> submap;
            if (index.KeyComparer.Compare(comparableStart, comparableEnd) <= 0) {
                submap = index.Between(comparableStart, includeStart, comparableEnd, includeEnd);
            }
            else if (_allowReverseRange) {
                submap = index.Between(comparableEnd, includeStart, comparableStart, includeEnd);
            }
            else {
                return null;
            }

            return CompositeIndexQueryRange.Handle(theEvent, submap, null, result, next, postProcessor);
        }
Example #14
0
        public static CompositeIndexQuery MakeJoinSingleLookupStream(
            bool isNWOnTrigger,
            int lookupStream,
            IList <QueryGraphValueEntryHashKeyed> hashKeys,
            IList <Type> keyCoercionTypes,
            IList <QueryGraphValueEntryRange> rangeProps,
            IList <Type> rangeCoercionTypes)
        {
            // construct chain
            IList <CompositeIndexQuery> queries = new List <CompositeIndexQuery>();

            if (hashKeys.Count > 0)
            {
                queries.Add(new CompositeIndexQueryKeyed(false, lookupStream, -1, hashKeys, keyCoercionTypes));
            }
            int count = 0;

            foreach (QueryGraphValueEntryRange rangeProp in rangeProps)
            {
                Type coercionType       = rangeCoercionTypes == null ? null : rangeCoercionTypes[count];
                SubordPropRangeKey rkey = new SubordPropRangeKey(rangeProp, coercionType);
                queries.Add(
                    new CompositeIndexQueryRange(isNWOnTrigger, lookupStream, -1, rkey, coercionType, new List <String>()));
                count++;
            }

            // Hook up as chain for remove
            CompositeIndexQuery last = null;

            foreach (CompositeIndexQuery action in queries)
            {
                if (last != null)
                {
                    last.SetNext(action);
                }
                last = action;
            }
            return(queries[0]);
        }
Example #15
0
        public ICollection <EventBean> Lookup(
            EventBean theEvent,
            DataMap parent,
            ICollection <EventBean> result,
            CompositeIndexQuery next,
            ExprEvaluatorContext context,
            IList <object> optionalKeyCollector,
            CompositeIndexQueryResultPostProcessor postProcessor)
        {
            var index      = (OrderedDictionary <object, object>)parent;
            var comparable = EvaluateLookup(theEvent, context);

            if (optionalKeyCollector != null)
            {
                optionalKeyCollector.Add(comparable);
            }
            if (comparable == null)
            {
                return(null);
            }
            comparable = EventBeanUtility.Coerce(comparable, CoercionType);
            return(CompositeIndexQueryRange.Handle(theEvent, index.Tail(comparable, false), null, result, next, postProcessor));
        }
Example #16
0
        protected internal static ICollection<EventBean> Handle(
            EventBean[] eventsPerStream,
            IDictionary<object, CompositeIndexEntry> sortedMapOne,
            IDictionary<object, CompositeIndexEntry> sortedMapTwo,
            ICollection<EventBean> result,
            CompositeIndexQuery next,
            CompositeIndexQueryResultPostProcessor postProcessor)
        {
            if (next == null) {
                if (result == null) {
                    result = new HashSet<EventBean>();
                }

                AddResults(sortedMapOne, sortedMapTwo, result, postProcessor);
                return result;
            }
            else {
                if (result == null) {
                    result = new HashSet<EventBean>();
                }

                var map = sortedMapOne;
                foreach (var entry in map) {
                    next.Add(eventsPerStream, entry.Value.AssertIndex(), result, postProcessor);
                }

                if (sortedMapTwo != null) {
                    map = sortedMapTwo;
                    foreach (var entry in map) {
                        next.Add(eventsPerStream, entry.Value.AssertIndex(), result, postProcessor);
                    }
                }

                return result;
            }
        }
Example #17
0
        public ISet <EventBean> Lookup(EventBean theEvent, Map parent, ISet <EventBean> result, CompositeIndexQuery next, ExprEvaluatorContext context, IList <object> optionalKeyCollector)
        {
            var comparableStart = base.EvaluateLookupStart(theEvent, context);

            if (optionalKeyCollector != null)
            {
                optionalKeyCollector.Add(comparableStart);
            }
            if (comparableStart == null)
            {
                return(null);
            }
            var comparableEnd = base.EvaluateLookupEnd(theEvent, context);

            if (optionalKeyCollector != null)
            {
                optionalKeyCollector.Add(comparableEnd);
            }
            if (comparableEnd == null)
            {
                return(null);
            }
            comparableStart = EventBeanUtility.Coerce(comparableStart, CoercionType);
            comparableEnd   = EventBeanUtility.Coerce(comparableEnd, CoercionType);

            var index     = (TreeMap)parent;
            var submapOne = index.Head(comparableStart, !IncludeStart);
            var submapTwo = index.Tail(comparableEnd, !IncludeEnd);

            return(CompositeIndexQueryRange.Handle(theEvent, submapOne, submapTwo, result, next));
        }
Example #18
0
 public void SetNext(CompositeIndexQuery next)
 {
     _next = next;
 }
 public SubordCompositeTableLookupStrategy(CompositeIndexQuery innerIndexQuery, PropertyCompositeEventTable index, LookupStrategyDesc strategyDesc)
 {
     this._innerIndexQuery = innerIndexQuery;
     this._index           = index;
     this._strategyDesc    = strategyDesc;
 }
Example #20
0
        public ISet <EventBean> Lookup(EventBean[] eventPerStream, DataMap parent, ISet <EventBean> result, CompositeIndexQuery next, ExprEvaluatorContext context, IList <object> optionalKeyCollector)
        {
            var index      = (OrderedDictionary <object, object>)parent;
            var comparable = EvaluatePerStream(eventPerStream, context);

            if (optionalKeyCollector != null)
            {
                optionalKeyCollector.Add(comparable);
            }
            if (comparable == null)
            {
                return(null);
            }
            comparable = EventBeanUtility.Coerce(comparable, CoercionType);
            return(CompositeIndexQueryRange.Handle(eventPerStream, index.Tail(comparable, false), null, result, next));
        }
        public ICollection <EventBean> Lookup(EventBean[] eventPerStream, Map parent, ICollection <EventBean> result, CompositeIndexQuery next, ExprEvaluatorContext context, IList <object> optionalKeyCollector, CompositeIndexQueryResultPostProcessor postProcessor)
        {
            var comparableStart = base.EvaluatePerStreamStart(eventPerStream, context);

            if (optionalKeyCollector != null)
            {
                optionalKeyCollector.Add(comparableStart);
            }
            if (comparableStart == null)
            {
                return(null);
            }
            var comparableEnd = base.EvaluatePerStreamEnd(eventPerStream, context);

            if (optionalKeyCollector != null)
            {
                optionalKeyCollector.Add(comparableEnd);
            }
            if (comparableEnd == null)
            {
                return(null);
            }
            comparableStart = EventBeanUtility.Coerce(comparableStart, CoercionType);
            comparableEnd   = EventBeanUtility.Coerce(comparableEnd, CoercionType);

            var index     = (TreeMap)parent;
            var submapOne = index.Head(comparableStart, !IncludeStart);
            var submapTwo = index.Tail(comparableEnd, !IncludeEnd);

            return(CompositeIndexQueryRange.Handle(eventPerStream, submapOne, submapTwo, result, next, postProcessor));
        }
Example #22
0
 public HistoricalIndexLookupStrategyComposite(int lookupStream, IList <QueryGraphValueEntryHashKeyed> hashKeys, Type[] keyCoercionTypes, IList <QueryGraphValueEntryRange> rangeKeyPairs, Type[] rangeCoercionTypes)
 {
     _chain = CompositeIndexQueryFactory.MakeJoinSingleLookupStream(false, lookupStream, hashKeys, keyCoercionTypes, rangeKeyPairs, rangeCoercionTypes);
 }
Example #23
0
 public CompositeIndexQuery SetNext(CompositeIndexQuery next)
 {
     this._next = next;
     return this;
 }
        public ICollection <EventBean> Lookup(EventBean[] eventPerStream, Map parent, ICollection <EventBean> result, CompositeIndexQuery next, ExprEvaluatorContext context, IList <object> optionalKeyCollector, CompositeIndexQueryResultPostProcessor postProcessor)
        {
            var comparableStart = base.EvaluatePerStreamStart(eventPerStream, context);

            if (optionalKeyCollector != null)
            {
                optionalKeyCollector.Add(comparableStart);
            }
            if (comparableStart == null)
            {
                return(null);
            }
            var comparableEnd = base.EvaluatePerStreamEnd(eventPerStream, context);

            if (optionalKeyCollector != null)
            {
                optionalKeyCollector.Add(comparableEnd);
            }
            if (comparableEnd == null)
            {
                return(null);
            }
            var index = (OrderedDictionary <object, object>)parent;

            comparableStart = EventBeanUtility.Coerce(comparableStart, CoercionType);
            comparableEnd   = EventBeanUtility.Coerce(comparableEnd, CoercionType);

            IDictionary <object, object> submap;

            try
            {
                submap = index.Between(comparableStart, IncludeStart, comparableEnd, IncludeEnd);
            }
            catch (ArgumentException)
            {
                if (_allowReverseRange)
                {
                    submap = index.Between(comparableEnd, IncludeStart, comparableStart, IncludeEnd);
                }
                else
                {
                    return(null);
                }
            }

            return(CompositeIndexQueryRange.Handle(eventPerStream, submap, null, result, next, postProcessor));
        }