Example #1
0
        public void Run(RegressionEnvironment env)
        {
            var plainFilter = "@Name('s0') select count(*) as mycount from SupportBean";

            tryCount(env, 2, 1000, plainFilter, GeneratorEnumerator.DEFAULT_SUPPORTEBEAN_CB);
            tryCount(env, 4, 1000, plainFilter, GeneratorEnumerator.DEFAULT_SUPPORTEBEAN_CB);

            ICollection <string> vals = Arrays.AsList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j");

            GeneratorEnumeratorCallback enumCallback = numEvent => {
                var bean = new SupportCollection();
                bean.Strvals = vals;
                return(bean);
            };

            var enumFilter =
                "@Name('s0') select count(*) as mycount from SupportCollection(Strvals.anyOf(v -> v = 'j'))";

            tryCount(env, 4, 1000, enumFilter, enumCallback);
        }
            public void Run(RegressionEnvironment env)
            {
                string[]           fields  = "c0,c1".SplitCsv();
                SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(fields[0], "Strvals.mostFrequent()");
                builder.WithExpression(fields[1], "Strvals.leastFrequent()");

                builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(string)));

                builder.WithAssertion(SupportCollection.MakeString("E2,E1,E2,E1,E3,E3,E4,E3")).Expect(fields, "E3", "E4");

                builder.WithAssertion(SupportCollection.MakeString("E1")).Expect(fields, "E1", "E1");

                builder.WithAssertion(SupportCollection.MakeString(null)).Expect(fields, null, null);

                builder.WithAssertion(SupportCollection.MakeString("")).Expect(fields, null, null);

                builder.Run(env);
            }
Example #3
0
        public void TestParseSpecialAndMixedExprAndScript()
        {
            var listener = new SupportUpdateListener();

            _epService.EPAdministrator.CreateEPL("create expression string jscript:myscript(p1) [return \"--\"+p1+\"--\"]");
            _epService.EPAdministrator.CreateEPL("create expression myexpr {sb => '--'||TheString||'--'}");

            // test mapped property syntax
            var eplMapped  = "select myscript('x') as c0, myexpr(sb) as c1 from SupportBean as sb";
            var stmtMapped = _epService.EPAdministrator.CreateEPL(eplMapped);

            stmtMapped.Events += listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "c0,c1".Split(','), new Object[] { "--x--", "--E1--" });
            stmtMapped.Dispose();

            // test expression chained syntax
            var eplExpr = "" +
                          "create expression scalarfilter {s => " +
                          "   Strvals.where(y => y != 'E1') " +
                          "}";

            _epService.EPAdministrator.CreateEPL(eplExpr);
            var eplSelect = "select scalarfilter(t).where(x => x != 'E2') as val1 from SupportCollection as t";

            _epService.EPAdministrator.CreateEPL(eplSelect).Events += listener.Update;
            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3,E4"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", "E3", "E4");
            _epService.EPAdministrator.DestroyAllStatements();
            listener.Reset();

            // test script chained syntax
            var beanType  = typeof(SupportBean).FullName;
            var eplScript = $"create expression {beanType} jscript:callIt() [ return host.newObj(host.resolveType('{beanType}'), 'E1', 10); ]";

            _epService.EPAdministrator.CreateEPL(eplScript);
            _epService.EPAdministrator.CreateEPL("select callIt() as val0, callIt().get_TheString() as val1 from SupportBean as sb").Events += listener.Update;
            _epService.EPRuntime.SendEvent(new SupportBean());
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "val0.TheString,val0.IntPrimitive,val1".Split(','), new Object[] { "E1", 10, "E1" });
        }
        private void RunAssertionSetLogicWithScalar(EPServiceProvider epService)
        {
            string epl = "select " +
                         "Strvals.except(Strvalstwo) as val0," +
                         "Strvals.intersect(Strvalstwo) as val1, " +
                         "Strvals.union(Strvalstwo) as val2 " +
                         " from SupportCollection as bean";
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(epl);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;
            LambdaAssertionUtil.AssertTypes(stmt.EventType, "val0".Split(','), new Type[] {
                typeof(ICollection <string>)
            });

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2", "E3,E4"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E2");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", "E1", "E2", "E3", "E4");
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString(null, "E3,E4"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", (object[])null);
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", (object[])null);
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", (object[])null);
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("", "E3,E4"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", "E3", "E4");
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E3,E5", "E3,E4"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E5");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", "E3");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", "E1", "E3", "E5", "E3", "E4");
            listener.Reset();

            stmt.Dispose();
        }
