Ejemplo n.º 1
0
        public void TestTakeWhileScalar()
        {
            String[] fields = "val0,val1,val2,val3".Split(',');
            String   epl    = "select " +
                              "Strvals.TakeWhile(x => x != 'E1') as val0," +
                              "Strvals.TakeWhile( (x, i) => x != 'E1' and i<2) as val1," +
                              "Strvals.TakeWhileLast(x => x != 'E1') as val2," +
                              "Strvals.TakeWhileLast( (x, i) => x != 'E1' and i<2) as val3" +
                              " from SupportCollection";
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl);

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

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3,E4"));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val2", "E2", "E3", "E4");
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val3", "E3", "E4");
            _listener.Reset();
        }
Ejemplo n.º 2
0
        private void RunAssertionDistinctScalar(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(ExecEnumMinMax.MyService), "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);
            var         listener     = new SupportUpdateListener();

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

            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();
        }
        private void RunAssertionTakeWhileScalar(EPServiceProvider epService)
        {
            string[] fields = "val0,val1,val2,val3".Split(',');
            string   epl    = "select " +
                              "Strvals.takeWhile(x => x != 'E1') as val0," +
                              "Strvals.takeWhile( (x, i) => x != 'E1' and i<2) as val1," +
                              "Strvals.takeWhileLast(x => x != 'E1') as val2," +
                              "Strvals.takeWhileLast( (x, i) => x != 'E1' and i<2) 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,E4"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", "E2", "E3", "E4");
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val3", "E3", "E4");
            listener.Reset();

            stmt.Dispose();
        }
Ejemplo n.º 4
0
        private void RunAssertionPrevWindowSorted(EPServiceProvider epService)
        {
            var stmt = epService.EPAdministrator.CreateEPL(
                "select prevwindow(st0) as val0, prevwindow(st0).EsperInternalNoop() as val1 " +
                "from SupportBean_ST0#sort(3, p00 asc) as st0");
            var listener = new SupportUpdateListener();
            stmt.Events += listener.Update;
            LambdaAssertionUtil.AssertTypes(
                stmt.EventType, "val0,val1".Split(','), new[] {
                    typeof(SupportBean_ST0[]),
                    typeof(ICollection<SupportBean_ST0>)
                });

            epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 5));
            LambdaAssertionUtil.AssertST0Id(listener, "val1", "E1");
            listener.Reset();

            epService.EPRuntime.SendEvent(new SupportBean_ST0("E2", 6));
            LambdaAssertionUtil.AssertST0Id(listener, "val1", "E1,E2");
            listener.Reset();

            epService.EPRuntime.SendEvent(new SupportBean_ST0("E3", 4));
            LambdaAssertionUtil.AssertST0Id(listener, "val1", "E3,E1,E2");
            listener.Reset();

            epService.EPRuntime.SendEvent(new SupportBean_ST0("E5", 3));
            LambdaAssertionUtil.AssertST0Id(listener, "val1", "E5,E3,E1");
            listener.Reset();
            stmt.Dispose();

            // Scalar version
            var fields = new[] {"val0"};
            var stmtScalar = epService.EPAdministrator.CreateEPL(
                "select prevwindow(id).where(x => x not like '%ignore%') as val0 " +
                "from SupportBean_ST0#keepall as st0");
            stmtScalar.Events += listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtScalar.EventType, fields, new[] {
                typeof(ICollection<string>)
            });

            epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 5));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1");
            listener.Reset();

            epService.EPRuntime.SendEvent(new SupportBean_ST0("E2ignore", 6));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1");
            listener.Reset();

            epService.EPRuntime.SendEvent(new SupportBean_ST0("E3", 4));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E3", "E1");
            listener.Reset();

            epService.EPRuntime.SendEvent(new SupportBean_ST0("ignoreE5", 3));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E3", "E1");
            listener.Reset();

            stmtScalar.Dispose();
        }
