Exemple #1
0
  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();
  }
  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);
  }
Exemple #3
0
  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();
  }
Exemple #4
0
  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());
  }
Exemple #5
0
  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"));
  }