Example #5
0
        public void TestWhereString()
        {
            String[] fields      = "val0,val1".Split(',');
            String   eplFragment = "select " +
                                   "Strvals.Where(x => x not like '%1%') as val0, " +
                                   "Strvals.Where((x, i) => x not like '%1%' and i > 1) as val1 " +
                                   "from SupportCollection";
            EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment);

            stmtFragment.Events += _listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(ICollection <object>), typeof(ICollection <object>) });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3"));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E2", "E3");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", "E3");
            _listener.Reset();

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E4,E2,E1"));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E4", "E2");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", new String[0]);
            _listener.Reset();

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString(""));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", new String[0]);
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", new String[0]);
            _listener.Reset();

            stmtFragment.Dispose();

            // test boolean
            eplFragment = "select " +
                          "Boolvals.Where(x => x) as val0 " +
                          "from SupportCollection";
            stmtFragment         = _epService.EPAdministrator.CreateEPL(eplFragment);
            stmtFragment.Events += _listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val0".Split(','), new Type[] { typeof(ICollection <object>) });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeBoolean("true,true,false"));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", true, true);
            _listener.Reset();
        }
Example #6
0
            public void Run(RegressionEnvironment env)
            {
                string[]           fields  = "c0,c1,c2,c3,c4,c5".SplitCsv();
                SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(fields[0], "Strvals.takeWhile(x => x != 'E1')");
                builder.WithExpression(fields[1], "Strvals.takeWhileLast(x => x != 'E1')");
                builder.WithExpression(fields[2], "Strvals.takeWhile( (x, i) => x != 'E1' and i<2)");
                builder.WithExpression(fields[3], "Strvals.takeWhileLast( (x, i) => x != 'E1' and i<2)");
                builder.WithExpression(fields[4], "Strvals.takeWhile( (x, i, s) => x != 'E1' and i<s-2)");
                builder.WithExpression(fields[5], "Strvals.takeWhileLast( (x, i, s) => x != 'E1' and i<s-2)");

                builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(ICollection <object>)));

                builder.WithAssertion(SupportCollection.MakeString("E1,E2,E3,E4"))
                .Verify("c0", val => AssertValuesArrayScalar(val))
                .Verify("c1", val => AssertValuesArrayScalar(val, "E2", "E3", "E4"))
                .Verify("c2", val => AssertValuesArrayScalar(val))
                .Verify("c3", val => AssertValuesArrayScalar(val, "E3", "E4"))
                .Verify("c4", val => AssertValuesArrayScalar(val))
                .Verify("c5", val => AssertValuesArrayScalar(val, "E3", "E4"));

                builder.WithAssertion(SupportCollection.MakeString("E2"))
                .Verify("c0", val => AssertValuesArrayScalar(val, "E2"))
                .Verify("c1", val => AssertValuesArrayScalar(val, "E2"))
                .Verify("c2", val => AssertValuesArrayScalar(val, "E2"))
                .Verify("c3", val => AssertValuesArrayScalar(val, "E2"))
                .Verify("c4", val => AssertValuesArrayScalar(val))
                .Verify("c5", val => AssertValuesArrayScalar(val));

                builder.WithAssertion(SupportCollection.MakeString("E2,E3,E4,E5"))
                .Verify("c0", val => AssertValuesArrayScalar(val, "E2", "E3", "E4", "E5"))
                .Verify("c1", val => AssertValuesArrayScalar(val, "E2", "E3", "E4", "E5"))
                .Verify("c2", val => AssertValuesArrayScalar(val, "E2", "E3"))
                .Verify("c3", val => AssertValuesArrayScalar(val, "E4", "E5"))
                .Verify("c4", val => AssertValuesArrayScalar(val, "E2", "E3"))
                .Verify("c5", val => AssertValuesArrayScalar(val, "E4", "E5"));

                builder.Run(env);
            }