Ejemplo n.º 5
0
        private void RunAssertionSelect(EPServiceProvider epService)
        {
            string eplFragment = "select " +
                                 "Contained.selectFrom(x => id) as val0 " +
                                 "from Bean";
            EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment);
            var         listener     = new SupportUpdateListener();

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

            epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,12", "E2,11", "E3,2"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E2", "E3");
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", null);
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value());
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", new string[0]);
            listener.Reset();
            stmtFragment.Dispose();

            // test scalar-coll with lambda
            string[] fields = "val0".Split(',');
            epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(ExecEnumMinMax.MyService), "ExtractNum");
            string eplLambda = "select " +
                               "Strvals.selectFrom(v => extractNum(v)) as val0 " +
                               "from SupportCollection";
            EPStatement stmtLambda = epService.EPAdministrator.CreateEPL(eplLambda);

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

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", 2, 1, 5, 4);
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", 1);
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString(null));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", null);
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString(""));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0");

            stmtLambda.Dispose();
        }
Ejemplo n.º 6
0
        public void TestPrevWindowSorted()
        {
            var stmt = _epService.EPAdministrator.CreateEPL("select Prevwindow(st0) as val0, Prevwindow(st0).EsperInternalNoop() as val1 " +
                                                            "from SupportBean_ST0.ext:sort(3, p00 asc) as st0");

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

            _epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 5));
            LambdaAssertionUtil.AssertST0Id(_listener, "val1", "E1");
            _listener.Reset();

            _epService.EPRuntime.SendEvent(new SupportBean_ST0("E2", 6));
            LambdaAssertionUtil.AssertST0Id(_listener, "val1", "E1,E2");
            _listener.Reset();

            _epService.EPRuntime.SendEvent(new SupportBean_ST0("E3", 4));
            LambdaAssertionUtil.AssertST0Id(_listener, "val1", "E3,E1,E2");
            _listener.Reset();

            _epService.EPRuntime.SendEvent(new SupportBean_ST0("E5", 3));
            LambdaAssertionUtil.AssertST0Id(_listener, "val1", "E5,E3,E1");
            _listener.Reset();
            stmt.Dispose();

            // Scalar version
            String[] fields     = { "val0" };
            var      stmtScalar = _epService.EPAdministrator.CreateEPL("select Prevwindow(id).Where(x => x not like '%ignore%') as val0 " +
                                                                       "from SupportBean_ST0.win:keepall() as st0");

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

            _epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 5));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E1");
            _listener.Reset();

            _epService.EPRuntime.SendEvent(new SupportBean_ST0("E2ignore", 6));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E1");
            _listener.Reset();

            _epService.EPRuntime.SendEvent(new SupportBean_ST0("E3", 4));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E3", "E1");
            _listener.Reset();

            _epService.EPRuntime.SendEvent(new SupportBean_ST0("ignoreE5", 3));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E3", "E1");
            _listener.Reset();
        }
Ejemplo n.º 7
0
        private void RunAssertionScalarReturn(string epl)
        {
            var stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.AddListener(_listener);
            LambdaAssertionUtil.AssertTypes(stmt.EventType, "val1".Split(','), new Type[] { typeof(ICollection <object>) });

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

            _epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 8
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy("create expression string js:myscript(p1) [return \"--\"+p1+\"--\"]", path);
                env.CompileDeploy("create expression myexpr {sb => '--'||TheString||'--'}", path);

                // test mapped property syntax
                var eplMapped = "@Name('s0') select myscript('x') as c0, myexpr(sb) as c1 from SupportBean as sb";
                env.CompileDeploy(eplMapped, path).AddListener("s0");

                env.SendEventBean(new SupportBean("E1", 1));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"c0", "c1"},
                    new object[] {"--x--", "--E1--"});
                env.UndeployModuleContaining("s0");

                // test expression chained syntax
                var eplExpr = "" +
                              "create expression scalarfilter {s => " +
                              "   Strvals.where(y => y != 'E1') " +
                              "}";
                env.CompileDeploy(eplExpr, path);
                var eplSelect =
                    "@Name('s0') select scalarfilter(t).where(x => x != 'E2') as val1 from SupportCollection as t";
                env.CompileDeploy(eplSelect, path).AddListener("s0");
                AssertStatelessStmt(env, "s0", true);
                env.SendEventBean(SupportCollection.MakeString("E1,E2,E3,E4"));
                LambdaAssertionUtil.AssertValuesArrayScalar(env.Listener("s0"), "val1", "E3", "E4");
                env.UndeployAll();

                // test script chained syntax
                var supportBean = typeof(SupportBean).FullName;
                var eplScript =
                    $"create expression {typeof(SupportBean).MaskTypeName()} " +
                    "js:callIt() [ " +
                    $"  return host.newObj(host.resolveType('{supportBean}'), 'E1', 10); " +
                    "]";
                env.CompileDeploy(eplScript, path);
                env.CompileDeploy(
                        "@Name('s0') select callIt() as val0, callIt().GetTheString() as val1 from SupportBean as sb",
                        path)
                    .AddListener("s0");
                env.SendEventBean(new SupportBean());
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"val0.TheString", "val0.IntPrimitive", "val1"},
                    new object[] {"E1", 10, "E1"});

                env.UndeployAll();
            }
