コード例 #1
0
  public void testSingleMethod() throws Exception {
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("SupportBean", SupportBean.class);
    String text = "select power3(intPrimitive) as val from SupportBean";
    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    stmt.addListener(listener);

    runAssertionSingleMethod();

    stmt.destroy();
    EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(text);
    assertEquals(text, model.toEPL());
    stmt = epService.getEPAdministrator().create(model);
    assertEquals(text, stmt.getText());
    stmt.addListener(listener);

    runAssertionSingleMethod();

    stmt.destroy();
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("SupportBean", SupportBean.class);
    text = "select power3(2) as val from SupportBean";
    stmt = epService.getEPAdministrator().createEPL(text);
    stmt.addListener(listener);

    runAssertionSingleMethod();
  }
コード例 #2
0
ファイル: TestPerRowFunc.java プロジェクト: arberzal/esper
  public void testCoalesceLong_OM() throws Exception {
    String viewExpr =
        "select coalesce(longBoxed, intBoxed, shortBoxed) as result"
            + " from "
            + SupportBean.class.getName()
            + ".win:length(1000)";

    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setSelectClause(
        SelectClause.create()
            .add(Expressions.coalesce("longBoxed", "intBoxed", "shortBoxed"), "result"));
    model.setFromClause(
        FromClause.create(
            FilterStream.create(SupportBean.class.getName())
                .addView("win", "length", Expressions.constant(1000))));
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);
    assertEquals(viewExpr, model.toEPL());

    epService.initialize();
    selectTestView = epService.getEPAdministrator().create(model);
    selectTestView.addListener(testListener);
    assertEquals(Long.class, selectTestView.getEventType().getPropertyType("result"));

    runCoalesceLong();
  }
コード例 #3
0
 public static EPStatement compileCreate(EPServiceProvider epService, String epl) {
   EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(epl);
   Assert.assertEquals(epl, model.toEPL());
   EPStatement stmt = epService.getEPAdministrator().create(model);
   Assert.assertEquals(epl, stmt.getText());
   return stmt;
 }
コード例 #4
0
  public void testAfterCurrentRow() throws Exception {
    Configuration config = SupportConfigFactory.getConfiguration();
    config.addEventType("MyEvent", SupportRecogBean.class);
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config);
    epService.initialize();

    String text =
        "select * from MyEvent.win:keepall() "
            + "match_recognize ("
            + " measures A.theString as a, B[0].theString as b0, B[1].theString as b1"
            + " after match skip to current row"
            + " pattern (A B*)"
            + " define"
            + " A as A.theString like \"A%\","
            + " B as B.theString like \"B%\""
            + ")";

    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);

    runAssertion(epService, listener, stmt);

    stmt.destroy();
    EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(text);
    SerializableObjectCopier.copy(model);
    assertEquals(text, model.toEPL());
    stmt = epService.getEPAdministrator().create(model);
    stmt.addListener(listener);
    assertEquals(text, stmt.getText());

    runAssertion(epService, listener, stmt);
  }
コード例 #5
0
 public void testUnfilteredStreamPrior_Compile() throws Exception {
   String stmtText = "select (select prior(0, id) from S1.win:length(1000)) as idS1 from S0";
   EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(stmtText);
   model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);
   assertEquals(stmtText, model.toEPL());
   EPStatement stmt = epService.getEPAdministrator().create(model);
   runUnfilteredStreamPrior(stmt);
 }
