Search in sources :

Example 11 with AbstractDefinition

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

the class SiddhiAppRuntimeBuilder method defineTable.

public void defineTable(TableDefinition tableDefinition) {
    DefinitionParserHelper.validateDefinition(tableDefinition, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap);
    AbstractDefinition currentDefinition = tableDefinitionMap.putIfAbsent(tableDefinition.getId(), tableDefinition);
    if (currentDefinition != null) {
        tableDefinition = (TableDefinition) currentDefinition;
    }
    DefinitionParserHelper.addTable(tableDefinition, tableMap, siddhiAppContext);
}
Also used : AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition)

Example 12 with AbstractDefinition

use of io.siddhi.query.api.definition.AbstractDefinition 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);
}
Also used : AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition)

Example 13 with AbstractDefinition

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

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

the class SiddhiAppRuntimeBuilder method defineStream.

public void defineStream(StreamDefinition streamDefinition) {
    DefinitionParserHelper.validateDefinition(streamDefinition, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap);
    AbstractDefinition currentDefinition = streamDefinitionMap.putIfAbsent(streamDefinition.getId(), streamDefinition);
    if (currentDefinition != null) {
        streamDefinition = (StreamDefinition) currentDefinition;
    }
    try {
        DefinitionParserHelper.addStreamJunction(streamDefinition, streamJunctionMap, siddhiAppContext);
    } catch (Throwable t) {
        ExceptionUtil.populateQueryContext(t, streamDefinition, siddhiAppContext);
        throw t;
    }
    DefinitionParserHelper.addEventSource(streamDefinition, sourceMap, siddhiAppContext);
    StreamJunction streamJunction = streamJunctionMap.get(streamDefinition.getId());
    DefinitionParserHelper.addEventSink(streamDefinition, streamJunction, sinkMap, siddhiAppContext);
}
Also used : StreamJunction(io.siddhi.core.stream.StreamJunction) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition)

Example 15 with AbstractDefinition

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

the class StreamEventConverterFactory method getConversionElements.

private static List<StreamEventConverter.ConversionMapping> getConversionElements(MetaStreamEvent metaStreamEvent, int size) {
    AbstractDefinition inputDefinition = metaStreamEvent.getInputDefinitions().get(0);
    List<StreamEventConverter.ConversionMapping> conversionMappings = new ArrayList<StreamEventConverter.ConversionMapping>(size);
    for (int j = 0; j < 3; j++) {
        List<Attribute> currentDataList = null;
        if (j == 0) {
            currentDataList = metaStreamEvent.getBeforeWindowData();
        } else if (j == 1) {
            currentDataList = metaStreamEvent.getOnAfterWindowData();
        } else if (j == 2) {
            currentDataList = metaStreamEvent.getOutputData();
        }
        if (currentDataList != null) {
            int i = 0;
            for (Attribute attribute : currentDataList) {
                // Only variable slots will be filled.
                if (attribute == null) {
                    i++;
                } else if (!inputDefinition.getAttributeList().contains(attribute)) {
                    i++;
                } else {
                    int fromPosition = inputDefinition.getAttributePosition(attribute.getName());
                    StreamEventConverter.ConversionMapping conversionMapping = new StreamEventConverter.ConversionMapping();
                    conversionMapping.setFromPosition(fromPosition);
                    int[] toPosition = new int[2];
                    toPosition[0] = j;
                    toPosition[1] = i;
                    conversionMapping.setToPosition(toPosition);
                    conversionMappings.add(conversionMapping);
                    i++;
                }
            }
        }
    }
    return conversionMappings;
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) ArrayList(java.util.ArrayList) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition)

Aggregations

AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)24 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)12 Attribute (io.siddhi.query.api.definition.Attribute)12 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)9 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)9 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)8 ArrayList (java.util.ArrayList)8 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)7 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)7 Variable (io.siddhi.query.api.expression.Variable)7 Expression (io.siddhi.query.api.expression.Expression)6 Table (io.siddhi.core.table.Table)5 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)5 AttributeFunction (io.siddhi.query.api.expression.AttributeFunction)5 SiddhiAppContext (io.siddhi.core.config.SiddhiAppContext)4 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)4 SiddhiAppValidationException (io.siddhi.query.api.exception.SiddhiAppValidationException)4 AndConditionExpressionExecutor (io.siddhi.core.executor.condition.AndConditionExpressionExecutor)3 BoolConditionExpressionExecutor (io.siddhi.core.executor.condition.BoolConditionExpressionExecutor)3 ConditionExpressionExecutor (io.siddhi.core.executor.condition.ConditionExpressionExecutor)3