示例#1
0
        /// <summary>
        ///     Populates into the supplied list all aggregation functions within this expression, if any.
        ///     <para />
        ///     Populates by going bottom-up such that nested aggregates appear first.
        ///     <para />
        ///     I.e. sum(volume * sum(price)) would put first A then B into the list with A=sum(price) and B=sum(volume * A)
        /// </summary>
        /// <param name="topNode">is the expression node to deep inspect</param>
        /// <param name="aggregateNodes">is a list of node to populate into</param>
        public static void GetAggregatesBottomUp(
            ExprNode topNode,
            IList<ExprAggregateNode> aggregateNodes)
        {
            // Map to hold per level of the node (1 to N depth) of expression node a list of aggregation expr nodes, if any
            // exist at that level
            var aggregateExprPerLevel = new OrderedListDictionary<int, IList<ExprAggregateNode>>();

            RecursiveAggregate(topNode, aggregateExprPerLevel, 1);

            // Done if none found
            if (aggregateExprPerLevel.IsEmpty()) {
                return;
            }

            // From the deepest (highest) level to the lowest, add aggregates to list
            int deepLevel = aggregateExprPerLevel.Last().Key;
            for (var i = deepLevel; i >= 1; i--) {
                var list = aggregateExprPerLevel.Get(i);
                if (list == null) {
                    continue;
                }

                aggregateNodes.AddAll(list);
            }
        }
            public void Run(RegressionEnvironment env)
            {
                var fields  = "c0".SplitCsv();
                var treemap = new OrderedListDictionary <int, IList <SupportBean> >();

                var epl = "@Name('s0') select sorted(IntPrimitive).floorEvent(IntPrimitive-1) as c0 from SupportBean#length(3) as sb";

                env.EplToModelCompileDeploy(epl).AddListener("s0");

                MakeSendBean(env, treemap, "E1", 10);
                EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] { LessThanOrEqualToFirstEvent(treemap, 10 - 1) });

                MakeSendBean(env, treemap, "E2", 20);
                EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] { LessThanOrEqualToFirstEvent(treemap, 20 - 1) });

                env.Milestone(0);

                MakeSendBean(env, treemap, "E3", 15);
                EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] { LessThanOrEqualToFirstEvent(treemap, 15 - 1) });

                MakeSendBean(env, treemap, "E3", 17);
                EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] { LessThanOrEqualToFirstEvent(treemap, 17 - 1) });

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var epl =
                    "create table MyTable(sortcol sorted(IntPrimitive) @type('SupportBean'));\n" +
                    "into table MyTable select sorted(*) as sortcol from SupportBean;\n" +
                    "@Name('s0') select " +
                    "MyTable.sortcol.dictionaryReference() as nmr" +
                    " from SupportBean_S0";

                env.CompileDeploy(epl).AddListener("s0");

                AssertType(env, typeof(IOrderedDictionary <object, object>), "nmr");

                var treemap = new OrderedListDictionary <int, IList <SupportBean> >();

                PrepareTestData(env, treemap);                 // 1, 1, 4, 6, 6, 8, 9

                env.SendEventBean(new SupportBean_S0(-1));
                var @event          = env.Listener("s0").AssertOneGetNewAndReset();
                var eventDictionary = (IOrderedDictionary <object, ICollection <EventBean> >)@event.Get("nmr");

                AssertOrderedDictionary(treemap, eventDictionary);

                env.UndeployAll();
            }
示例#4
0
        public static FilterSpecPlanPathForge SortRemoveDups(FilterSpecPlanPathForge parameters)
        {
            if (parameters.Triplets.Length <= 1) {
                return parameters;
            }

            var map = new OrderedListDictionary<FilterOperator, IList<FilterSpecPlanPathTripletForge>>(COMPARATOR_PARAMETERS);

            foreach (FilterSpecPlanPathTripletForge parameter in parameters.Triplets) {
                if (!map.TryGetValue(parameter.Param.FilterOperator, out var list)) {
                    list = new List<FilterSpecPlanPathTripletForge>();
                    map[parameter.Param.FilterOperator] = list;
                }

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

                list.Add(parameter);
            }

            var result = new List<FilterSpecPlanPathTripletForge>();
            foreach (var entry in map) {
                result.AddAll(entry.Value);
            }

            return new FilterSpecPlanPathForge(
                result.ToArray(),
                parameters.PathNegate);
        }
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var epl  =
                    "create table MyTable(sortcol sorted(IntPrimitive) @type('SupportBean'));\n" +
                    "into table MyTable select sorted(*) as sortcol from SupportBean;\n";

                env.CompileDeploy(epl, path);

                env.EplToModelCompileDeploy("@Name('s0') select sortcol.floorEvent(Id) as c0 from SupportBean_S0, MyTable", path)
                .AddListener("s0");

                var treemap = new OrderedListDictionary <int, IList <SupportBean> >();

                MakeSendBean(env, treemap, "E1", 10);
                MakeSendBean(env, treemap, "E2", 20);
                MakeSendBean(env, treemap, "E3", 30);

                env.Milestone(0);

                for (var i = 0; i < 40; i++)
                {
                    env.SendEventBean(new SupportBean_S0(i));
                    Assert.AreEqual(LessThanOrEqualToFirstEvent(treemap, i), env.Listener("s0").AssertOneGetNewAndReset().Get("c0"));
                }

                env.UndeployAll();
            }