Example #7
0
        public void TestKeyValueSelector()
        {
            String      eplFragment  = "select contained.GroupBy(k => id, v => p00) as val from Bean";
            EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment);

            stmtFragment.Events += _listener.Update;
            EPAssertionUtil.AssertionCollectionValueString extractor = new EPAssertionUtil.ProxyAssertionCollectionValueString(
                collectionItem => Convert.ToString((int)collectionItem));

            _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,1", "E1,2", "E2,5"));
            EPAssertionUtil.AssertMapOfCollection(
                (GroupMap)_listener.AssertOneGetNewAndReset().Get("val"),
                new String[] { "E1", "E2" },
                new String[] { "1,2", "5" },
                extractor);

            _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null));
            Assert.IsNull(_listener.AssertOneGetNewAndReset().Get("val"));

            _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value());
            Assert.AreEqual(0, ((GroupMap)_listener.AssertOneGetNewAndReset().Get("val")).Count);

            // test scalar
            _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractAfterUnderscore", this.GetType().FullName, "ExtractAfterUnderscore");
            String      eplScalar  = "select Strvals.GroupBy(k => extractAfterUnderscore(k), v => v) as val from SupportCollection";
            EPStatement stmtScalar = _epService.EPAdministrator.CreateEPL(eplScalar);

            stmtScalar.Events += _listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtScalar.EventType, "val".Split(','), new Type[] { typeof(GroupMap) });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1_2,E2_1,E3_2"));
            EPAssertionUtil.AssertMapOfCollection((GroupMap)_listener.AssertOneGetNewAndReset().Get("val"), "2,1".Split(','),
                                                  new String[] { "E1_2,E3_2", "E2_1" }, GetExtractorScalar());

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null));
            Assert.IsNull(_listener.AssertOneGetNewAndReset().Get("val"));

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString(""));
            Assert.AreEqual(0, ((GroupMap)_listener.AssertOneGetNewAndReset().Get("val")).Count);
        }
Example #8
0
        public void TestDistinctScalar()
        {
            _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(TestEnumMinMax.MyService).FullName, "ExtractNum");

            String[] fields      = "val0,val1".Split(',');
            String   eplFragment = "select " +
                                   "Strvals.distinctOf() as val0, " +
                                   "Strvals.distinctOf(v => extractNum(v)) as val1 " +
                                   "from SupportCollection";
            EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment);

            stmtFragment.Events += _listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(ICollection <object>), typeof(ICollection <object>) });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E2,E2"));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E2", "E1");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", "E2", "E1");
            _listener.Reset();

            LambdaAssertionUtil.AssertSingleAndEmptySupportColl(_epService, _listener, fields);
            stmtFragment.Dispose();
        }
Example #9
0
            public void Run(RegressionEnvironment env)
            {
                string[]           fields  = "c0,c1,c2,c3".SplitCsv();
                SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(fields[0], "Strvals.countof()");
                builder.WithExpression(fields[1], "Strvals.countof(x => x = 'E1')");
                builder.WithExpression(fields[2], "Strvals.countof((x, i) => x = 'E1' and i >= 1)");
                builder.WithExpression(fields[3], "Strvals.countof((x, i, s) => x = 'E1' and i >= 1 and s > 2)");

                builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(int?)));

                builder.WithAssertion(SupportCollection.MakeString("E1,E2")).Expect(fields, 2, 1, 0, 0);

                builder.WithAssertion(SupportCollection.MakeString("E1,E2,E1,E3")).Expect(fields, 4, 2, 1, 1);

                builder.WithAssertion(SupportCollection.MakeString("E1")).Expect(fields, 1, 1, 0, 0);

                builder.WithAssertion(SupportCollection.MakeString("E1,E1")).Expect(fields, 2, 2, 1, 0);

                builder.Run(env);
            }
