Search in sources :

Example 1 with WindowDefinition

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

Example 2 with WindowDefinition

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

the class SiddhiAppRuntimeBuilder method defineWindow.

public void defineWindow(WindowDefinition windowDefinition) {
    DefinitionParserHelper.validateDefinition(windowDefinition, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap);
    DefinitionParserHelper.addStreamJunction(windowDefinition, streamJunctionMap, siddhiAppContext);
    AbstractDefinition currentDefinition = windowDefinitionMap.putIfAbsent(windowDefinition.getId(), windowDefinition);
    if (currentDefinition != null) {
        windowDefinition = (WindowDefinition) currentDefinition;
    }
    DefinitionParserHelper.addWindow(windowDefinition, windowMap, siddhiAppContext);
// defineStream(windowDefinition);
// DefinitionParserHelper.addStreamJunction(windowDefinition, streamJunctionMap, siddhiAppContext);
}
Also used : AbstractDefinition(org.wso2.siddhi.query.api.definition.AbstractDefinition)

Example 3 with WindowDefinition

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

the class Window method init.

/**
 * Initialize the WindowEvent table by creating {@link WindowProcessor} to handle the events.
 *
 * @param tableMap       map of {@link Table}s
 * @param eventWindowMap map of EventWindows
 * @param queryName      name of the query window belongs to.
 */
public void init(Map<String, Table> tableMap, Map<String, Window> eventWindowMap, String queryName) {
    if (this.windowProcessor != null) {
        return;
    }
    // Create and initialize MetaStreamEvent
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addInputDefinition(windowDefinition);
    metaStreamEvent.setEventType(MetaStreamEvent.EventType.WINDOW);
    metaStreamEvent.initializeAfterWindowData();
    for (Attribute attribute : windowDefinition.getAttributeList()) {
        metaStreamEvent.addOutputData(attribute);
    }
    this.streamEventPool = new StreamEventPool(metaStreamEvent, 5);
    StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, this.streamEventPool);
    OutputStream.OutputEventType outputEventType = windowDefinition.getOutputEventType();
    boolean outputExpectsExpiredEvents = outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS;
    WindowProcessor internalWindowProcessor = (WindowProcessor) SingleInputStreamParser.generateProcessor(windowDefinition.getWindow(), metaStreamEvent, new ArrayList<VariableExpressionExecutor>(), this.siddhiAppContext, tableMap, false, outputExpectsExpiredEvents, queryName);
    internalWindowProcessor.setStreamEventCloner(streamEventCloner);
    internalWindowProcessor.constructStreamEventPopulater(metaStreamEvent, 0);
    EntryValveProcessor entryValveProcessor = null;
    if (internalWindowProcessor instanceof SchedulingProcessor) {
        entryValveProcessor = new EntryValveProcessor(this.siddhiAppContext);
        Scheduler scheduler = SchedulerParser.parse(this.siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, this.siddhiAppContext);
        scheduler.init(this.lockWrapper, queryName);
        scheduler.setStreamEventPool(streamEventPool);
        ((SchedulingProcessor) internalWindowProcessor).setScheduler(scheduler);
    }
    if (entryValveProcessor != null) {
        entryValveProcessor.setToLast(internalWindowProcessor);
        this.windowProcessor = entryValveProcessor;
    } else {
        this.windowProcessor = internalWindowProcessor;
    }
    // StreamPublishProcessor must be the last in chain so that it can publish the events to StreamJunction
    this.windowProcessor.setToLast(new StreamPublishProcessor(outputEventType));
    this.internalWindowProcessor = internalWindowProcessor;
}
Also used : Attribute(org.wso2.siddhi.query.api.definition.Attribute) Scheduler(org.wso2.siddhi.core.util.Scheduler) OutputStream(org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream) ArrayList(java.util.ArrayList) SchedulingProcessor(org.wso2.siddhi.core.query.processor.SchedulingProcessor) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) StreamEventCloner(org.wso2.siddhi.core.event.stream.StreamEventCloner) EntryValveProcessor(org.wso2.siddhi.core.query.input.stream.single.EntryValveProcessor) WindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.WindowProcessor) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Example 4 with WindowDefinition

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

the class SiddhiApp method defineWindow.

public SiddhiApp defineWindow(WindowDefinition windowDefinition) {
    if (windowDefinition == null) {
        throw new SiddhiAppValidationException("Window Definition should not be null");
    } else if (windowDefinition.getId() == null) {
        throw new SiddhiAppValidationException("Window Id should not be null for Window Definition", windowDefinition.getQueryContextStartIndex(), windowDefinition.getQueryContextEndIndex());
    }
    checkDuplicateDefinition(windowDefinition);
    this.windowDefinitionMap.put(windowDefinition.getId(), windowDefinition);
    return this;
}
Also used : SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)

Example 5 with WindowDefinition

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

Aggregations

WindowDefinition (org.wso2.siddhi.query.api.definition.WindowDefinition)3 AbstractDefinition (org.wso2.siddhi.query.api.definition.AbstractDefinition)2 AggregationDefinition (org.wso2.siddhi.query.api.definition.AggregationDefinition)2 Attribute (org.wso2.siddhi.query.api.definition.Attribute)2 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)2 TableDefinition (org.wso2.siddhi.query.api.definition.TableDefinition)2 DuplicateDefinitionException (org.wso2.siddhi.query.api.exception.DuplicateDefinitionException)2 OutputStream (org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream)2 SiddhiQLParser (org.wso2.siddhi.query.compiler.SiddhiQLParser)2 ArrayList (java.util.ArrayList)1 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)1 StreamEventCloner (org.wso2.siddhi.core.event.stream.StreamEventCloner)1 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)1 EntryValveProcessor (org.wso2.siddhi.core.query.input.stream.single.EntryValveProcessor)1 SchedulingProcessor (org.wso2.siddhi.core.query.processor.SchedulingProcessor)1 WindowProcessor (org.wso2.siddhi.core.query.processor.stream.window.WindowProcessor)1 Scheduler (org.wso2.siddhi.core.util.Scheduler)1 Window (org.wso2.siddhi.core.window.Window)1 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)1 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)1