Search in sources :

Example 1 with AggregationDefinition

use of io.siddhi.query.api.definition.AggregationDefinition in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitDefinition_aggregation.

@Override
public AggregationDefinition visitDefinition_aggregation(@NotNull SiddhiQLParser.Definition_aggregationContext ctx) {
    // Read the name of the aggregation
    String aggregationName = (String) visitAggregation_name(ctx.aggregation_name());
    // Create the aggregation using the extracted aggregation name
    AggregationDefinition aggregationDefinition = AggregationDefinition.id(aggregationName);
    // Get all annotation and populate the aggregation
    for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
        aggregationDefinition.annotation((Annotation) visit(annotationContext));
    }
    // Attach the input stream
    BasicSingleInputStream basicSingleInputStream = (BasicSingleInputStream) visit(ctx.standard_stream());
    aggregationDefinition.from(basicSingleInputStream);
    // Extract the selector and attach it to the new aggregation
    BasicSelector selector = (BasicSelector) visit(ctx.group_by_query_selection());
    aggregationDefinition.select(selector);
    // Get the variable (if available) and aggregate on that variable
    if (ctx.attribute_reference() != null) {
        Variable aggregatedBy = (Variable) visit(ctx.attribute_reference());
        aggregationDefinition.aggregateBy(aggregatedBy);
    }
    // Extract the specified time-durations and attache it to the aggregation definition
    TimePeriod timePeriod = (TimePeriod) visit(ctx.aggregation_time());
    aggregationDefinition.every(timePeriod);
    populateQueryContext(aggregationDefinition, ctx);
    return aggregationDefinition;
}
Also used : SiddhiQLParser(io.siddhi.query.compiler.SiddhiQLParser) Variable(io.siddhi.query.api.expression.Variable) AggregationDefinition(io.siddhi.query.api.definition.AggregationDefinition) TimePeriod(io.siddhi.query.api.aggregation.TimePeriod) BasicSingleInputStream(io.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) BasicSelector(io.siddhi.query.api.execution.query.selection.BasicSelector)

Example 2 with AggregationDefinition

use of io.siddhi.query.api.definition.AggregationDefinition in project siddhi by wso2.

the class DefineAggregationTestCase method test2.

@Test
public void test2() throws SiddhiParserException {
    AggregationDefinition aggregationDefinitionQuery = SiddhiCompiler.parseAggregationDefinition("define aggregation StockAggregationDefinition " + "from StockStream " + "select StockStream.timestamp, StockStream.symbol as symbol, " + "       StockStream.price as price " + "   group by StockStream.symbol " + "aggregate by timestamp " + "every seconds, minutes, hours ;");
    AggregationDefinition aggregationDefinition = AggregationDefinition.id("StockAggregationDefinition").from(InputStream.stream("StockStream")).select(Selector.basicSelector().select(Expression.variable("timestamp").ofStream("StockStream")).select("symbol", Expression.variable("symbol").ofStream("StockStream")).select("price", Expression.variable("price").ofStream("StockStream")).groupBy(Expression.variable("symbol").ofStream("StockStream"))).aggregateBy(Expression.variable("timestamp")).every(TimePeriod.interval(TimePeriod.Duration.SECONDS, TimePeriod.Duration.MINUTES, TimePeriod.Duration.HOURS));
    AssertJUnit.assertEquals(aggregationDefinition, aggregationDefinitionQuery);
}
Also used : AggregationDefinition(io.siddhi.query.api.definition.AggregationDefinition) Test(org.testng.annotations.Test)

Example 3 with AggregationDefinition

use of io.siddhi.query.api.definition.AggregationDefinition in project siddhi by wso2.

the class DefinitionParserHelper method validateDefinition.