Example #10
0
            public void Run(RegressionEnvironment env)
            {
                string[]           fields  = "c0,c1,c2,c3".SplitCsv();
                SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(fields[0], "Strvals.distinctOf()");
                builder.WithExpression(fields[1], "Strvals.distinctOf(v => extractNum(v))");
                builder.WithExpression(fields[2], "Strvals.distinctOf((v, i) => case when i<2 then extractNum(v) else 0 end)");
                builder.WithExpression(fields[3], "Strvals.distinctOf((v, i, s) => case when s<=2 then extractNum(v) else 0 end)");

                builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(ICollection <object>)));

                builder.WithAssertion(SupportCollection.MakeString("E2,E1,E2,E2"))
                .Verify("c0", val => AssertValuesArrayScalar(val, "E2", "E1"))
                .Verify("c1", val => AssertValuesArrayScalar(val, "E2", "E1"))
                .Verify("c2", val => AssertValuesArrayScalar(val, "E2", "E1", "E2"))
                .Verify("c3", val => AssertValuesArrayScalar(val, "E2"));

                LambdaAssertionUtil.AssertSingleAndEmptySupportColl(builder, fields);

                builder.Run(env);
            }
Example #11
0
            public void Run(RegressionEnvironment env)
            {
                string[]           fields  = "c0".SplitCsv();
                SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(fields[0], "Strvals.sequenceEqual(Strvalstwo)");

                builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(bool?)));

                builder.WithAssertion(SupportCollection.MakeString("E1,E2,E3", "E1,E2,E3")).Expect(fields, true);

                builder.WithAssertion(SupportCollection.MakeString("E1,E3", "E1,E2,E3")).Expect(fields, false);

                builder.WithAssertion(SupportCollection.MakeString("E1,E3", "E1,E3")).Expect(fields, true);

                builder.WithAssertion(SupportCollection.MakeString("E1,E2,E3", "E1,E3")).Expect(fields, false);

                builder.WithAssertion(SupportCollection.MakeString("E1,E2,null,E3", "E1,E2,null,E3")).Expect(fields, true);

                builder.WithAssertion(SupportCollection.MakeString("E1,E2,E3", "E1,E2,null")).Expect(fields, false);

                builder.WithAssertion(SupportCollection.MakeString("E1,E2,null", "E1,E2,E3")).Expect(fields, false);

                builder.WithAssertion(SupportCollection.MakeString("E1", "")).Expect(fields, false);

                builder.WithAssertion(SupportCollection.MakeString("", "E1")).Expect(fields, false);

                builder.WithAssertion(SupportCollection.MakeString("E1", "E1")).Expect(fields, true);

                builder.WithAssertion(SupportCollection.MakeString("", "")).Expect(fields, true);

                builder.WithAssertion(SupportCollection.MakeString(null, "")).Expect(fields, new object[] { null });

                builder.WithAssertion(SupportCollection.MakeString("", null)).Expect(fields, false);

                builder.WithAssertion(SupportCollection.MakeString(null, null)).Expect(fields, new object[] { null });

                builder.Run(env);
            }
Example #12
0
        private void RunAssertionTakeScalar(EPServiceProvider epService)
        {
            string[] fields = "val0,val1,val2,val3".Split(',');
            string   epl    = "select " +
                              "Strvals.take(2) as val0," +
                              "Strvals.take(1) as val1," +
                              "Strvals.takeLast(2) as val2," +
                              "Strvals.takeLast(1) as val3" +
                              " from SupportCollection";
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(epl);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;
            LambdaAssertionUtil.AssertTypes(stmt.EventType, fields, new Type[] {
                typeof(ICollection <string>),
                typeof(ICollection <string>),
                typeof(ICollection <string>),
                typeof(ICollection <string>)
            });

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E2");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", "E1");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", "E2", "E3");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val3", "E3");
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E2");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", "E1");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", "E1", "E2");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val3", "E2");
            listener.Reset();

            LambdaAssertionUtil.AssertSingleAndEmptySupportColl(epService, listener, fields);

            stmt.Dispose();
        }