示例#6
0
文件: URIUtil.cs 项目: lanicon/nesper
        /// <summary>
        /// Given a child URI and a map of factory URIs, inspect the child URI against the factory
        /// URIs and return a collection of entries for which the child URI falls within or is equals
        /// to the factory URI.
        /// </summary>
        /// <param name="child">is the child URI to match against factory URIs</param>
        /// <param name="uris">is a map of factory URI and an object</param>
        /// <returns>matching factory URIs, if any</returns>
        public static ICollection <KeyValuePair <Uri, V> > FilterSort <V>(
            Uri child,
            IDictionary <Uri, V> uris)
        {
            var childPathIsOpaque   = IsOpaque(child);
            var childPathIsRelative = !child.IsAbsoluteUri;
            var childPathElements   = ParsePathElements(child);

            var result = new OrderedListDictionary <int, KeyValuePair <Uri, V> >();

            foreach (var entry in uris)
            {
                var factoryUri = entry.Key;

                // handle opaque (mailto:) and relative (a/b) using equals
                if (childPathIsOpaque || childPathIsRelative || !factoryUri.IsAbsoluteUri || IsOpaque(factoryUri))
                {
                    if (factoryUri.Equals(child))
                    {
                        result.Put(int.MinValue, entry); // Equals is a perfect match
                    }

                    continue;
                }

                // handle absolute URIs, compare scheme and authority if present
                if (((child.Scheme != null) && (factoryUri.Scheme == null)) ||
                    ((child.Scheme == null) && (factoryUri.Scheme != null)))
                {
                    continue;
                }

                if ((child.Scheme != null) && (!child.Scheme.Equals(factoryUri.Scheme)))
                {
                    continue;
                }

                if (((child.Authority != null) && (factoryUri.Authority == null)) ||
                    ((child.Authority == null) && (factoryUri.Authority != null)))
                {
                    continue;
                }

                if ((child.Authority != null) && (child.Authority != factoryUri.Authority))
                {
                    continue;
                }

                // Match the child
                string[] factoryPathElements = ParsePathElements(factoryUri);
                int      score = ComputeScore(childPathElements, factoryPathElements);
                if (score > 0)
                {
                    result.Put(score, entry); // Partial match if score is positive
                }
            }

            return(result.Values);
        }
