use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitPartition.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Partition visitPartition(@NotNull SiddhiQLParser.PartitionContext ctx) {
Partition partition = Partition.partition();
for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
partition.annotation((Annotation) visit(annotationContext));
}
for (SiddhiQLParser.Partition_with_streamContext with_streamContext : ctx.partition_with_stream()) {
partition.with((PartitionType) visit(with_streamContext));
}
for (SiddhiQLParser.QueryContext queryContext : ctx.query()) {
partition.addQuery((Query) visit(queryContext));
}
populateQueryContext(partition, ctx);
return partition;
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class DefinePartitionTestCase method test2.
@Test
public void test2() {
Partition partition = SiddhiCompiler.parsePartition("partition with (symbol of cseEventStream) begin from " + "cseEventStream select sum(volume) as sumvolume insert into StockStream ; end ");
AssertJUnit.assertEquals(Partition.partition().with("cseEventStream", Expression.variable("symbol")).toString().split("queryList")[0], partition.toString().split("queryList")[0]);
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class SiddhiApp method addPartition.
public SiddhiApp addPartition(Partition partition) {
if (partition == null) {
throw new SiddhiAppValidationException("Partition should not be null");
}
String name = null;
Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants.ANNOTATION_ELEMENT_NAME, partition.getAnnotations());
if (element != null) {
name = element.getValue();
}
if (name != null && executionElementNameList.contains(name)) {
throw new SiddhiAppValidationException("Cannot add Partition as another Execution Element already " + "uses its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex());
}
executionElementNameList.add(name);
this.executionElementList.add(partition);
return this;
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionQueryTestCase method testCreatingFilterQuery.
// from StockStream[ 7+9.5>price AND 100>=volume]
// insert into OutStockStream symbol, avg(price) as avgPrice
// group by symbol
// having avgPrice>50
@Test
public void testCreatingFilterQuery() {
Partition partition = Partition.partition().with("StockStream", Expression.variable("symbol")).with("StockStream1", Expression.variable("symbol")).with("StockStream2", Partition.range("LessValue", Expression.compare(Expression.value(7), Compare.Operator.GREATER_THAN, Expression.variable("price"))), Partition.range("HighValue", Expression.compare(Expression.value(9.5), Compare.Operator.LESS_THAN, Expression.variable("price1"))));
Query query = Query.query();
query.from(InputStream.stream("StockStream").filter(Expression.and(Expression.compare(Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume")))));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("symbol"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("avgPrice"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(50))));
query.insertIntoInner("OutStockStream");
partition.addQuery(query);
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionSample method main.
public static void main(String[] args) throws InterruptedException {
// Creating Siddhi Manager
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "define stream cseEventStream (symbol string, price float,volume int);" + "" + "partition with (symbol of cseEventStream)" + "begin" + " @info(name = 'query') " + " from cseEventStream " + " select symbol, sum(price) as price, volume " + " insert into OutStockStream ;" + "end ";
// Generating runtime
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
// Adding callback to retrieve output events from stream
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
}
});
// Retrieving InputHandler to push events into Siddhi
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
// Starting event processing
siddhiAppRuntime.start();
// Sending events to Siddhi
inputHandler.send(new Object[] { "IBM", 75f, 100 });
inputHandler.send(new Object[] { "WSO2", 705f, 100 });
inputHandler.send(new Object[] { "IBM", 35f, 100 });
inputHandler.send(new Object[] { "ORACLE", 50.0f, 100 });
Thread.sleep(1000);
// Shutting down the runtime
siddhiAppRuntime.shutdown();
// Shutting down Siddhi
siddhiManager.shutdown();
}
Aggregations