Example #13
0
        private void RunAssertionCountOfScalar(EPServiceProvider epService)
        {
            var    fields      = new string[] { "val0", "val1" };
            string eplFragment = "select " +
                                 "Strvals.countof() as val0, " +
                                 "Strvals.countof(x => x = 'E1') as val1 " +
                                 " from SupportCollection";
            EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment);
            var         listener     = new SupportUpdateListener();

            stmtFragment.Events += listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] {
                typeof(int), typeof(int)
            });

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2, 1 });

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E1,E3"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 4, 2 });

            stmtFragment.Dispose();
        }
Example #14
0
            public void Run(RegressionEnvironment env)
            {
                string             field   = "c0";
                SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(field, "Strvals.selectFrom(v => extractNum(v))");

                builder.WithStatementConsumer(stmt => AssertTypes(stmt.EventType, field, typeof(ICollection <object>)));

                builder.WithAssertion(SupportCollection.MakeString("E2,E1,E5,E4"))
                .Verify(field, value => AssertValuesArrayScalar(value, 2, 1, 5, 4));

                builder.WithAssertion(SupportCollection.MakeString("E1"))
                .Verify(field, value => AssertValuesArrayScalar(value, 1));

                builder.WithAssertion(SupportCollection.MakeString(null))
                .Verify(field, Assert.IsNull);

                builder.WithAssertion(SupportCollection.MakeString(""))
                .Verify(field, value => AssertValuesArrayScalar(value));

                builder.Run(env);
            }
Example #15
0
        public static void AssertSingleAndEmptySupportColl(EPServiceProvider epService, SupportUpdateListener listener, String[] fields)
        {
            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1"));
            foreach (string field in fields)
            {
                LambdaAssertionUtil.AssertValuesArrayScalar(listener, field, "E1");
            }
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString(null));
            foreach (string field in fields)
            {
                LambdaAssertionUtil.AssertValuesArrayScalar(listener, field, null);
            }
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString(""));
            foreach (string field in fields)
            {
                LambdaAssertionUtil.AssertValuesArrayScalar(listener, field);
            }
            listener.Reset();
        }
Example #16
0
            public void Run(RegressionEnvironment env)
            {
                string[]           fields  = "c0,c1,c2,c3,c4,c5".SplitCsv();
                SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(fields[0], "Strvals.allof(v => v='A')");
                builder.WithExpression(fields[1], "Strvals.anyof(v => v='A')");
                builder.WithExpression(fields[2], "Strvals.allof((v, i) => (v='A' and i < 2) or (v='C' and i >= 2))");
                builder.WithExpression(fields[3], "Strvals.anyof((v, i) => (v='A' and i < 2) or (v='C' and i >= 2))");
                builder.WithExpression(fields[4], "Strvals.allof((v, i, s) => (v='A' and i < s - 2) or (v='C' and i >= s - 2))");
                builder.WithExpression(fields[5], "Strvals.anyof((v, i, s) => (v='A' and i < s - 2) or (v='C' and i >= s - 2))");

                builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(bool?)));

                builder.WithAssertion(SupportCollection.MakeString("B,A,C"))
                .Expect(fields, false, true, false, true, false, true);

                builder.WithAssertion(SupportCollection.MakeString(null))
                .Expect(fields, null, null, null, null, null, null);

                builder.WithAssertion(SupportCollection.MakeString("A,A"))
                .Expect(fields, true, true, true, true, false, false);

                builder.WithAssertion(SupportCollection.MakeString("B"))
                .Expect(fields, false, false, false, false, false, false);

                builder.WithAssertion(SupportCollection.MakeString(""))
                .Expect(fields, true, false, true, false, true, false);

                builder.WithAssertion(SupportCollection.MakeString("B,B,B"))
                .Expect(fields, false, false, false, false, false, false);

                builder.WithAssertion(SupportCollection.MakeString("A,A,C,C"))
                .Expect(fields, false, true, true, true, true, true);

                builder.Run(env);
            }
