public void testScalar() {

    String[] fields = "val0,val1".split(",");
    String eplFragment =
        "select "
            + "strvals.mostFrequent() as val0, "
            + "strvals.leastFrequent() as val1 "
            + "from SupportCollection";
    EPStatement stmtFragment = epService.getEPAdministrator().createEPL(eplFragment);
    stmtFragment.addListener(listener);
    LambdaAssertionUtil.assertTypes(
        stmtFragment.getEventType(), fields, new Class[] {String.class, String.class});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString("E2,E1,E2,E1,E3,E3,E4,E3"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"E3", "E4"});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString("E1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"E1", "E1"});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(null));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(""));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});
    stmtFragment.destroy();

    epService
        .getEPAdministrator()
        .getConfiguration()
        .addPlugInSingleRowFunction(
            "extractNum", TestEnumMinMax.MyService.class.getName(), "extractNum");
    String eplLambda =
        "select "
            + "strvals.mostFrequent(v => extractNum(v)) as val0, "
            + "strvals.leastFrequent(v => extractNum(v)) as val1 "
            + "from SupportCollection";
    EPStatement stmtLambda = epService.getEPAdministrator().createEPL(eplLambda);
    stmtLambda.addListener(listener);
    LambdaAssertionUtil.assertTypes(
        stmtLambda.getEventType(), fields, new Class[] {Integer.class, Integer.class});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString("E2,E1,E2,E1,E3,E3,E4,E3"));
    EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {3, 4});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString("E1"));
    EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {1, 1});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(null));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(""));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});
  }
예제 #2
0
  public void testAverageEvents() {

    String[] fields = "val0,val1,val2,val3".split(",");
    String eplFragment =
        "select "
            + "beans.average(x => intBoxed) as val0,"
            + "beans.average(x => doubleBoxed) as val1,"
            + "beans.average(x => longBoxed) as val2,"
            + "beans.average(x => bigDecimal) as val3 "
            + "from Bean";
    EPStatement stmtFragment = epService.getEPAdministrator().createEPL(eplFragment);
    stmtFragment.addListener(listener);
    LambdaAssertionUtil.assertTypes(
        stmtFragment.getEventType(),
        fields,
        new Class[] {Double.class, Double.class, Double.class, BigDecimal.class});

    epService.getEPRuntime().sendEvent(new SupportBean_Container(null));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null});

    epService
        .getEPRuntime()
        .sendEvent(new SupportBean_Container(Collections.<SupportBean>emptyList()));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null});

    List<SupportBean> list = new ArrayList<SupportBean>();
    list.add(make(2, 3d, 4l, 5));
    epService.getEPRuntime().sendEvent(new SupportBean_Container(list));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        fields,
        new Object[] {2d, 3d, 4d, new BigDecimal(5.0d)});

    list.add(make(4, 6d, 8l, 10));
    epService.getEPRuntime().sendEvent(new SupportBean_Container(list));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        fields,
        new Object[] {(2 + 4) / 2d, (3d + 6d) / 2d, (4L + 8L) / 2d, new BigDecimal((5 + 10) / 2d)});
  }
  public void testMostLeastEvents() {

    String[] fields = "val0,val1".split(",");
    String eplFragment =
        "select "
            + "contained.mostFrequent(x => p00) as val0,"
            + "contained.leastFrequent(x => p00) as val1 "
            + "from Bean";
    EPStatement stmtFragment = epService.getEPAdministrator().createEPL(eplFragment);
    stmtFragment.addListener(listener);
    LambdaAssertionUtil.assertTypes(
        stmtFragment.getEventType(), fields, new Class[] {Integer.class, Integer.class});

    SupportBean_ST0_Container bean =
        SupportBean_ST0_Container.make2Value("E1,12", "E2,11", "E2,2", "E3,12");
    epService.getEPRuntime().sendEvent(bean);
    EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {12, 11});

    bean = SupportBean_ST0_Container.make2Value("E1,12");
    epService.getEPRuntime().sendEvent(bean);
    EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {12, 12});

    bean =
        SupportBean_ST0_Container.make2Value(
            "E1,12", "E2,11", "E2,2", "E3,12", "E1,12", "E2,11", "E3,11");
    epService.getEPRuntime().sendEvent(bean);
    EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {12, 2});

    bean =
        SupportBean_ST0_Container.make2Value(
            "E2,11", "E1,12", "E2,15", "E3,12", "E1,12", "E2,11", "E3,11");
    epService.getEPRuntime().sendEvent(bean);
    EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {11, 15});

    epService.getEPRuntime().sendEvent(SupportBean_ST0_Container.make2Value(null));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});

    epService.getEPRuntime().sendEvent(SupportBean_ST0_Container.make2Value());
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});
  }
예제 #4
0
  public void testAverageScalar() {

    String[] fields = "val0,val1".split(",");
    String eplFragment =
        "select "
            + "intvals.average() as val0,"
            + "bdvals.average() as val1 "
            + "from SupportCollection";
    EPStatement stmtFragment = epService.getEPAdministrator().createEPL(eplFragment);
    stmtFragment.addListener(listener);
    LambdaAssertionUtil.assertTypes(
        stmtFragment.getEventType(), fields, new Class[] {Double.class, BigDecimal.class});

    epService.getEPRuntime().sendEvent(SupportCollection.makeNumeric("1,2,3"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {2d, new BigDecimal(2d)});

    epService.getEPRuntime().sendEvent(SupportCollection.makeNumeric("1,null,3"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {2d, new BigDecimal(2d)});

    epService.getEPRuntime().sendEvent(SupportCollection.makeNumeric("4"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {4d, new BigDecimal(4d)});
    stmtFragment.destroy();

    // test average with lambda
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addPlugInSingleRowFunction(
            "extractNum", TestEnumMinMax.MyService.class.getName(), "extractNum");
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addPlugInSingleRowFunction(
            "extractBigDecimal", TestEnumMinMax.MyService.class.getName(), "extractBigDecimal");

    String[] fieldsLambda = "val0,val1".split(",");
    String eplLambda =
        "select "
            + "strvals.average(v => extractNum(v)) as val0, "
            + "strvals.average(v => extractBigDecimal(v)) as val1 "
            + "from SupportCollection";
    EPStatement stmtLambda = epService.getEPAdministrator().createEPL(eplLambda);
    stmtLambda.addListener(listener);
    LambdaAssertionUtil.assertTypes(
        stmtLambda.getEventType(), fieldsLambda, new Class[] {Double.class, BigDecimal.class});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString("E2,E1,E5,E4"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        fieldsLambda,
        new Object[] {(2 + 1 + 5 + 4) / 4d, new BigDecimal((2 + 1 + 5 + 4) / 4d)});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString("E1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fieldsLambda, new Object[] {1d, new BigDecimal(1)});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(null));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fieldsLambda, new Object[] {null, null});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(""));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fieldsLambda, new Object[] {null, null});
  }