Search in sources :

Example 16 with Partition

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;
}
Also used : SiddhiQLParser(io.siddhi.query.compiler.SiddhiQLParser) Partition(io.siddhi.query.api.execution.partition.Partition) SiddhiApp(io.siddhi.query.api.SiddhiApp) Query(io.siddhi.query.api.execution.query.Query) OnDemandQuery(io.siddhi.query.api.execution.query.OnDemandQuery) ExecutionElement(io.siddhi.query.api.execution.ExecutionElement)

Example 17 with Partition

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);
}
Also used : Partition(io.siddhi.query.api.execution.partition.Partition) Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 18 with Partition

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());
}
Also used : Partition(io.siddhi.query.api.execution.partition.Partition) Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 19 with Partition

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);
}
Also used : Partition(io.siddhi.query.api.execution.partition.Partition) Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Aggregations

Partition (io.siddhi.query.api.execution.partition.Partition)19 Query (io.siddhi.query.api.execution.query.Query)14 Test (org.testng.annotations.Test)13 SiddhiApp (io.siddhi.query.api.SiddhiApp)10 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)8 SiddhiManager (io.siddhi.core.SiddhiManager)8 Event (io.siddhi.core.event.Event)8 InputHandler (io.siddhi.core.stream.input.InputHandler)8 StreamCallback (io.siddhi.core.stream.output.StreamCallback)8 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)7 ExecutionElement (io.siddhi.query.api.execution.ExecutionElement)3 SiddhiQLParser (io.siddhi.query.compiler.SiddhiQLParser)2 ArrayList (java.util.ArrayList)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 SiddhiAppContext (io.siddhi.core.config.SiddhiAppContext)1 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)1 PartitionRuntimeImpl (io.siddhi.core.partition.PartitionRuntimeImpl)1 QueryRuntimeImpl (io.siddhi.core.query.QueryRuntimeImpl)1 IdGenerator (io.siddhi.core.util.IdGenerator)1 SiddhiAppRuntimeBuilder (io.siddhi.core.util.SiddhiAppRuntimeBuilder)1