示例#7
0
        private static void ReadState(
            DataInput input,
            CountMinSketchState state)
        {
            var depth = input.ReadInt();
            var width = input.ReadInt();

            var rowsTable = input.ReadInt();
            var table = new long[rowsTable][];
            for (var i = 0; i < rowsTable; i++) {
                var colsRows = input.ReadInt();
                table[i] = new long[colsRows];
                for (var j = 0; j < colsRows; j++) {
                    table[i][j] = input.ReadLong();
                }
            }

            var rowsHash = input.ReadInt();
            var hash = new long[rowsHash];
            for (var i = 0; i < rowsTable; i++) {
                hash[i] = input.ReadLong();
            }

            var total = input.ReadLong();
            state.Hashes = new CountMinSketchStateHashes(depth, width, table, hash, total);

            var hasTopk = input.ReadBoolean();
            state.Topk = null;
            if (hasTopk) {
                var topkMax = input.ReadInt();

                var topMap = new OrderedListDictionary<long, object>(
                    Comparers.Default<long>().Inverse());
                var refMap = new Dictionary<ByteBuffer, long>();
                var numRows = input.ReadInt();
                for (var i = 0; i < numRows; i++) {
                    var freq = input.ReadLong();
                    var numEntries = input.ReadInt();
                    if (numEntries == 1) {
                        var buf = ReadBytes(input);
                        topMap.Put(freq, buf);
                        refMap.Put(buf, freq);
                    }
                    else {
                        Deque<ByteBuffer> q = new ArrayDeque<ByteBuffer>(numEntries);
                        for (var j = 0; j < numEntries; j++) {
                            var buf = ReadBytes(input);
                            q.AddLast(buf);
                            refMap.Put(buf, freq);
                        }

                        topMap.Put(freq, q);
                    }
                }

                state.Topk = new CountMinSketchStateTopk(topkMax, topMap, refMap);
            }
        }
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var epl  = "create table MyTable(sortcol sorted(IntPrimitive) @type('SupportBean'));\n" +
                           "into table MyTable select sorted(*) as sortcol from SupportBean;\n";

                env.CompileDeploy(epl, path);

                var select = "@Name('s0') select " +
                             "MyTable.sortcol as sortedItself, " +
                             "MyTable.sortcol.ceilingEvent(Id) as ce, " +
                             "MyTable.sortcol.ceilingEvents(Id) as ces, " +
                             "MyTable.sortcol.ceilingKey(Id) as ck, " +
                             "MyTable.sortcol.floorEvent(Id) as fe, " +
                             "MyTable.sortcol.floorEvents(Id) as fes, " +
                             "MyTable.sortcol.floorKey(Id) as fk, " +
                             "MyTable.sortcol.higherEvent(Id) as he, " +
                             "MyTable.sortcol.higherEvents(Id) as hes, " +
                             "MyTable.sortcol.higherKey(Id) as hk, " +
                             "MyTable.sortcol.lowerEvent(Id) as le, " +
                             "MyTable.sortcol.lowerEvents(Id) as les, " +
                             "MyTable.sortcol.lowerKey(Id) as lk" +
                             " from SupportBean_S0";

                env.EplToModelCompileDeploy(select, path).AddListener("s0");

                AssertType(env, typeof(SupportBean), "ce,fe,he,le");
                AssertType(env, typeof(SupportBean[]), "ces,fes,hes,les");
                AssertType(env, typeof(int?), "ck,fk,hk,lk");

                var treemap = new OrderedListDictionary <int, IList <SupportBean> >();

                PrepareTestData(env, treemap);                 // 1, 1, 4, 6, 6, 8, 9

                for (var i = 0; i < 12; i++)
                {
                    env.SendEventBean(new SupportBean_S0(i));
                    var @event = env.Listener("s0").AssertOneGetNewAndReset();
                    Assert.AreEqual(FirstEvent(treemap.GreaterThanOrEqualTo(i)), @event.Get("ce"));
                    EPAssertionUtil.AssertEqualsExactOrder(AllEvents(treemap.GreaterThanOrEqualTo(i)), (SupportBean[])@event.Get("ces"));
                    Assert.AreEqual(treemap.GreaterThanOrEqualTo(i)?.Key, @event.Get("ck"));
                    Assert.AreEqual(FirstEvent(treemap.LessThanOrEqualTo(i)), @event.Get("fe"));
                    EPAssertionUtil.AssertEqualsExactOrder(AllEvents(treemap.LessThanOrEqualTo(i)), (SupportBean[])@event.Get("fes"));
                    Assert.AreEqual(treemap.LessThanOrEqualTo(i)?.Key, @event.Get("fk"));
                    Assert.AreEqual(FirstEvent(treemap.GreaterThan(i)), @event.Get("he"));
                    EPAssertionUtil.AssertEqualsExactOrder(AllEvents(treemap.GreaterThan(i)), (SupportBean[])@event.Get("hes"));
                    Assert.AreEqual(treemap.GreaterThan(i)?.Key, @event.Get("hk"));
                    Assert.AreEqual(FirstEvent(treemap.LessThan(i)), @event.Get("le"));
                    EPAssertionUtil.AssertEqualsExactOrder(AllEvents(treemap.LessThan(i)), (SupportBean[])@event.Get("les"));
                    Assert.AreEqual(treemap.LessThan(i)?.Key, @event.Get("lk"));
                }

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var epl =
                    "@public @buseventtype create schema MySubmapEvent as " +
                    typeof(MySubmapEvent).MaskTypeName() +
                    ";\n" +
                    "create table MyTable(sortcol sorted(IntPrimitive) @type('SupportBean'));\n" +
                    "into table MyTable select sorted(*) as sortcol from SupportBean;\n" +
                    "@Name('s0') select " +
                    "MyTable.sortcol.eventsBetween(FromKey, IsFromInclusive, ToKey, IsToInclusive) as eb," +
                    "MyTable.sortcol.eventsBetween(FromKey, IsFromInclusive, ToKey, IsToInclusive).lastOf() as eblastof," +
                    "MyTable.sortcol.subMap(FromKey, IsFromInclusive, ToKey, IsToInclusive) as sm" +
                    " from MySubmapEvent";

                env.CompileDeploy(epl).AddListener("s0");

                AssertType(env, typeof(SupportBean[]), "eb");
                AssertType(env, typeof(IOrderedDictionary <object, object>), "sm");
                AssertType(env, typeof(SupportBean), "eblastof");

                var treemap = new OrderedListDictionary <int, IList <SupportBean> >();

                PrepareTestData(env, treemap);                 // 1, 1, 4, 6, 6, 8, 9

                for (var start = 0; start < 12; start++)
                {
                    for (var end = 0; end < 12; end++)
                    {
                        if (start > end)
                        {
                            continue;
                        }

                        foreach (var includeStart in new bool[] { false, true })
                        {
                            foreach (var includeEnd in new bool[] { false, true })
                            {
                                var sme = new MySubmapEvent(start, includeStart, end, includeEnd);
                                env.SendEventBean(sme);
                                var @event = env.Listener("s0").AssertOneGetNewAndReset();
                                var submap = @event.Get("sm")
                                             .AsObjectDictionary(MagicMarker.SingletonInstance)
                                             .TransformLeft <object, object, SupportBean[]>();

                                AssertEventsBetween(treemap, sme, (SupportBean[])@event.Get("eb"), (SupportBean)@event.Get("eblastof"));
                                AssertSubmap(treemap, sme, submap);
                            }
                        }
                    }
                }

                env.UndeployAll();
            }
        public IOrderedDictionary <string, V> PrefixMap(string key)
        {
            var result = new OrderedListDictionary <string, V>();

            foreach (var entry in simple)
            {
                if (entry.Key.StartsWith(key))
                {
                    result.Put(entry.Key, entry.Value);
                }
            }

            return(result);
        }
            public void Run(RegressionEnvironment env)
            {
                var epl = "create table MyTable(sortcol sorted(IntPrimitive) @type('SupportBean'));\n" +
                          "into table MyTable select sorted(*) as sortcol from SupportBean;\n" +
                          "@Name('s0') select " +
                          "MyTable.sortcol.ceilingEvent(Id).TheString as ceid," +
                          "MyTable.sortcol.ceilingEvent(Id).firstOf() as cefo," +
                          "MyTable.sortcol.ceilingEvents(Id).lastOf() as ceslo," +
                          "MyTable.sortcol.floorEvent(Id).TheString as feid," +
                          "MyTable.sortcol.floorEvent(Id).firstOf() as fefo," +
                          "MyTable.sortcol.floorEvents(Id).lastOf() as feslo," +
                          "MyTable.sortcol.higherEvent(Id).TheString as heid," +
                          "MyTable.sortcol.higherEvent(Id).firstOf() as hefo," +
                          "MyTable.sortcol.higherEvents(Id).lastOf() as heslo," +
                          "MyTable.sortcol.lowerEvent(Id).TheString as leid," +
                          "MyTable.sortcol.lowerEvent(Id).firstOf() as lefo," +
                          "MyTable.sortcol.lowerEvents(Id).lastOf() as leslo " +
                          " from SupportBean_S0";

                env.CompileDeploy(epl).AddListener("s0");

                AssertType(env, typeof(string), "ceid,feid,heid,leid");
                AssertType(env, typeof(SupportBean), "cefo,fefo,hefo,lefo,ceslo,feslo,heslo,leslo");

                var treemap = new OrderedListDictionary <int, IList <SupportBean> >();

                PrepareTestData(env, treemap);                 // 1, 1, 4, 6, 6, 8, 9

                for (var i = 0; i < 12; i++)
                {
                    env.SendEventBean(new SupportBean_S0(i));
                    var @event  = env.Listener("s0").AssertOneGetNewAndReset();
                    var message = "failed at " + i;
                    Assert.AreEqual(FirstEventString(treemap.GreaterThanOrEqualTo(i)), @event.Get("ceid"), message);
                    Assert.AreEqual(FirstEvent(treemap.GreaterThanOrEqualTo(i)), @event.Get("cefo"), message);
                    Assert.AreEqual(LastEvent(treemap.GreaterThanOrEqualTo(i)), @event.Get("ceslo"), message);
                    Assert.AreEqual(FirstEventString(treemap.LessThanOrEqualTo(i)), @event.Get("feid"), message);
                    Assert.AreEqual(FirstEvent(treemap.LessThanOrEqualTo(i)), @event.Get("fefo"), message);
                    Assert.AreEqual(LastEvent(treemap.LessThanOrEqualTo(i)), @event.Get("feslo"), message);
                    Assert.AreEqual(FirstEventString(treemap.GreaterThan(i)), @event.Get("heid"), message);
                    Assert.AreEqual(FirstEvent(treemap.GreaterThan(i)), @event.Get("hefo"), message);
                    Assert.AreEqual(LastEvent(treemap.GreaterThan(i)), @event.Get("heslo"), message);
                    Assert.AreEqual(FirstEventString(treemap.LessThan(i)), @event.Get("leid"), message);
                    Assert.AreEqual(FirstEvent(treemap.LessThan(i)), @event.Get("lefo"), message);
                    Assert.AreEqual(LastEvent(treemap.LessThan(i)), @event.Get("leslo"), message);
                }

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var epl =
                    "create table MyTable(sortcol sorted(IntPrimitive) @type('SupportBean'));\n" +
                    "into table MyTable select sorted(*) as sortcol from SupportBean;\n" +
                    "@Name('s0') select " +
                    "MyTable.sortcol.getEvent(Id) as ge," +
                    "MyTable.sortcol.getEvents(Id) as ges," +
                    "MyTable.sortcol.containsKey(Id) as ck," +
                    "MyTable.sortcol.countEvents() as cnte," +
                    "MyTable.sortcol.countKeys() as cntk," +
                    "MyTable.sortcol.getEvent(Id).TheString as geid," +
                    "MyTable.sortcol.getEvent(Id).firstOf() as gefo," +
                    "MyTable.sortcol.getEvents(Id).lastOf() as geslo " +
                    " from SupportBean_S0";

                env.CompileDeploy(epl).AddListener("s0");

                AssertType(env, typeof(SupportBean), "ge,gefo,geslo");
                AssertType(env, typeof(SupportBean[]), "ges");
                AssertType(env, typeof(int?), "cnte,cntk");
                AssertType(env, typeof(bool?), "ck");
                AssertType(env, typeof(string), "geid");

                var treemap = new OrderedListDictionary <int, IList <SupportBean> >();

                PrepareTestData(env, treemap);                 // 1, 1, 4, 6, 6, 8, 9

                for (var i = 0; i < 12; i++)
                {
                    env.SendEventBean(new SupportBean_S0(i));
                    var @event  = env.Listener("s0").AssertOneGetNewAndReset();
                    var message = "failed at " + i;

                    var valueAtIndex = treemap.Get(i);

                    Assert.AreEqual(FirstEvent(valueAtIndex), @event.Get("ge"), message);
                    EPAssertionUtil.AssertEqualsExactOrder(AllEvents(valueAtIndex), (SupportBean[])@event.Get("ges"));
                    Assert.AreEqual(treemap.ContainsKey(i), @event.Get("ck"), message);
                    Assert.AreEqual(7, @event.Get("cnte"), message);
                    Assert.AreEqual(5, @event.Get("cntk"), message);
                    Assert.AreEqual(FirstEventString(valueAtIndex), @event.Get("geid"), message);
                    Assert.AreEqual(FirstEvent(valueAtIndex), @event.Get("gefo"), message);
                    Assert.AreEqual(LastEvent(valueAtIndex), @event.Get("geslo"), message);
                }

                env.UndeployAll();
            }
        public object GetValue(
            int aggColNum,
            AggregationRow row,
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            AggregationStateSorted sorted = (AggregationStateSorted)row.GetAccessState(aggColNum);
            var fromKey = _fromKeyEval.Evaluate(eventsPerStream, isNewData, exprEvaluatorContext);

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

            var fromInclusive = _fromInclusiveEval.Evaluate(eventsPerStream, isNewData, exprEvaluatorContext).AsBoxedBoolean();

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

            var toKey = _toKeyEval.Evaluate(eventsPerStream, isNewData, exprEvaluatorContext);

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

            var toInclusive = _toInclusiveEval.Evaluate(eventsPerStream, isNewData, exprEvaluatorContext).AsBoxedBoolean();

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

            var mapOfArrays = new OrderedListDictionary <object, object>(sorted.Sorted.KeyComparer);
            var submap      = sorted.Sorted.Between(fromKey, fromInclusive.Value, toKey, toInclusive.Value);

            foreach (KeyValuePair <object, object> entry in submap)
            {
                mapOfArrays.Put(entry.Key, AggregatorAccessSortedImpl.CheckedPayloadGetUnderlyingArray(entry.Value, _underlyingClass));
            }

            return(mapOfArrays);
        }
