use of org.ballerinalang.siddhi.query.api.execution.partition.Partition in project ballerina by ballerina-lang.
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.ballerinalang.siddhi.query.api.execution.partition.Partition in project ballerina by ballerina-lang.
the class DefinePartitionTestCase method test1.
@Test
public void test1() {
Partition partition = SiddhiCompiler.parsePartition("partition with (200>volume as 'LessValue' or 200<=volume" + " as 'HighValue' of cseEventStream) begin from cseEventStream select sum(volume) as sumvolume insert " + "into StockStream ; end ");
AssertJUnit.assertEquals(Partition.partition().with("cseEventStream", Partition.range("LessValue", Expression.compare(Expression.value(200), Compare.Operator.GREATER_THAN, Expression.variable("volume"))), Partition.range("HighValue", Expression.compare(Expression.value(200), Compare.Operator.LESS_THAN_EQUAL, Expression.variable("volume")))).toString().split("queryList")[0], partition.toString().split("queryList")[0]);
}
use of org.ballerinalang.siddhi.query.api.execution.partition.Partition in project ballerina by ballerina-lang.
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.ballerinalang.siddhi.query.api.execution.partition.Partition in project ballerina by ballerina-lang.
the class SiddhiCompiler method parsePartition.
public static Partition parsePartition(String source) throws SiddhiParserException {
ANTLRInputStream input = new ANTLRInputStream(source);
SiddhiQLLexer lexer = new SiddhiQLLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SiddhiQLParser parser = new SiddhiQLParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(SiddhiErrorListener.INSTANCE);
ParseTree tree = parser.partition_final();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (Partition) eval.visit(tree);
}
use of org.ballerinalang.siddhi.query.api.execution.partition.Partition in project ballerina by ballerina-lang.
the class PartitionTestCase1 method testPartitionQuery39.
@Test
public void testPartitionQuery39() throws InterruptedException {
log.info("Partition test");
SiddhiApp siddhiApp = SiddhiApp.siddhiApp("Test").defineStream(StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT));
Query query = Query.query();
query.from(InputStream.stream("streamA"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("StockQuote");
Partition partition = Partition.partition().annotation(Annotation.annotation("info").element("name", "partitionA")).with("streamA", Expression.variable("symbol")).addQuery(query);
siddhiApp.addPartition(partition);
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
StreamCallback streamCallback = new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
count.addAndGet(events.length);
eventArrived = true;
}
};
siddhiAppRuntime.addCallback("StockQuote", streamCallback);
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
siddhiAppRuntime.start();
inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
Thread.sleep(1000);
AssertJUnit.assertEquals(3, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations