use of io.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitSiddhi_app.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public SiddhiApp visitSiddhi_app(@NotNull SiddhiQLParser.Siddhi_appContext ctx) {
SiddhiApp siddhiApp = SiddhiApp.siddhiApp();
for (SiddhiQLParser.App_annotationContext annotationContext : ctx.app_annotation()) {
siddhiApp.annotation((Annotation) visit(annotationContext));
}
for (SiddhiQLParser.Definition_streamContext streamContext : ctx.definition_stream()) {
siddhiApp.defineStream((StreamDefinition) visit(streamContext));
}
for (SiddhiQLParser.Definition_tableContext tableContext : ctx.definition_table()) {
siddhiApp.defineTable((TableDefinition) visit(tableContext));
}
for (SiddhiQLParser.Definition_functionContext functionContext : ctx.definition_function()) {
siddhiApp.defineFunction((FunctionDefinition) visit(functionContext));
}
for (SiddhiQLParser.Definition_windowContext windowContext : ctx.definition_window()) {
siddhiApp.defineWindow((WindowDefinition) visit(windowContext));
}
for (SiddhiQLParser.Definition_aggregationContext aggregationContext : ctx.definition_aggregation()) {
siddhiApp.defineAggregation((AggregationDefinition) visit(aggregationContext));
}
for (SiddhiQLParser.Execution_elementContext executionElementContext : ctx.execution_element()) {
ExecutionElement executionElement = (ExecutionElement) visit(executionElementContext);
if (executionElement instanceof Partition) {
siddhiApp.addPartition((Partition) executionElement);
} else if (executionElement instanceof Query) {
siddhiApp.addQuery((Query) executionElement);
} else {
throw newSiddhiParserException(ctx);
}
}
for (SiddhiQLParser.Definition_triggerContext triggerContext : ctx.definition_trigger()) {
siddhiApp.defineTrigger((TriggerDefinition) visit(triggerContext));
}
populateQueryContext(siddhiApp, ctx);
return siddhiApp;
}
use of io.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 io.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionQueryTestCase method testQuery1.
@Test
public void testQuery1() {
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);
Partition partition1 = 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 query1 = Query.query();
query1.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")))));
query1.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))));
query1.insertIntoInner("OutStockStream");
partition1.addQuery(query1);
Assert.assertTrue(partition.equals(partition1));
Assert.assertEquals(partition.hashCode(), partition1.hashCode());
}
use of io.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionQueryTestCase method testPartitionQueryNull.
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQueryNull() {
Partition partition = Partition.partition();
Query query = null;
partition.addQuery(query);
}
Aggregations