use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.
the class LogicalAbsentPatternTestCase method testQueryAbsent26.
@Test(dependsOnMethods = { "testQueryAbsent25" })
public void testQueryAbsent26() throws InterruptedException {
log.info("Test the query e1 -> (not e2 for 1 sec and not e3 for 1 sec) within 2 sec with e1 and e2");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> (not Stream2[price>20] for 1 sec and not Stream3[price>30] for 1 sec) " + "within 2 sec " + "select e1.symbol as symbol1 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 15.0f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 25.0f, 101 });
Thread.sleep(1100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.
the class LogicalAbsentPatternTestCase method testQueryAbsent27.
@Test(dependsOnMethods = { "testQueryAbsent26" })
public void testQueryAbsent27() throws InterruptedException {
log.info("Test the query e1 -> (not e2 for 1 sec and not e3 for 1 sec) within 2 sec with e1 and e3");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> (not Stream2[price>20] for 1 sec and not Stream3[price>30] for 1 sec) " + "within 2 sec " + "select e1.symbol as symbol1 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 15.0f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "IBM", 35.0f, 102 });
Thread.sleep(1100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.
the class StoreQueryTableTestCase method test13.
@Test
public void test13() throws InterruptedException {
log.info("Test13 - Test output attributes and its types for aggregation table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long);" + "define aggregation StockTableAg " + "from StockStream " + "select symbol, price " + "group by symbol " + "aggregate every minutes ...year;";
String storeQuery = "" + "from StockTableAg within '2018-**-** **:**:**' per 'minutes' select symbol, price ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
siddhiAppRuntime.start();
Attribute[] actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
Attribute[] expectedAttributeArray = new Attribute[] { symbolAttribute, priceAttribute };
AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
storeQuery = "" + "from StockTableAg within '2018-**-** **:**:**' per 'minutes' select symbol, sum(price) as total";
actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
Attribute totalVolumeAttribute = new Attribute("total", Attribute.Type.DOUBLE);
expectedAttributeArray = new Attribute[] { symbolAttribute, totalVolumeAttribute };
siddhiAppRuntime.shutdown();
AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitStore_input.
@Override
public Object visitStore_input(SiddhiQLParser.Store_inputContext ctx) {
String sourceId = (String) visit(ctx.source_id());
String alias = null;
if (ctx.alias() != null) {
alias = (String) visit(ctx.source_id());
}
Store store = InputStore.store(alias, sourceId);
Expression expression = null;
if (ctx.expression() != null) {
expression = (Expression) visit(ctx.expression());
}
populateQueryContext(store, ctx);
if (ctx.per() != null) {
return store.on(expression, (Within) visit(ctx.within_time_range()), (Expression) visit(ctx.per()));
} else if (expression != null) {
return store.on(expression);
} else {
return store;
}
}
use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.
the class PatternQueryTestCase method testPatternQuery6.
// from every (e1=Stream1[price >= 30]) -> e2=Stream1[ price >= 20] or e3=Stream2[ price >= e1.price] within 3 min
// -> e4=Stream3[price>74] within 2 min
// select e1.symbol, avg(e2.price ) as avgPrice
// insert into OutputStream
@Test
public void testPatternQuery6() {
Query query = Query.query();
query.from(InputStream.patternStream(State.next(State.every(State.stream(InputStream.stream("e1", "Stream1").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(30))))), State.next(State.logicalOr(State.stream(InputStream.stream("e2", "Stream1").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20)))), State.stream(InputStream.stream("e3", "Stream2").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("price").ofStream("e1")))), Expression.Time.minute(3)), State.stream(InputStream.stream("e4", "Stream3").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(74))))))));
query.select(Selector.selector().select("symbol", Expression.variable("symbol").ofStream("e1")).select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2"))));
query.insertInto("OutputStream");
}
Aggregations