示例#14
0
        /// <summary>
        ///     NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="outgoingEvents">events</param>
        /// <param name="orderKeys">keys</param>
        /// <param name="comparator">comparator</param>
        /// <returns>sorted</returns>
        public static EventBean[] SortWOrderKeys(
            EventBean[] outgoingEvents,
            object[] orderKeys,
            IComparer<object> comparator)
        {
            var sort = new OrderedListDictionary<object, object>(comparator);

            if (outgoingEvents == null || outgoingEvents.Length < 2) {
                return outgoingEvents;
            }

            for (var i = 0; i < outgoingEvents.Length; i++) {
                var entry = sort.Get(orderKeys[i]);
                if (entry == null) {
                    sort.Put(orderKeys[i], outgoingEvents[i]);
                }
                else if (entry is EventBean) {
                    IList<EventBean> list = new List<EventBean>();
                    list.Add((EventBean) entry);
                    list.Add(outgoingEvents[i]);
                    sort.Put(orderKeys[i], list);
                }
                else {
                    var list = (IList<EventBean>) entry;
                    list.Add(outgoingEvents[i]);
                }
            }

            var result = new EventBean[outgoingEvents.Length];
            var count = 0;
            foreach (object entry in sort.Values) {
                if (entry is IList<EventBean> output) {
                    foreach (var theEvent in output) {
                        result[count++] = theEvent;
                    }
                }
                else {
                    result[count++] = (EventBean) entry;
                }
            }

            return result;
        }
            public void Run(RegressionEnvironment env)
            {
                var epl = "create table MyTable(sortcol sorted(IntPrimitive) @type('SupportBean'));\n" +
                          "into table MyTable select sorted(*) as sortcol from SupportBean;\n" +
                          "@Name('s0') select " +
                          "MyTable.sortcol.firstEvent() as fe," +
                          "MyTable.sortcol.minBy() as minb," +
                          "MyTable.sortcol.firstEvents() as fes," +
                          "MyTable.sortcol.firstKey() as fk," +
                          "MyTable.sortcol.lastEvent() as le," +
                          "MyTable.sortcol.maxBy() as maxb," +
                          "MyTable.sortcol.lastEvents() as les," +
                          "MyTable.sortcol.lastKey() as lk" +
                          " from SupportBean_S0";

                env.CompileDeploy(epl).AddListener("s0");

                AssertType(env, typeof(SupportBean), "fe,le,minb,maxb");
                AssertType(env, typeof(SupportBean[]), "fes,les");
                AssertType(env, typeof(int?), "fk,lk");

                var treemap = new OrderedListDictionary <int, IList <SupportBean> >();

                PrepareTestData(env, treemap);                 // 1, 1, 4, 6, 6, 8, 9

                var treeMapFirst = treemap.First();
                var treeMapLast  = treemap.Last();

                env.SendEventBean(new SupportBean_S0(-1));
                var @event = env.Listener("s0").AssertOneGetNewAndReset();

                Assert.AreEqual(FirstEvent <IList <SupportBean> >(treeMapFirst), @event.Get("fe"));
                Assert.AreEqual(FirstEvent <IList <SupportBean> >(treeMapFirst), @event.Get("minb"));
                EPAssertionUtil.AssertEqualsExactOrder(AllEvents <IList <SupportBean> >(treeMapFirst), (SupportBean[])@event.Get("fes"));
                Assert.AreEqual(treeMapFirst.Key, @event.Get("fk"));
                Assert.AreEqual(FirstEvent <IList <SupportBean> >(treeMapLast), @event.Get("le"));
                Assert.AreEqual(FirstEvent <IList <SupportBean> >(treeMapLast), @event.Get("maxb"));
                EPAssertionUtil.AssertEqualsExactOrder(AllEvents <IList <SupportBean> >(treeMapLast), (SupportBean[])@event.Get("les"));
                Assert.AreEqual(treeMapLast.Key, @event.Get("lk"));

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var epl = "create table MyTable(sortcol sorted(IntPrimitive) @type('SupportBean'));\n" +
                          "into table MyTable select sorted(*) as sortcol from SupportBean;\n" +
                          "@Name('s0') select " +
                          "MyTable.sortcol.firstEvent().TheString as feid," +
                          "MyTable.sortcol.firstEvent().firstOf() as fefo," +
                          "MyTable.sortcol.firstEvents().lastOf() as feslo," +
                          "MyTable.sortcol.lastEvent().TheString() as leid," +
                          "MyTable.sortcol.lastEvent().firstOf() as lefo," +
                          "MyTable.sortcol.lastEvents().lastOf as leslo" +
                          " from SupportBean_S0";

                env.CompileDeploy(epl).AddListener("s0");

                AssertType(env, typeof(string), "feid,leid");
                AssertType(env, typeof(SupportBean), "fefo,feslo,lefo,leslo");

                var treemap = new OrderedListDictionary <int, IList <SupportBean> >();

                PrepareTestData(env, treemap);                 // 1, 1, 4, 6, 6, 8, 9
                var treeMapFirst = treemap.First();
                var treeMapLast  = treemap.Last();

                env.SendEventBean(new SupportBean_S0(-1));
                var @event = env.Listener("s0").AssertOneGetNewAndReset();

                Assert.AreEqual(FirstEventString <IList <SupportBean> >(treeMapFirst), @event.Get("feid"));
                Assert.AreEqual(FirstEvent <IList <SupportBean> >(treeMapFirst), @event.Get("fefo"));
                Assert.AreEqual(LastEvent <IList <SupportBean> >(treeMapFirst), @event.Get("feslo"));
                Assert.AreEqual(FirstEventString <IList <SupportBean> >(treeMapLast), @event.Get("leid"));
                Assert.AreEqual(FirstEvent <IList <SupportBean> >(treeMapLast), @event.Get("lefo"));
                Assert.AreEqual(LastEvent <IList <SupportBean> >(treeMapLast), @event.Get("leslo"));

                env.UndeployAll();
            }
        public void EvaluateEventForStatement(
            EventBean theEvent,
            IList<AgentInstance> agentInstances,
            AgentInstanceContext agentInstanceContextCreate)
        {
            // context was created - reevaluate for the given event
            ArrayDeque<FilterHandle> callbacks = new ArrayDeque<FilterHandle>(2);
            agentInstanceContextCreate.FilterService.Evaluate(theEvent, callbacks, agentInstanceContextCreate); // evaluates for ALL statements
            if (callbacks.IsEmpty()) {
                return;
            }

            // there is a single callback and a single context, if they match we are done
            if (agentInstances.Count == 1 && callbacks.Count == 1) {
                AgentInstance agentInstance = agentInstances[0];
                AgentInstanceContext agentInstanceContext = agentInstance.AgentInstanceContext;
                FilterHandle callback = callbacks.First;
                if (agentInstanceContext.StatementId == callback.StatementId &&
                    agentInstanceContext.AgentInstanceId == callback.AgentInstanceId) {
                    Process(agentInstance, callbacks, theEvent);
                }

                return;
            }

            // use the right sorted/unsorted Map keyed by AgentInstance to sort
            bool isPrioritized = agentInstanceContextCreate.RuntimeSettingsService.ConfigurationRuntime.Execution
                .IsPrioritized;
            IDictionary<AgentInstance, object> stmtCallbacks;
            if (!isPrioritized) {
                stmtCallbacks = new Dictionary<AgentInstance, object>();
            }
            else {
                stmtCallbacks = new OrderedListDictionary<AgentInstance, object>(AgentInstanceComparator.INSTANCE);
            }

            // process all callbacks
            foreach (FilterHandle filterHandle in callbacks) {
                EPStatementHandleCallbackFilter handleCallback = (EPStatementHandleCallbackFilter) filterHandle;

                // determine if this filter entry applies to any of the affected agent instances
                int statementId = filterHandle.StatementId;
                AgentInstance agentInstanceFound = null;
                foreach (AgentInstance agentInstance in agentInstances) {
                    AgentInstanceContext agentInstanceContext = agentInstance.AgentInstanceContext;
                    if (agentInstanceContext.StatementId == statementId &&
                        agentInstanceContext.AgentInstanceId == handleCallback.AgentInstanceId) {
                        agentInstanceFound = agentInstance;
                        break;
                    }
                }

                if (agentInstanceFound == null) { // when the callback is for some other stmt
                    continue;
                }

                EPStatementAgentInstanceHandle handle = handleCallback.AgentInstanceHandle;

                // Self-joins require that the internal dispatch happens after all streams are evaluated.
                // Priority or preemptive settings also require special ordering.
                if (handle.IsCanSelfJoin || isPrioritized) {
                    var stmtCallback = stmtCallbacks.Get(agentInstanceFound);
                    if (stmtCallback == null) {
                        stmtCallbacks.Put(agentInstanceFound, handleCallback);
                    }
                    else if (stmtCallback is ArrayDeque<FilterHandle> callbackFilterDeque) {
                        if (!callbackFilterDeque.Contains(handleCallback)) {
                            // De-duplicate for Filter OR expression paths
                            callbackFilterDeque.Add(handleCallback);
                        }
                    }
                    else {
                        var filterDeque = new ArrayDeque<FilterHandle>(4);
                        filterDeque.Add((FilterHandle) stmtCallback);
                        if (stmtCallback != handleCallback) { // De-duplicate for Filter OR expression paths
                            filterDeque.Add(handleCallback);
                        }

                        stmtCallbacks.Put(agentInstanceFound, filterDeque);
                    }

                    continue;
                }

                // no need to be sorted, process
                Process(agentInstanceFound, Collections.SingletonList<FilterHandle>(handleCallback), theEvent);
            }

            if (stmtCallbacks.IsEmpty()) {
                return;
            }

            // Process self-join or sorted prioritized callbacks
            foreach (KeyValuePair<AgentInstance, object> entry in stmtCallbacks) {
                AgentInstance agentInstance = entry.Key;
                object callbackList = entry.Value;
                if (callbackList is ICollection<FilterHandle> filterHandleCollection) {
                    Process(agentInstance, filterHandleCollection, theEvent);
                }
                else {
                    Process(
                        agentInstance,
                        Collections.SingletonList<FilterHandle>((FilterHandle) callbackList),
                        theEvent);
                }

                if (agentInstance.AgentInstanceContext.EpStatementAgentInstanceHandle.IsPreemptive) {
                    return;
                }
            }
        }
