Search in sources :

Example 1 with WindowDefinition

use of io.siddhi.query.api.definition.WindowDefinition 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 2 with WindowDefinition

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

the class SiddhiQLBaseVisitorImpl method visitDefinition_window.

@Override
public Object visitDefinition_window(@NotNull SiddhiQLParser.Definition_windowContext ctx) {
    Source source = (Source) visit(ctx.source());
    if (source.isInnerStream) {
        throw newSiddhiParserException(ctx, " '#' cannot be used, because Windows can't be defined " + "as InnerStream!");
    }
    if (source.isFaultStream) {
        throw newSiddhiParserException(ctx, " '!' cannot be used, because Windows can't be defined " + "as FaultStream!");
    }
    WindowDefinition windowDefinition = WindowDefinition.id(source.streamId);
    List<SiddhiQLParser.Attribute_nameContext> attribute_names = ctx.attribute_name();
    List<SiddhiQLParser.Attribute_typeContext> attribute_types = ctx.attribute_type();
    for (int i = 0; i < attribute_names.size(); i++) {
        SiddhiQLParser.Attribute_nameContext attributeNameContext = attribute_names.get(i);
        SiddhiQLParser.Attribute_typeContext attributeTypeContext = attribute_types.get(i);
        windowDefinition.attribute((String) visit(attributeNameContext), (Attribute.Type) visit(attributeTypeContext));
    }
    for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
        windowDefinition.annotation((Annotation) visit(annotationContext));
    }
    AttributeFunction attributeFunction = (AttributeFunction) visit(ctx.function_operation());
    Window window = new Window(attributeFunction.getNamespace(), attributeFunction.getName(), attributeFunction.getParameters());
    windowDefinition.window(window);
    // Optional output event type
    if (ctx.output_event_type() != null) {
        windowDefinition.setOutputEventType((OutputStream.OutputEventType) visit(ctx.output_event_type()));
    }
    populateQueryContext(windowDefinition, ctx);
    return windowDefinition;
}
Also used : Window(io.siddhi.query.api.execution.query.input.handler.Window) SiddhiQLParser(io.siddhi.query.compiler.SiddhiQLParser) Attribute(io.siddhi.query.api.definition.Attribute) OrderByAttribute(io.siddhi.query.api.execution.query.selection.OrderByAttribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) AttributeFunction(io.siddhi.query.api.expression.AttributeFunction) WindowDefinition(io.siddhi.query.api.definition.WindowDefinition)

Example 3 with WindowDefinition

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

the class SiddhiApp method checkDuplicateDefinition.

private void checkDuplicateDefinition(AbstractDefinition definition) {
    TableDefinition 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());
    }
    StreamDefinition 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());
    }
    WindowDefinition existingWindowDefinition = windowDefinitionMap.get(definition.getId());
    if (existingWindowDefinition != null && (!existingWindowDefinition.equals(definition) || definition instanceof WindowDefinition)) {
        throw new DuplicateDefinitionException("Stream Definition with same Window Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AggregationDefinition existingAggregationDefinition = aggregationDefinitionMap.get(definition.getId());
    if (existingAggregationDefinition != null && (!existingAggregationDefinition.equals(definition) || definition instanceof AggregationDefinition)) {
        throw new DuplicateDefinitionException("Aggregate Definition with same Aggregate Id '" + definition.getId() + "' already exist : " + existingAggregationDefinition + ", 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) TableDefinition(io.siddhi.query.api.definition.TableDefinition) WindowDefinition(io.siddhi.query.api.definition.WindowDefinition)

Aggregations

WindowDefinition (io.siddhi.query.api.definition.WindowDefinition)3 AggregationDefinition (io.siddhi.query.api.definition.AggregationDefinition)2 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)2 TableDefinition (io.siddhi.query.api.definition.TableDefinition)2 DuplicateDefinitionException (io.siddhi.query.api.exception.DuplicateDefinitionException)2 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)1 Attribute (io.siddhi.query.api.definition.Attribute)1 Window (io.siddhi.query.api.execution.query.input.handler.Window)1 OutputStream (io.siddhi.query.api.execution.query.output.stream.OutputStream)1 OrderByAttribute (io.siddhi.query.api.execution.query.selection.OrderByAttribute)1 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)1 AttributeFunction (io.siddhi.query.api.expression.AttributeFunction)1 SiddhiQLParser (io.siddhi.query.compiler.SiddhiQLParser)1