コード例 #6
0
  public void testEqualsAll() {
    String[] fields = "eq,neq,sqlneq,nneq".split(",");
    String stmtText =
        "select "
            + "intPrimitive = all (1, intBoxed) as eq, "
            + "intPrimitive != all (1, intBoxed) as neq, "
            + "intPrimitive <> all (1, intBoxed) as sqlneq, "
            + "not intPrimitive = all (1, intBoxed) as nneq "
            + "from SupportBean(string like \"E%\")";
    EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText);
    stmt.addListener(listener);

    // in the format intPrimitive, intBoxed
    int[][] testdata = {
      {1, 1},
      {1, 2},
      {2, 2},
      {2, 1},
    };

    Object[][] result = {
      {true, false, false, false}, // 1, 1
      {false, false, false, true}, // 1, 2
      {false, false, false, true}, // 2, 2
      {false, true, true, true} // 2, 1
    };

    for (int i = 0; i < testdata.length; i++) {
      SupportBean bean = new SupportBean("E", testdata[i][0]);
      bean.setIntBoxed(testdata[i][1]);
      epService.getEPRuntime().sendEvent(bean);
      // System.out.println("line " + i);
      ArrayAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, result[i]);
    }

    // test OM
    stmt.destroy();
    EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(stmtText);
    assertEquals(stmtText.replace("<>", "!="), model.toEPL());
    stmt = epService.getEPAdministrator().create(model);
    stmt.addListener(listener);

    for (int i = 0; i < testdata.length; i++) {
      SupportBean bean = new SupportBean("E", testdata[i][0]);
      bean.setIntBoxed(testdata[i][1]);
      epService.getEPRuntime().sendEvent(bean);
      // System.out.println("line " + i);
      ArrayAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, result[i]);
    }
  }
コード例 #7
0
  public void testRelationalOpAllArray() {
    String[] fields = "g,ge".split(",");
    String stmtText =
        "select "
            + "longBoxed > all ({1, 2}, intArr, intCol) as g, "
            + "longBoxed >= all ({1, 2}, intArr, intCol) as ge "
            + "from ArrayBean";
    EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText);
    stmt.addListener(listener);

    SupportBeanArrayCollMap arrayBean = new SupportBeanArrayCollMap(new int[] {1, 2});
    arrayBean.setIntCol(Arrays.asList(1, 2));
    arrayBean.setLongBoxed(3L);
    epService.getEPRuntime().sendEvent(arrayBean);
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {true, true});

    arrayBean.setLongBoxed(2L);
    epService.getEPRuntime().sendEvent(arrayBean);
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {false, true});

    arrayBean = new SupportBeanArrayCollMap(new int[] {1, 3});
    arrayBean.setIntCol(Arrays.asList(1, 2));
    arrayBean.setLongBoxed(3L);
    epService.getEPRuntime().sendEvent(arrayBean);
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {false, true});

    arrayBean = new SupportBeanArrayCollMap(new int[] {1, 2});
    arrayBean.setIntCol(Arrays.asList(1, 3));
    arrayBean.setLongBoxed(3L);
    epService.getEPRuntime().sendEvent(arrayBean);
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {false, true});

    // test OM
    stmt.destroy();
    EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(stmtText);
    assertEquals(stmtText.replace("<>", "!="), model.toEPL());
    stmt = epService.getEPAdministrator().create(model);
    stmt.addListener(listener);

    arrayBean = new SupportBeanArrayCollMap(new int[] {1, 2});
    arrayBean.setIntCol(Arrays.asList(1, 2));
    arrayBean.setLongBoxed(3L);
    epService.getEPRuntime().sendEvent(arrayBean);
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {true, true});
  }
コード例 #8
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  public void testVariantOneEPLToOMStmt() throws Exception {
    String epl =
        "insert into Event_1(delta, product) "
            + "select intPrimitive - intBoxed as deltaTag, intPrimitive * intBoxed as productTag "
            + "from "
            + SupportBean.class.getName()
            + ".win:length(100)";

    EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(epl);
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);
    assertEquals(epl, model.toEPL());

    EPStatement stmt = runAsserts(null, model);
    assertEquals(epl, stmt.getText());
  }
コード例 #9
0
  public EPStatement create(
      EPStatementObjectModel sodaStatement,
      String statementName,
      Object userObject,
      String statementId)
      throws EPException {
    // Specifies the statement
    StatementSpecRaw statementSpec = mapSODAToRaw(sodaStatement);
    String eplStatement = sodaStatement.toEPL();

    EPStatement statement =
        services
            .getStatementLifecycleSvc()
            .createAndStart(
                statementSpec,
                eplStatement,
                false,
                statementName,
                userObject,
                null,
                statementId,
                sodaStatement);

    log.debug(".createEPLStmt Statement created and started");
    return statement;
  }
