public void Run(RegressionEnvironment env)
            {
                GroupingSupportFunc.Parameters.Clear();

                // test uncorrelated subquery and expression-declaration and single-row func
                var epl = "create expression myExpr {x-> '|' || x.Name || '|'};\n" +
                          "@Name('s0') select myfunc(" +
                          "  Name, Place, sum(Count), grouping(Name), grouping(Place), grouping_id(Name, Place)," +
                          "  (select RefId from SupportCarInfoEvent#lastevent), " +
                          "  myExpr(ce)" +
                          "  )" +
                          "from SupportCarEvent ce group by grouping sets((Name, Place),Name, Place,())";
                env.CompileDeploy(epl).AddListener("s0");

                env.SendEventBean(new SupportBean("E1", 1));
                env.SendEventBean(new SupportCarInfoEvent("a", "b", "c01"));

                env.SendEventBean(new SupportCarEvent("skoda", "france", 10000));
                EPAssertionUtil.AssertEqualsExactOrder(
                    new[] {
                        new object[] {"skoda", "france", 10000, 0, 0, 0, "c01", "|skoda|"},
                        new object[] {"skoda", null, 10000, 0, 1, 1, "c01", "|skoda|"},
                        new object[] {null, "france", 10000, 1, 0, 2, "c01", "|skoda|"},
                        new object[] {null, null, 10000, 1, 1, 3, "c01", "|skoda|"}
                    },
                    GroupingSupportFunc.AssertGetAndClear(4));
                env.UndeployAll();

                // test "prev" and "prior"
                var fields = new [] { "c0", "c1", "c2", "c3" };
                var eplTwo =
                    "@Name('s0') select prev(1, Name) as c0, prior(1, Name) as c1, Name as c2, sum(Count) as c3 " +
                    "from SupportCarEvent#keepall ce group by rollup(Name)";
                env.CompileDeploy(eplTwo).AddListener("s0");

                env.SendEventBean(new SupportCarEvent("skoda", "france", 10));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetLastNewData(),
                    fields,
                    new[] {
                        new object[] {null, null, "skoda", 10}, new object[] {null, null, null, 10}
                    });

                env.SendEventBean(new SupportCarEvent("vw", "france", 15));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetLastNewData(),
                    fields,
                    new[] {
                        new object[] {"skoda", "skoda", "vw", 15}, new object[] {"skoda", "skoda", null, 25}
                    });

                env.UndeployAll();
            }
示例#2
0
        private void RunAssertionGroupingFuncExpressionUse(EPServiceProvider epService)
        {
            GroupingSupportFunc.Parameters.Clear();
            epService.EPAdministrator.Configuration.AddEventType(typeof(CarEvent));

            // test uncorrelated subquery and expression-declaration and single-row func
            epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("myfunc", typeof(GroupingSupportFunc), "Myfunc");
            epService.EPAdministrator.CreateEPL("create expression myExpr {x=> '|' || x.name || '|'}");
            epService.EPAdministrator.Configuration.AddEventType(typeof(CarInfoEvent));
            string epl = "select myfunc(" +
                         "  name, place, sum(count), grouping(name), grouping(place), grouping_id(name, place)," +
                         "  (select refId from CarInfoEvent#lastevent), " +
                         "  myExpr(ce)" +
                         "  )" +
                         "from CarEvent ce group by grouping sets((name, place),name, place,())";
            var listener = new SupportUpdateListener();

            epService.EPAdministrator.CreateEPL(epl).Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            epService.EPRuntime.SendEvent(new CarInfoEvent("a", "b", "c01"));

            epService.EPRuntime.SendEvent(new CarEvent("skoda", "france", 10000));
            EPAssertionUtil.AssertEqualsExactOrder(new object[][] {
                new object[] { "skoda", "france", 10000, 0, 0, 0, "c01", "|skoda|" },
                new object[] { "skoda", null, 10000, 0, 1, 1, "c01", "|skoda|" },
                new object[] { null, "france", 10000, 1, 0, 2, "c01", "|skoda|" },
                new object[] { null, null, 10000, 1, 1, 3, "c01", "|skoda|" }
            }, GroupingSupportFunc.AssertGetAndClear(4));
            epService.EPAdministrator.DestroyAllStatements();

            // test "prev" and "prior"
            string[] fields = "c0,c1,c2,c3".Split(',');
            string   eplTwo = "select prev(1, name) as c0, prior(1, name) as c1, name as c2, sum(count) as c3 from CarEvent#keepall ce group by Rollup(name)";

            epService.EPAdministrator.CreateEPL(eplTwo).Events += listener.Update;

            epService.EPRuntime.SendEvent(new CarEvent("skoda", "france", 10));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] {
                new object[] { null, null, "skoda", 10 }, new object[] { null, null, null, 10 }
            });

            epService.EPRuntime.SendEvent(new CarEvent("vw", "france", 15));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] {
                new object[] { "skoda", "skoda", "vw", 15 }, new object[] { "skoda", "skoda", null, 25 }
            });

            epService.EPAdministrator.DestroyAllStatements();
        }