Example #17
0
            public void Run(RegressionEnvironment env)
            {
                var fields  = "c0,c1,c2,c3,c4,c5".SplitCsv();
                var builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(fields[0], "Strvals.average(v => extractNum(v))");
                builder.WithExpression(fields[1], "Strvals.average(v => extractDecimal(v))");
                builder.WithExpression(fields[2], "Strvals.average( (v, i) => extractNum(v) + i*10)");
                builder.WithExpression(fields[3], "Strvals.average( (v, i) => extractDecimal(v) + i*10)");
                builder.WithExpression(fields[4], "Strvals.average( (v, i, s) => extractNum(v) + i*10 + s*100)");
                builder.WithExpression(fields[5], "Strvals.average( (v, i, s) => extractDecimal(v) + i*10 + s*100)");

                builder.WithStatementConsumer(
                    stmt => AssertTypes(
                        stmt.EventType,
                        fields,
                        new[] { typeof(double?), typeof(decimal?), typeof(double?), typeof(decimal?), typeof(double?), typeof(decimal?) }));

                builder.WithAssertion(SupportCollection.MakeString("E2,E1,E5,E4"))
                .Expect(
                    fields,
                    (2 + 1 + 5 + 4) / 4d,
                    (2 + 1 + 5 + 4) / 4m,
                    (2 + 11 + 25 + 34) / 4d,
                    (2 + 11 + 25 + 34) / 4m,
                    (402 + 411 + 425 + 434) / 4d,
                    (402 + 411 + 425 + 434) / 4m);

                builder.WithAssertion(SupportCollection.MakeString("E1"))
                .Expect(fields, 1d, 1m, 1d, 1m, 101d, 101m);

                builder.WithAssertion(SupportCollection.MakeString(null)).Expect(fields, null, null, null, null, null, null);

                builder.WithAssertion(SupportCollection.MakeString("")).Expect(fields, null, null, null, null, null, null);

                builder.Run(env);
            }
Example #18
0
        public void TestTakeScalar()
        {
            String[] fields = "val0,val1,val2,val3".Split(',');
            String   epl    = "select " +
                              "Strvals.Take(2) as val0," +
                              "Strvals.Take(1) as val1," +
                              "Strvals.TakeLast(2) as val2," +
                              "Strvals.TakeLast(1) as val3" +
                              " from SupportCollection";
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.Events += _listener.Update;
            LambdaAssertionUtil.AssertTypes(stmt.EventType, fields, new Type[]
            {
                typeof(ICollection <string>),
                typeof(ICollection <string>),
                typeof(ICollection <string>),
                typeof(ICollection <string>)
            });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3"));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E1", "E2");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", "E1");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val2", "E2", "E3");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val3", "E3");
            _listener.Reset();

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2"));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E1", "E2");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", "E1");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val2", "E1", "E2");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val3", "E2");
            _listener.Reset();

            LambdaAssertionUtil.AssertSingleAndEmptySupportColl(_epService, _listener, fields);
        }
Example #19
0
            public void Run(RegressionEnvironment env)
            {
                string[]           fields  = "c0,c1,c2".SplitCsv();
                SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(fields[0], "Strvals.groupBy(k => extractAfterUnderscore(k), v => v)");
                builder.WithExpression(
                    fields[1],
                    "Strvals.groupBy((k, i) => extractAfterUnderscore(k) || '_' || Convert.ToString(i), (v, i) => v || '_' || Convert.ToString(i))");
                builder.WithExpression(
                    fields[2],
                    "Strvals.groupBy((k, i, s) => extractAfterUnderscore(k) || '_' || Convert.ToString(i) || '_' || Convert.ToString(s), (v, i, s) => v || '_' || Convert.ToString(i) || '_' || Convert.ToString(s))");

                builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(IDictionary <object, object>)));

                builder.WithAssertion(SupportCollection.MakeString("E1_2,E2_1,E3_2"))
                .Verify("c0", val => CompareMaps(val, "2,1", new[] { "E1_2,E3_2", "E2_1" }, GetExtractorScalar()))
                .Verify("c1", val => CompareMaps(val, "2_0,1_1,2_2", new[] { "E1_2_0", "E2_1_1", "E3_2_2" }, GetExtractorScalar()))
                .Verify("c2", val => CompareMaps(val, "2_0_3,1_1_3,2_2_3", new[] { "E1_2_0_3", "E2_1_1_3", "E3_2_2_3" }, GetExtractorScalar()));

                SupportEvalAssertionBuilder assertionNull = builder.WithAssertion(SupportCollection.MakeString(null));

                foreach (string field in fields)
                {
                    assertionNull.Verify(field, Assert.IsNull);
                }

                SupportEvalAssertionBuilder assertionEmpty = builder.WithAssertion(SupportCollection.MakeString(""));

                foreach (string field in fields)
                {
                    assertionEmpty.Verify(field, val => CompareMaps(val, "", new string[0], GetExtractorScalar()));
                }

                builder.Run(env);
            }