Ejemplo n.º 9
0
        public void TestSelect()
        {
            String eplFragment = "select " +
                                 "contained.selectFrom(x => id) as val0 " +
                                 "from Bean";
            EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment);

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

            _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,12", "E2,11", "E3,2"));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E1", "E2", "E3");
            _listener.Reset();

            _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", null);
            _listener.Reset();

            _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value());
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", new String[0]);
            _listener.Reset();
            stmtFragment.Dispose();

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

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

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4"));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", 2, 1, 5, 4);
            _listener.Reset();

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

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

            _epService.EPRuntime.SendEvent(SupportCollection.MakeString(""));
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0");
        }
Ejemplo n.º 10
0
        private void RunAssertionWhereString(EPServiceProvider epService)
        {
            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);
            var         listener     = new SupportUpdateListener();

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

            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 <bool?>)
            });

            epService.EPRuntime.SendEvent(SupportCollection.MakeBoolean("true,true,false"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", true, true);
            listener.Reset();

            stmtFragment.Dispose();
        }
Ejemplo n.º 11
0
        public void TestSetLogicWithScalar()
        {
            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);

            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",
                                                        null);
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1",
                                                        null);
            LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val2",
                                                        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();
        }
Ejemplo n.º 12
0
        public void TestReverseScalar()
        {
            String[] fields      = "val0".Split(',');
            String   eplFragment = "select " +
                                   "Strvals.reverse() as val0 " +
                                   "from SupportCollection";
            EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment);

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

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

            LambdaAssertionUtil.AssertSingleAndEmptySupportColl(_epService, _listener, fields);
        }
Ejemplo n.º 13
0
        private void RunAssertionParseSpecialAndMixedExprAndScript(EPServiceProvider epService)
        {
            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
            string      eplMapped  = "select myscript('x') as c0, myexpr(sb) as c1 from SupportBean as sb";
            EPStatement 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
            string eplExpr = "" +
                             "create expression scalarfilter {s => " +
                             "   Strvals.where(y => y != 'E1') " +
                             "}";

            epService.EPAdministrator.CreateEPL(eplExpr);
            string 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" });

            epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 14
0
        public void TestOrderByScalar()
        {
            String[] fields      = "val0,val1".Split(',');
            String   eplFragment = "select " +
                                   "Strvals.orderBy() as val0, " +
                                   "Strvals.OrderByDesc() as val1 " +
                                   "from SupportCollection";
            EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment);

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

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

            LambdaAssertionUtil.AssertSingleAndEmptySupportColl(_epService, _listener, fields);
            stmtFragment.Dispose();

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

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

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

            LambdaAssertionUtil.AssertSingleAndEmptySupportColl(_epService, _listener, fields);
        }
Ejemplo n.º 15
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();
        }
        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();
        }
Ejemplo n.º 17
0
        public void TestParseSpecialAndMixedExprAndScript()
        {
            SupportUpdateListener listener = new SupportUpdateListener();

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

            // test mapped property syntax
            String      eplMapped  = "select myscript('x') as c0, myexpr(sb) as c1 from SupportBean as sb";
            EPStatement 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
            String eplExpr = "" +
                             "create expression scalarfilter {s => " +
                             "   Strvals.where(y => y != 'E1') " +
                             "}";

            _epService.EPAdministrator.CreateEPL(eplExpr);
            String 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
            String eplScript = "create expression " + typeof(SupportBean).FullName + " js:callIt() [ clr.New('" + typeof(SupportBean).FullName + "',new Array('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" });
        }