コード例 #10
0
ファイル: TestPerRowFunc.java プロジェクト: arberzal/esper
  public void testCoalesceLong_Compile() {
    String viewExpr =
        "select coalesce(longBoxed, intBoxed, shortBoxed) as result"
            + " from "
            + SupportBean.class.getName()
            + ".win:length(1000)";

    EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(viewExpr);
    assertEquals(viewExpr, model.toEPL());

    epService.initialize();
    selectTestView = epService.getEPAdministrator().create(model);
    selectTestView.addListener(testListener);
    assertEquals(Long.class, selectTestView.getEventType().getPropertyType("result"));

    runCoalesceLong();
  }
コード例 #11
0
ファイル: TestPerRowFunc.java プロジェクト: arberzal/esper
  public void testMinMaxWindowStats_Compile() throws Exception {
    String viewExpr =
        "select max(longBoxed, intBoxed) as myMax, "
            + "max(longBoxed, intBoxed, shortBoxed) as myMaxEx, "
            + "min(longBoxed, intBoxed) as myMin, "
            + "min(longBoxed, intBoxed, shortBoxed) as myMinEx"
            + " from "
            + SupportBean.class.getName()
            + ".win:length(3)";

    EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(viewExpr);
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);
    assertEquals(viewExpr, model.toEPL());

    selectTestView = epService.getEPAdministrator().create(model);
    selectTestView.addListener(testListener);
    testListener.reset();

    runMinMaxWindowStats();
  }
コード例 #12
0
ファイル: TestPerRowFunc.java プロジェクト: arberzal/esper
  public void testMinMaxWindowStats_OM() throws Exception {
    String viewExpr =
        "select max(longBoxed, intBoxed) as myMax, "
            + "max(longBoxed, intBoxed, shortBoxed) as myMaxEx, "
            + "min(longBoxed, intBoxed) as myMin, "
            + "min(longBoxed, intBoxed, shortBoxed) as myMinEx"
            + " from "
            + SupportBean.class.getName()
            + ".win:length(3)";

    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setSelectClause(
        SelectClause.create()
            .add(Expressions.max("longBoxed", "intBoxed"), "myMax")
            .add(
                Expressions.max(
                    Expressions.property("longBoxed"),
                    Expressions.property("intBoxed"),
                    Expressions.property("shortBoxed")),
                "myMaxEx")
            .add(Expressions.min("longBoxed", "intBoxed"), "myMin")
            .add(
                Expressions.min(
                    Expressions.property("longBoxed"),
                    Expressions.property("intBoxed"),
                    Expressions.property("shortBoxed")),
                "myMinEx"));
    model.setFromClause(
        FromClause.create(
            FilterStream.create(SupportBean.class.getName())
                .addView("win", "length", Expressions.constant(3))));
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);
    assertEquals(viewExpr, model.toEPL());

    selectTestView = epService.getEPAdministrator().create(model);
    selectTestView.addListener(testListener);
    testListener.reset();

    runMinMaxWindowStats();
  }
コード例 #13
0
ファイル: EsperBoltTest.java プロジェクト: zqhxuyuan/bigdata
  @Test
  public void testSODA() {
    // should say fieldsTypes, maybe with object/component prefix
    Map<String, Object> eventTypes = new HashMap<>();
    eventTypes.put(LITERAL_SYMBOL, String.class);
    eventTypes.put(LITERAL_PRICE, Integer.class);

    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setInsertInto(InsertIntoClause.create(LITERAL_RETURN_OBJ));
    model.setSelectClause(
        SelectClause.create().add(Expressions.avg(LITERAL_PRICE), LITERAL_AVG).add(LITERAL_PRICE));
    Filter filter = Filter.create("quotes_default", Expressions.eq(LITERAL_SYMBOL, "A"));
    model.setFromClause(
        FromClause.create(
            FilterStream.create(filter).addView("win", "length", Expressions.constant(2))));
    model.setHavingClause(
        Expressions.gt(Expressions.avg(LITERAL_PRICE), Expressions.constant(60.0)));

    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(LITERAL_QUOTES, new RandomSentenceSpout());
    builder
        .setBolt(
            LITERAL_ESPER,
            (new EsperBolt())
                .addEventTypes(eventTypes)
                .addOutputTypes(
                    Collections.singletonMap(
                        LITERAL_RETURN_OBJ, Arrays.asList(LITERAL_AVG, LITERAL_PRICE)))
                .addObjectStatemens(Collections.singleton(model)))
        .shuffleGrouping(LITERAL_QUOTES);
    builder.setBolt("print", new PrinterBolt()).shuffleGrouping(LITERAL_ESPER, LITERAL_RETURN_OBJ);

    Config conf = new Config();
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("test", conf, builder.createTopology());
    Utils.sleep(10000);
    cluster.shutdown();
    assertEquals(resultSODA.get(100), new Double(75.0));
    assertEquals(resultSODA.get(50), new Double(75.0));
  }
