Search in sources :

Example 1 with WindowDefinition

use of org.ballerinalang.siddhi.query.api.definition.WindowDefinition in project ballerina by ballerina-lang.

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(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) DuplicateDefinitionException(org.ballerinalang.siddhi.query.api.exception.DuplicateDefinitionException) AggregationDefinition(org.ballerinalang.siddhi.query.api.definition.AggregationDefinition) AbstractDefinition(org.ballerinalang.siddhi.query.api.definition.AbstractDefinition) TableDefinition(org.ballerinalang.siddhi.query.api.definition.TableDefinition) WindowDefinition(org.ballerinalang.siddhi.query.api.definition.WindowDefinition)

Example 2 with WindowDefinition

use of org.ballerinalang.siddhi.query.api.definition.WindowDefinition in project ballerina by ballerina-lang.

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(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) DuplicateDefinitionException(org.ballerinalang.siddhi.query.api.exception.DuplicateDefinitionException) AggregationDefinition(org.ballerinalang.siddhi.query.api.definition.AggregationDefinition) TableDefinition(org.ballerinalang.siddhi.query.api.definition.TableDefinition) WindowDefinition(org.ballerinalang.siddhi.query.api.definition.WindowDefinition)

Example 3 with WindowDefinition

use of org.ballerinalang.siddhi.query.api.definition.WindowDefinition in project ballerina by ballerina-lang.

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!");
    }
    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(org.ballerinalang.siddhi.query.api.execution.query.input.handler.Window) SiddhiQLParser(org.ballerinalang.siddhi.query.compiler.SiddhiQLParser) OrderByAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OrderByAttribute) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) OutputAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute) OutputStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.OutputStream) AttributeFunction(org.ballerinalang.siddhi.query.api.expression.AttributeFunction) WindowDefinition(org.ballerinalang.siddhi.query.api.definition.WindowDefinition)

Aggregations

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