Ejemplo n.º 18
0
        private void RunAssertionReverseScalar(EPServiceProvider epService)
        {
            string[] fields      = "val0".Split(',');
            string   eplFragment = "select " +
                                   "Strvals.Reverse() as val0 " +
                                   "from SupportCollection";
            EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment);
            var         listener     = new SupportUpdateListener();

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

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

            LambdaAssertionUtil.AssertSingleAndEmptySupportColl(epService, listener, fields);

            stmtFragment.Dispose();
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        public void TestUDFStaticMethod()
        {
            var fields = "val1,val2,val3,val4".Split(',');

            _epService.EPAdministrator.Configuration.AddImport(typeof(SupportBean_ST0_Container));
            var epl = "select " +
                      "SupportBean_ST0_Container.MakeSampleList().Where(x => x.p00 < 5) as val1, " +
                      "SupportBean_ST0_Container.MakeSampleArray().Where(x => x.p00 < 5) as val2, " +
                      "MakeSampleList().Where(x => x.p00 < 5) as val3, " +
                      "MakeSampleArray().Where(x => x.p00 < 5) as val4 " +
                      "from SupportBean.win:length(2) as sb";
            var stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.Events += _listener.Update;

            SupportBean_ST0_Container.Samples = new String[] { "E1,1", "E2,20", "E3,3" };
            _epService.EPRuntime.SendEvent(new SupportBean());
            foreach (var field in fields)
            {
                var result = _listener.AssertOneGetNew().Get(field).UnwrapIntoArray <SupportBean_ST0>();
                Assert.AreEqual(2, result.Length, "Failed for field " + field);
            }
            _listener.Reset();

            SupportBean_ST0_Container.Samples = null;
            _epService.EPRuntime.SendEvent(new SupportBean());
            foreach (var field in fields)
            {
                Assert.IsNull(_listener.AssertOneGetNew().Get(field));
            }
            _listener.Reset();

            SupportBean_ST0_Container.Samples = new String[0];
            _epService.EPRuntime.SendEvent(new SupportBean());
            foreach (var field in fields)
            {
                var result = _listener.AssertOneGetNew().Get(field).UnwrapIntoArray <SupportBean_ST0>();
                Assert.AreEqual(0, result.Length);
            }
            _listener.Reset();
            stmt.Dispose();

            // test UDF returning scalar values collection
            fields = "val0,val1,val2,val3".Split(',');
            _epService.EPAdministrator.Configuration.AddImport(typeof(SupportCollection));
            var eplScalar = "select " +
                            "SupportCollection.MakeSampleListString().Where(x => x != 'E1') as val0, " +
                            "SupportCollection.MakeSampleArrayString().Where(x => x != 'E1') as val1, " +
                            "makeSampleListString().Where(x => x != 'E1') as val2, " +
                            "makeSampleArrayString().Where(x => x != 'E1') as val3 " +
                            "from SupportBean.win:length(2) as sb";
            var stmtScalar = _epService.EPAdministrator.CreateEPL(eplScalar);

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

            SupportCollection.SampleCSV = "E1,E2,E3";
            _epService.EPRuntime.SendEvent(new SupportBean());
            foreach (var field in fields)
            {
                LambdaAssertionUtil.AssertValuesArrayScalar(_listener, field, "E2", "E3");
            }
            _listener.Reset();

            SupportCollection.SampleCSV = null;
            _epService.EPRuntime.SendEvent(new SupportBean());
            foreach (var field in fields)
            {
                LambdaAssertionUtil.AssertValuesArrayScalar(_listener, field, null);
            }
            _listener.Reset();

            SupportCollection.SampleCSV = "";
            _epService.EPRuntime.SendEvent(new SupportBean());
            foreach (var field in fields)
            {
                LambdaAssertionUtil.AssertValuesArrayScalar(_listener, field);
            }
            _listener.Reset();
        }