public static void validateDefinition(AbstractDefinition definition, ConcurrentMap<String, AbstractDefinition> streamDefinitionMap, ConcurrentMap<String, AbstractDefinition> tableDefinitionMap, ConcurrentMap<String, AbstractDefinition> windowDefinitionMap, ConcurrentMap<String, AbstractDefinition> aggregationDefinitionMap) {
    AbstractDefinition existingTableDefinition = tableDefinitionMap.get(definition.getId());
    if (existingTableDefinition != null && (!existingTableDefinition.equals(definition) || definition instanceof StreamDefinition)) {
        throw new DuplicateDefinitionException("Table Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingTableDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingStreamDefinition = streamDefinitionMap.get(definition.getId());
    if (existingStreamDefinition != null && (!existingStreamDefinition.equals(definition) || definition instanceof TableDefinition)) {
        throw new DuplicateDefinitionException("Stream Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingStreamDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingWindowDefinition = windowDefinitionMap.get(definition.getId());
    if (existingWindowDefinition != null && (!existingWindowDefinition.equals(definition) || definition instanceof WindowDefinition)) {
        throw new DuplicateDefinitionException("Window Definition with same Window Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingAggregationDefinition = aggregationDefinitionMap.get(definition.getId());
    if (existingAggregationDefinition != null && (!existingAggregationDefinition.equals(definition) || definition instanceof AggregationDefinition)) {
        throw new DuplicateDefinitionException("Aggregation Definition with same Aggregation Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) DuplicateDefinitionException(io.siddhi.query.api.exception.DuplicateDefinitionException) AggregationDefinition(io.siddhi.query.api.definition.AggregationDefinition) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) TableDefinition(io.siddhi.query.api.definition.TableDefinition) WindowDefinition(io.siddhi.query.api.definition.WindowDefinition)

Example 4 with AggregationDefinition

use of io.siddhi.query.api.definition.AggregationDefinition in project siddhi by wso2.

the class DefineAggregationTestCase method testDefineAggregation5.

@Test
public void testDefineAggregation5() {
    AggregationDefinition aggregationDefinition = AggregationDefinition.id("StockAggregation").from(InputStream.stream("StockStream")).select(Selector.basicSelector().select("timestamp", Expression.variable("timestamp").ofStream("StockStream")).select("symbol", Expression.variable("symbol").ofStream("StockStream")).select("price", Expression.variable("price").ofStream("StockStream")).groupBy(Expression.variable("price").ofStream("StockStream")));
    Assert.assertEquals(aggregationDefinition.getAttributeNameArray(), new String[] {});
}
Also used : AggregationDefinition(io.siddhi.query.api.definition.AggregationDefinition) Test(org.testng.annotations.Test)

Example 5 with AggregationDefinition

use of io.siddhi.query.api.definition.AggregationDefinition in project siddhi by wso2.

the class DefineAggregationTestCase method testDefineAggregation6.

@Test
public void testDefineAggregation6() {
    AggregationDefinition aggregationDefinition = AggregationDefinition.id("StockAggregation").from(InputStream.stream("StockStream")).select(Selector.basicSelector().select("timestamp", Expression.variable("timestamp").ofStream("StockStream")).select("symbol", Expression.variable("symbol").ofStream("StockStream")).select("price", Expression.variable("price").ofStream("StockStream")).groupBy(Expression.variable("price").ofStream("StockStream")));
    AggregationDefinition aggregationDefinition1 = AggregationDefinition.id("StockAggregation").from(InputStream.stream("StockStream")).select(Selector.basicSelector().select("timestamp", Expression.variable("timestamp").ofStream("StockStream")).select("symbol", Expression.variable("symbol").ofStream("StockStream")).select("price", Expression.variable("price").ofStream("StockStream")).groupBy(Expression.variable("price").ofStream("StockStream")));
    Assert.assertEquals(aggregationDefinition, aggregationDefinition1);
    Assert.assertEquals(aggregationDefinition.hashCode(), aggregationDefinition1.hashCode());
    Assert.assertTrue(aggregationDefinition.equals(aggregationDefinition1));
}
Also used : AggregationDefinition(io.siddhi.query.api.definition.AggregationDefinition) Test(org.testng.annotations.Test)

Aggregations

AggregationDefinition (io.siddhi.query.api.definition.AggregationDefinition)10 Test (org.testng.annotations.Test)5 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)3 TableDefinition (io.siddhi.query.api.definition.TableDefinition)3 AggregationRuntime (io.siddhi.core.aggregation.AggregationRuntime)1 Executor (io.siddhi.core.aggregation.Executor)1 IncrementalAggregationProcessor (io.siddhi.core.aggregation.IncrementalAggregationProcessor)1 IncrementalDataPurger (io.siddhi.core.aggregation.IncrementalDataPurger)1 IncrementalExecutor (io.siddhi.core.aggregation.IncrementalExecutor)1 IncrementalExecutorsInitialiser (io.siddhi.core.aggregation.IncrementalExecutorsInitialiser)1 CudStreamProcessorQueueManager (io.siddhi.core.aggregation.persistedaggregation.CudStreamProcessorQueueManager)1 PersistedIncrementalExecutor (io.siddhi.core.aggregation.persistedaggregation.PersistedIncrementalExecutor)1 QueuedCudStreamProcessor (io.siddhi.core.aggregation.persistedaggregation.QueuedCudStreamProcessor)1 DBAggregationQueryConfigurationEntry (io.siddhi.core.aggregation.persistedaggregation.config.DBAggregationQueryConfigurationEntry)1 DBAggregationQueryUtil (io.siddhi.core.aggregation.persistedaggregation.config.DBAggregationQueryUtil)1 DBAggregationSelectFunctionTemplate (io.siddhi.core.aggregation.persistedaggregation.config.DBAggregationSelectFunctionTemplate)1 DBAggregationSelectQueryTemplate (io.siddhi.core.aggregation.persistedaggregation.config.DBAggregationSelectQueryTemplate)1 DBAggregationTimeConversionDurationMapping (io.siddhi.core.aggregation.persistedaggregation.config.DBAggregationTimeConversionDurationMapping)1 PersistedAggregationResultsProcessor (io.siddhi.core.aggregation.persistedaggregation.config.PersistedAggregationResultsProcessor)1 SiddhiAppContext (io.siddhi.core.config.SiddhiAppContext)1