コード例 #14
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  public void testVariantOneOMToStmt() throws Exception {
    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setInsertInto(InsertIntoClause.create("Event_1", "delta", "product"));
    model.setSelectClause(
        SelectClause.create()
            .add(Expressions.minus("intPrimitive", "intBoxed"), "deltaTag")
            .add(Expressions.multiply("intPrimitive", "intBoxed"), "productTag"));
    model.setFromClause(
        FromClause.create(
            FilterStream.create(SupportBean.class.getName())
                .addView(View.create("win", "length", Expressions.constant(100)))));
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);

    EPStatement stmt = runAsserts(null, model);

    String epl =
        "insert into Event_1(delta, product) "
            + "select intPrimitive - intBoxed as deltaTag, intPrimitive * intBoxed as productTag "
            + "from "
            + SupportBean.class.getName()
            + ".win:length(100)";
    assertEquals(epl, model.toEPL());
    assertEquals(epl, stmt.getText());
  }
コード例 #15
0
  public void testUnfilteredStreamPrior_OM() throws Exception {
    EPStatementObjectModel subquery = new EPStatementObjectModel();
    subquery.setSelectClause(SelectClause.create().add(Expressions.prior(0, "id")));
    subquery.setFromClause(
        FromClause.create(
            FilterStream.create("S1").addView("win", "length", Expressions.constant(1000))));

    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setSelectClause(SelectClause.create().add(Expressions.subquery(subquery), "idS1"));
    model.setFromClause(FromClause.create(FilterStream.create("S0")));
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);

    String stmtText = "select (select prior(0, id) from S1.win:length(1000)) as idS1 from S0";
    assertEquals(stmtText, model.toEPL());
    EPStatement stmt = epService.getEPAdministrator().create(model);
    runUnfilteredStreamPrior(stmt);
  }
コード例 #16
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  public void testVariantRStreamOMToStmt() throws Exception {
    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setInsertInto(
        InsertIntoClause.create("Event_1", new String[0], StreamSelector.RSTREAM_ONLY));
    model.setSelectClause(SelectClause.create().add("intPrimitive", "intBoxed"));
    model.setFromClause(FromClause.create(FilterStream.create(SupportBean.class.getName())));
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);

    EPStatement stmt = epService.getEPAdministrator().create(model, "s1");

    String epl =
        "insert rstream into Event_1 "
            + "select intPrimitive, intBoxed "
            + "from "
            + SupportBean.class.getName();
    assertEquals(epl, model.toEPL());
    assertEquals(epl, stmt.getText());

    EPStatementObjectModel modelTwo = epService.getEPAdministrator().compileEPL(model.toEPL());
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);
    assertEquals(epl, modelTwo.toEPL());

    // assert statement-type reference
    EPServiceProviderSPI spi = (EPServiceProviderSPI) epService;
    assertTrue(spi.getStatementEventTypeRef().isInUse("Event_1"));
    Set<String> stmtNames =
        spi.getStatementEventTypeRef().getStatementNamesForType(SupportBean.class.getName());
    assertTrue(stmtNames.contains("s1"));

    stmt.destroy();

    assertFalse(spi.getStatementEventTypeRef().isInUse("Event_1"));
    stmtNames =
        spi.getStatementEventTypeRef().getStatementNamesForType(SupportBean.class.getName());
    assertFalse(stmtNames.contains("s1"));
  }