Example #20
0
            public void Run(RegressionEnvironment env)
            {
                string[]           fields  = "c0,c1,c2".SplitCsv();
                SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(fields[0], "Strvals.aggregate('', (result, item) => result || '+' || item)");
                builder.WithExpression(fields[1], "Strvals.aggregate('', (result, item, i) => result || '+' || item || '_' || Convert.ToString(i))");
                builder.WithExpression(
                    fields[2],
                    "Strvals.aggregate('', (result, item, i, s) => result || '+' || item || '_' || Convert.ToString(i) || '_' || Convert.ToString(s))");

                builder.WithStatementConsumer(stmt => LambdaAssertionUtil.AssertTypesAllSame(stmt.EventType, fields, typeof(string)));

                builder.WithAssertion(SupportCollection.MakeString("E1,E2,E3"))
                .Expect(fields, "+E1+E2+E3", "+E1_0+E2_1+E3_2", "+E1_0_3+E2_1_3+E3_2_3");

                builder.WithAssertion(SupportCollection.MakeString("E1")).Expect(fields, "+E1", "+E1_0", "+E1_0_1");

                builder.WithAssertion(SupportCollection.MakeString("")).Expect(fields, "", "", "");

                builder.WithAssertion(SupportCollection.MakeString(null)).Expect(fields, null, null, null);

                builder.Run(env);
            }
Example #21
0
        public void TestMinMaxScalar()
        {
            String[] fields      = "val0,val1".Split(',');
            String   eplFragment = "select " +
                                   "Strvals.min() as val0, " +
                                   "Strvals.Max() as val1 " +
                                   "from SupportCollection";
            EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment);

            stmtFragment.Events += _listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(string), typeof(string) });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", "E5" });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", "E1" });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString(""));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null });
        }
            public void Run(RegressionEnvironment env)
            {
                string[]           fields  = "c0,c1,c2,c3,c4,c5".SplitCsv();
                SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection");

                builder.WithExpression(fields[0], "Strvals.mostFrequent(v => extractNum(v))");
                builder.WithExpression(fields[1], "Strvals.leastFrequent(v => extractNum(v))");
                builder.WithExpression(fields[2], "Strvals.mostFrequent( (v, i) => extractNum(v) + i*10)");
                builder.WithExpression(fields[3], "Strvals.leastFrequent( (v, i) => extractNum(v) + i*10)");
                builder.WithExpression(fields[4], "Strvals.mostFrequent( (v, i, s) => extractNum(v) + i*10 + s*100)");
                builder.WithExpression(fields[5], "Strvals.leastFrequent( (v, i, s) => extractNum(v) + i*10 + s*100)");

                builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(int?)));

                builder.WithAssertion(SupportCollection.MakeString("E2,E1,E2,E1,E3,E3,E4,E3")).Expect(fields, 3, 4, 2, 2, 802, 802);

                builder.WithAssertion(SupportCollection.MakeString("E1")).Expect(fields, 1, 1, 1, 1, 101, 101);

                builder.WithAssertion(SupportCollection.MakeString(null)).Expect(fields, null, null, null, null, null, null);

                builder.WithAssertion(SupportCollection.MakeString("")).Expect(fields, null, null, null, null, null, null);

                builder.Run(env);
            }
Example #23
0
        public void TestAggregateScalar()
        {
            String[] fields      = "val0".Split(',');
            String   eplFragment = "select " +
                                   "Strvals.Aggregate('', (result, item) => result || '+' || item) as val0 " +
                                   "from SupportCollection";
            EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment);

            stmtFragment.Events += _listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(string) });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "+E1+E2+E3" });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "+E1" });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString(""));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "" });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null });
            stmtFragment.Dispose();
        }