示例#18
0
        // Wherein: Object either is ByteBuffer or Deque<ByteBuffer>

        public CountMinSketchStateTopk(int topKMax)
        {
            TopKMax          = topKMax;
            _lastFreqForItem = new Dictionary <ByteBuffer, long>();
            Topk             = new OrderedListDictionary <long, object>(SimpleComparer <long> .Reverse);
        }
示例#19
0
        public static RowRecogPlan ValidateAndPlan(
            IContainer container,
            EventType parentEventType,
            bool unbound,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var statementRawInfo = @base.StatementRawInfo;
            var matchRecognizeSpec = @base.StatementSpec.Raw.MatchRecognizeSpec;
            var annotations = statementRawInfo.Annotations;
            var iterateOnly = HintEnum.ITERATE_ONLY.GetHint(annotations) != null;
            var additionalForgeables = new List<StmtClassForgeableFactory>();

            // Expanded pattern already there
            RowRecogExprNode expandedPatternNode = matchRecognizeSpec.Pattern;

            // Determine single-row and multiple-row variables
            var variablesSingle = new LinkedHashSet<string>();
            var variablesMultiple = new LinkedHashSet<string>();
            RowRecogHelper.RecursiveInspectVariables(expandedPatternNode, false, variablesSingle, variablesMultiple);

            // each variable gets associated with a stream number (multiple-row variables as well to hold the current event for the expression).
            var streamNum = 0;
            var variableStreams = new LinkedHashMap<string, Pair<int, bool>>();
            foreach (var variableSingle in variablesSingle) {
                variableStreams.Put(variableSingle, new Pair<int, bool>(streamNum, false));
                streamNum++;
            }

            foreach (var variableMultiple in variablesMultiple) {
                variableStreams.Put(variableMultiple, new Pair<int, bool>(streamNum, true));
                streamNum++;
            }

            // mapping of stream to variable
            var streamVariables = new OrderedListDictionary<int, string>();
            foreach (var entry in variableStreams) {
                streamVariables.Put(entry.Value.First, entry.Key);
            }

            // determine visibility rules
            var visibility = RowRecogHelper.DetermineVisibility(expandedPatternNode);

            // assemble all single-row variables for expression validation
            var allStreamNames = new string[variableStreams.Count];
            var allTypes = new EventType[variableStreams.Count];

            streamNum = 0;
            foreach (var variableSingle in variablesSingle) {
                allStreamNames[streamNum] = variableSingle;
                allTypes[streamNum] = parentEventType;
                streamNum++;
            }

            foreach (var variableMultiple in variablesMultiple) {
                allStreamNames[streamNum] = variableMultiple;
                allTypes[streamNum] = parentEventType;
                streamNum++;
            }

            // determine type service for use with DEFINE
            // validate each DEFINE clause expression
            ISet<string> definedVariables = new HashSet<string>();
            IList<ExprAggregateNode> aggregateNodes = new List<ExprAggregateNode>();
            var isExprRequiresMultimatchState = new bool[variableStreams.Count];
            var previousNodes = new OrderedListDictionary<int, IList<ExprPreviousMatchRecognizeNode>>();

            for (var defineIndex = 0; defineIndex < matchRecognizeSpec.Defines.Count; defineIndex++) {
                MatchRecognizeDefineItem defineItem = matchRecognizeSpec.Defines[defineIndex];
                if (definedVariables.Contains(defineItem.Identifier)) {
                    throw new ExprValidationException(
                        "Variable '" + defineItem.Identifier + "' has already been defined");
                }

                definedVariables.Add(defineItem.Identifier);

                // stream-type visibilities handled here
                var typeServiceDefines = BuildDefineStreamTypeServiceDefine(
                    defineIndex,
                    variableStreams,
                    defineItem,
                    visibility,
                    parentEventType,
                    statementRawInfo,
                    services);

                var exprNodeResult = HandlePreviousFunctions(defineItem.Expression, previousNodes);
                var validationContext = new ExprValidationContextBuilder(typeServiceDefines, statementRawInfo, services)
                    .WithAllowBindingConsumption(true)
                    .WithDisablePropertyExpressionEventCollCache(true)
                    .Build();

                ExprNode validated;
                try {
                    // validate
                    validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                        ExprNodeOrigin.MATCHRECOGDEFINE,
                        exprNodeResult,
                        validationContext);

                    // check aggregates
                    defineItem.Expression = validated;
                    ExprAggregateNodeUtil.GetAggregatesBottomUp(validated, aggregateNodes);
                    if (!aggregateNodes.IsEmpty()) {
                        throw new ExprValidationException("An aggregate function may not appear in a DEFINE clause");
                    }
                }
                catch (ExprValidationException ex) {
                    throw new ExprValidationException(
                        "Failed to validate condition expression for variable '" +
                        defineItem.Identifier +
                        "': " +
                        ex.Message,
                        ex);
                }

                // determine access to event properties from multi-matches
                var visitor = new ExprNodeStreamRequiredVisitor();
                validated.Accept(visitor);
                var streamsRequired = visitor.StreamsRequired;
                foreach (var streamRequired in streamsRequired) {
                    if (streamRequired >= variableStreams.Count) {
                        var streamNumIdent = variableStreams.Get(defineItem.Identifier).First;
                        isExprRequiresMultimatchState[streamNumIdent] = true;
                        break;
                    }
                }
            }

            var defineAsksMultimatches = CollectionUtil.IsAnySet(isExprRequiresMultimatchState);

            // determine type service for use with MEASURE
            IDictionary<string, object> measureTypeDef = new LinkedHashMap<string, object>();
            foreach (var variableSingle in variablesSingle) {
                measureTypeDef.Put(variableSingle, parentEventType);
            }

            foreach (var variableMultiple in variablesMultiple) {
                measureTypeDef.Put(variableMultiple, new[] {parentEventType});
            }

            var compositeTypeName = services.EventTypeNameGeneratorStatement.AnonymousRowrecogCompositeName;
            var compositeTypeMetadata = new EventTypeMetadata(
                compositeTypeName,
                @base.ModuleName,
                EventTypeTypeClass.MATCHRECOGDERIVED,
                EventTypeApplicationType.OBJECTARR,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var compositeEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                compositeTypeMetadata,
                measureTypeDef,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(compositeEventType);
            StreamTypeService compositeTypeServiceMeasure =
                new StreamTypeServiceImpl(compositeEventType, "MATCH_RECOGNIZE", true);

            // find MEASURE clause aggregations
            var measureReferencesMultivar = false;
            IList<ExprAggregateNode> measureAggregateExprNodes = new List<ExprAggregateNode>();
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                ExprAggregateNodeUtil.GetAggregatesBottomUp(measureItem.Expr, measureAggregateExprNodes);
            }

            AggregationServiceForgeDesc[] aggregationServices = null;
            if (!measureAggregateExprNodes.IsEmpty()) {
                aggregationServices = PlanAggregations(
                    measureAggregateExprNodes,
                    compositeTypeServiceMeasure,
                    allStreamNames,
                    allTypes,
                    streamVariables,
                    variablesMultiple,
                    @base,
                    services);
                foreach (AggregationServiceForgeDesc svc in aggregationServices) {
                    if (svc != null) {
                        additionalForgeables.AddAll(svc.AdditionalForgeables);
                    }
                }
            }

            // validate each MEASURE clause expression
            IDictionary<string, object> rowTypeDef = new LinkedHashMap<string, object>();
            var streamRefVisitor = new ExprNodeStreamUseCollectVisitor();
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                if (measureItem.Name == null) {
                    throw new ExprValidationException(
                        "The measures clause requires that each expression utilizes the AS keyword to assign a column name");
                }

                var validated = ValidateMeasureClause(
                    measureItem.Expr,
                    compositeTypeServiceMeasure,
                    variablesMultiple,
                    variablesSingle,
                    statementRawInfo,
                    services);
                measureItem.Expr = validated;
                rowTypeDef.Put(measureItem.Name, validated.Forge.EvaluationType);
                validated.Accept(streamRefVisitor);
            }

            // Determine if any of the multi-var streams are referenced in the measures (non-aggregated only)
            foreach (var @ref in streamRefVisitor.Referenced) {
                var rootPropName = @ref.RootPropertyNameIfAny;
                if (rootPropName != null) {
                    if (variablesMultiple.Contains(rootPropName)) {
                        measureReferencesMultivar = true;
                        break;
                    }
                }

                var streamRequired = @ref.StreamReferencedIfAny;
                if (streamRequired != null) {
                    var streamVariable = streamVariables.Get(streamRequired.Value);
                    if (streamVariable != null) {
                        var def = variableStreams.Get(streamVariable);
                        if (def != null && def.Second) {
                            measureReferencesMultivar = true;
                            break;
                        }
                    }
                }
            }

            var collectMultimatches = measureReferencesMultivar || defineAsksMultimatches;

            // create rowevent type
            var rowTypeName = services.EventTypeNameGeneratorStatement.AnonymousRowrecogRowName;
            var rowTypeMetadata = new EventTypeMetadata(
                rowTypeName,
                @base.ModuleName,
                EventTypeTypeClass.MATCHRECOGDERIVED,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var rowEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                rowTypeMetadata,
                rowTypeDef,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(rowEventType);

            // validate partition-by expressions, if any
            ExprNode[] partitionBy;
            MultiKeyClassRef partitionMultiKey;
            if (!matchRecognizeSpec.PartitionByExpressions.IsEmpty()) {
                StreamTypeService typeServicePartition = new StreamTypeServiceImpl(
                    parentEventType,
                    "MATCH_RECOGNIZE_PARTITION",
                    true);
                IList<ExprNode> validated = new List<ExprNode>();
                var validationContext =
                    new ExprValidationContextBuilder(typeServicePartition, statementRawInfo, services)
                        .WithAllowBindingConsumption(true)
                        .Build();
                foreach (var partitionExpr in matchRecognizeSpec.PartitionByExpressions) {
                    validated.Add(
                        ExprNodeUtilityValidate.GetValidatedSubtree(
                            ExprNodeOrigin.MATCHRECOGPARTITION,
                            partitionExpr,
                            validationContext));
                }

                matchRecognizeSpec.PartitionByExpressions = validated;
                partitionBy = ExprNodeUtilityQuery.ToArray(validated);
                MultiKeyPlan multiKeyPlan = MultiKeyPlanner.PlanMultiKey(partitionBy, false, @base.StatementRawInfo, services.SerdeResolver);
                partitionMultiKey = multiKeyPlan.ClassRef;
                additionalForgeables.AddAll(multiKeyPlan.MultiKeyForgeables);
            }
            else {
                partitionBy = null;
                partitionMultiKey = null;
            }

            // validate interval if present
            if (matchRecognizeSpec.Interval != null) {
                var validationContext =
                    new ExprValidationContextBuilder(new StreamTypeServiceImpl(false), statementRawInfo, services)
                        .WithAllowBindingConsumption(true)
                        .Build();
                var validated = (ExprTimePeriod) ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.MATCHRECOGINTERVAL,
                    matchRecognizeSpec.Interval.TimePeriodExpr,
                    validationContext);
                matchRecognizeSpec.Interval.TimePeriodExpr = validated;
            }

            // compile variable definition expressions
            IDictionary<string, ExprNode> variableDefinitions = new Dictionary<string, ExprNode>();
            foreach (var defineItem in matchRecognizeSpec.Defines) {
                variableDefinitions.Put(defineItem.Identifier, defineItem.Expression);
            }

            // create evaluators
            var columnNames = new string[matchRecognizeSpec.Measures.Count];
            var columnForges = new ExprNode[matchRecognizeSpec.Measures.Count];
            var count = 0;
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                columnNames[count] = measureItem.Name;
                columnForges[count] = measureItem.Expr;
                count++;
            }

            // build states
            var strand = RowRecogHelper.BuildStartStates(
                expandedPatternNode,
                variableDefinitions,
                variableStreams,
                isExprRequiresMultimatchState);
            var startStates = strand.StartStates.ToArray();
            RowRecogNFAStateForge[] allStates = strand.AllStates.ToArray();

            if (Log.IsInfoEnabled) {
                Log.Info("NFA tree:\n" + RowRecogNFAViewUtil.Print(startStates));
            }

            // determine names of multimatching variables
            string[] multimatchVariablesArray;
            int[] multimatchStreamNumToVariable;
            int[] multimatchVariableToStreamNum;
            if (variablesSingle.Count == variableStreams.Count) {
                multimatchVariablesArray = new string[0];
                multimatchStreamNumToVariable = new int[0];
                multimatchVariableToStreamNum = new int[0];
            }
            else {
                multimatchVariablesArray = new string[variableStreams.Count - variablesSingle.Count];
                multimatchVariableToStreamNum = new int[multimatchVariablesArray.Length];
                multimatchStreamNumToVariable = new int[variableStreams.Count];
                CompatExtensions.Fill(multimatchStreamNumToVariable, -1);
                count = 0;
                foreach (var entry in variableStreams) {
                    if (entry.Value.Second) {
                        var index = count;
                        multimatchVariablesArray[index] = entry.Key;
                        multimatchVariableToStreamNum[index] = entry.Value.First;
                        multimatchStreamNumToVariable[entry.Value.First] = index;
                        count++;
                    }
                }
            }

            var numEventsEventsPerStreamDefine =
                defineAsksMultimatches ? variableStreams.Count + 1 : variableStreams.Count;

            // determine interval-or-terminated
            var orTerminated = matchRecognizeSpec.Interval != null && matchRecognizeSpec.Interval.IsOrTerminated;
            TimePeriodComputeForge intervalCompute = null;
            if (matchRecognizeSpec.Interval != null) {
                intervalCompute = matchRecognizeSpec.Interval.TimePeriodExpr.TimePeriodComputeForge;
            }

            EventType multimatchEventType = null;
            if (defineAsksMultimatches) {
                multimatchEventType = GetDefineMultimatchEventType(variableStreams, parentEventType, @base, services);
            }

            // determine previous-access indexes and assign "prev" node indexes
            // Since an expression such as "prior(2, price), prior(8, price)" translates into {2, 8} the relative index is {0, 1}.
            // Map the expression-supplied index to a relative index
            int[] previousRandomAccessIndexes = null;
            if (!previousNodes.IsEmpty()) {
                previousRandomAccessIndexes = new int[previousNodes.Count];
                var countPrev = 0;
                foreach (var entry in previousNodes) {
                    previousRandomAccessIndexes[countPrev] = entry.Key;
                    foreach (var callback in entry.Value) {
                        callback.AssignedIndex = countPrev;
                    }

                    countPrev++;
                }
            }

            RowRecogDescForge forge = new RowRecogDescForge(
                parentEventType,
                rowEventType,
                compositeEventType,
                multimatchEventType,
                multimatchStreamNumToVariable,
                multimatchVariableToStreamNum,
                partitionBy,
                partitionMultiKey,
                variableStreams,
                matchRecognizeSpec.Interval != null,
                iterateOnly,
                unbound,
                orTerminated,
                collectMultimatches,
                defineAsksMultimatches,
                numEventsEventsPerStreamDefine,
                multimatchVariablesArray,
                startStates,
                allStates,
                matchRecognizeSpec.IsAllMatches,
                matchRecognizeSpec.Skip.Skip,
                columnForges,
                columnNames,
                intervalCompute,
                previousRandomAccessIndexes,
                aggregationServices);
            
            return new RowRecogPlan(forge, additionalForgeables);
        }