Example #24
0
        private void RunAssertionSumOfScalar(EPServiceProvider epService)
        {
            string[] fields      = "val0,val1".Split(',');
            string   eplFragment = "select " +
                                   "Intvals.sumOf() as val0, " +
                                   "Bdvals.sumOf() as val1 " +
                                   "from SupportCollection";
            EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment);
            var         listener     = new SupportUpdateListener();

            stmtFragment.Events += listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] {
                typeof(int?), typeof(decimal?)
            });

            epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric("1,4,5"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1 + 4 + 5, 1m + 4m + 5m });

            epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric("3,4"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 3 + 4, 3m + 4m });

            epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric("3"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 3, 3m });

            epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric(""));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null });

            epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric(null));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null });

            stmtFragment.Dispose();

            // test average with lambda
            epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(ExecEnumMinMax.MyService), "ExtractNum");
            epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractDecimal", typeof(ExecEnumMinMax.MyService), "ExtractDecimal");

            // lambda with string-array input
            string[] fieldsLambda = "val0,val1".Split(',');
            string   eplLambda    = "select " +
                                    "Strvals.sumOf(v => extractNum(v)) as val0, " +
                                    "Strvals.sumOf(v => extractDecimal(v)) as val1 " +
                                    "from SupportCollection";
            EPStatement stmtLambda = epService.EPAdministrator.CreateEPL(eplLambda);

            stmtLambda.Events += listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fieldsLambda, new Type[] { typeof(int?), typeof(decimal?) });

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsLambda, new object[] { 2 + 1 + 5 + 4, 2m + 1m + 5m + 4m });

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsLambda, new object[] { 1, 1m });

            epService.EPRuntime.SendEvent(SupportCollection.MakeString(null));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsLambda, new object[] { null, null });

            epService.EPRuntime.SendEvent(SupportCollection.MakeString(""));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsLambda, new object[] { null, null });

            stmtLambda.Dispose();
        }
Example #25
0
        public void TestMinMaxBy()
        {
            String[] fields      = "val0,val1,val2,val3".SplitCsv();
            String   eplFragment = "select " +
                                   "contained.MinBy(x => p00) as val0," +
                                   "contained.MaxBy(x => p00) as val1," +
                                   "contained.MinBy(x => p00).id as val2," +
                                   "contained.MaxBy(x => p00).P00 as val3 " +
                                   "from Bean";
            EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment);

            stmtFragment.Events += _listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(SupportBean_ST0), typeof(SupportBean_ST0), typeof(string), typeof(int?) });

            SupportBean_ST0_Container bean = SupportBean_ST0_Container.Make2Value("E1,12", "E2,11", "E2,2");

            _epService.EPRuntime.SendEvent(bean);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields,
                                        new Object[] { bean.Contained[2], bean.Contained[0], "E2", 12 });

            bean = SupportBean_ST0_Container.Make2Value("E1,12");
            _epService.EPRuntime.SendEvent(bean);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields,
                                        new Object[] { bean.Contained[0], bean.Contained[0], "E1", 12 });

            _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields,
                                        new Object[] { null, null, null, null });

            _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value());
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields,
                                        new Object[] { null, null, null, null });

            stmtFragment.Dispose();

            // test scalar-coll with lambda
            String[] fieldsLambda = "val0,val1".Split(',');
            _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(TestEnumMinMax.MyService).FullName, "ExtractNum");
            String eplLambda = "select " +
                               "Strvals.minBy(v => extractNum(v)) as val0, " +
                               "Strvals.maxBy(v => extractNum(v)) as val1 " +
                               "from SupportCollection";
            EPStatement stmtLambda = _epService.EPAdministrator.CreateEPL(eplLambda);

            stmtLambda.Events += _listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fieldsLambda, new [] { typeof(string), typeof(string) });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsLambda, new Object[] { "E1", "E5" });

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsLambda, new Object[] { "E1", "E1" });
            _listener.Reset();

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsLambda, new Object[] { null, null });
            _listener.Reset();

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString(""));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsLambda, new Object[] { null, null });
        }