示例#20
0
        public static ViewResourceDelegateDesc[] VerifyPreviousAndPriorRequirements(
            IList<ViewFactoryForge>[] unmaterializedViewChain,
            ViewResourceDelegateExpr @delegate)
        {
            var numStreams = unmaterializedViewChain.Length;
            var perStream = new ViewResourceDelegateDesc[numStreams];

            // verify "previous"
            var previousPerStream = new bool[numStreams];
            foreach (ExprPreviousNode previousNode in @delegate.PreviousRequests) {
                var stream = previousNode.StreamNumber;
                var forges = unmaterializedViewChain[stream];

                var pass = InspectViewFactoriesForPrevious(forges);
                if (!pass) {
                    throw new ExprValidationException(
                        "Previous function requires a single data window view onto the stream");
                }

                var found = FindDataWindow(forges);
                if (!found) {
                    throw new ExprValidationException(
                        "Required data window not found for the 'prev' function, specify a data window for which previous events are retained");
                }

                previousPerStream[stream] = true;
            }

            // determine 'prior' indexes
            var priorPerStream = new IOrderedDictionary<int, IList<ExprPriorNode>>[numStreams];
            foreach (var priorNode in @delegate.PriorRequests) {
                var stream = priorNode.StreamNumber;

                if (priorPerStream[stream] == null) {
                    priorPerStream[stream] = new OrderedListDictionary<int, IList<ExprPriorNode>>();
                }

                var treemap = priorPerStream[stream];
                var callbackList = treemap.Get(priorNode.ConstantIndexNumber);
                if (callbackList == null) {
                    callbackList = new List<ExprPriorNode>();
                    treemap.Put(priorNode.ConstantIndexNumber, callbackList);
                }

                callbackList.Add(priorNode);
            }

            // when a given stream has multiple 'prior' nodes, assign a relative index
            for (var i = 0; i < numStreams; i++) {
                if (priorPerStream[i] != null) {
                    var relativeIndex = 0;
                    foreach (var entry in priorPerStream[i]) {
                        foreach (var node in entry.Value) {
                            node.RelativeIndex = relativeIndex;
                        }

                        relativeIndex++;
                    }
                }
            }

            // build per-stream info
            for (var i = 0; i < numStreams; i++) {
                if (priorPerStream[i] == null) {
                    priorPerStream[i] = new OrderedListDictionary<int, IList<ExprPriorNode>>();
                }

                perStream[i] = new ViewResourceDelegateDesc(
                    previousPerStream[i],
                    new SortedSet<int>(priorPerStream[i].Keys));
            }

            return perStream;
        }