Search in sources :

Example 6 with SiddhiAppCreationException

use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.

the class JoinInputStreamParser method parseInputStream.

public static StreamRuntime parseInputStream(JoinInputStream joinInputStream, Query query, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, Map<String, Window> windowMap, Map<String, AggregationRuntime> aggregationMap, List<VariableExpressionExecutor> executors, boolean outputExpectsExpiredEvents, SiddhiQueryContext siddhiQueryContext) {
    try {
        ProcessStreamReceiver leftProcessStreamReceiver;
        ProcessStreamReceiver rightProcessStreamReceiver;
        MetaStreamEvent leftMetaStreamEvent = new MetaStreamEvent();
        MetaStreamEvent rightMetaStreamEvent = new MetaStreamEvent();
        String leftInputStreamId = ((SingleInputStream) joinInputStream.getLeftInputStream()).getStreamId();
        String rightInputStreamId = ((SingleInputStream) joinInputStream.getRightInputStream()).getStreamId();
        boolean leftOuterJoinProcessor = false;
        boolean rightOuterJoinProcessor = false;
        if (joinInputStream.getAllStreamIds().size() == 2) {
            setEventType(streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, leftMetaStreamEvent, leftInputStreamId);
            setEventType(streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, rightMetaStreamEvent, rightInputStreamId);
            leftProcessStreamReceiver = new ProcessStreamReceiver(leftInputStreamId, siddhiQueryContext);
            rightProcessStreamReceiver = new ProcessStreamReceiver(rightInputStreamId, siddhiQueryContext);
            if ((leftMetaStreamEvent.getEventType() == TABLE || leftMetaStreamEvent.getEventType() == AGGREGATE) && (rightMetaStreamEvent.getEventType() == TABLE || rightMetaStreamEvent.getEventType() == AGGREGATE)) {
                throw new SiddhiAppCreationException("Both inputs of join " + leftInputStreamId + " and " + rightInputStreamId + " are from static sources");
            }
            if (leftMetaStreamEvent.getEventType() != AGGREGATE && rightMetaStreamEvent.getEventType() != AGGREGATE) {
                if (joinInputStream.getPer() != null) {
                    throw new SiddhiAppCreationException("When joining " + leftInputStreamId + " and " + rightInputStreamId + " 'per' cannot be used as neither of them is an aggregation ");
                } else if (joinInputStream.getWithin() != null) {
                    throw new SiddhiAppCreationException("When joining " + leftInputStreamId + " and " + rightInputStreamId + " 'within' cannot be used as neither of them is an aggregation ");
                }
            }
        } else {
            if (windowDefinitionMap.containsKey(joinInputStream.getAllStreamIds().get(0))) {
                leftMetaStreamEvent.setEventType(WINDOW);
                rightMetaStreamEvent.setEventType(WINDOW);
                rightProcessStreamReceiver = new MultiProcessStreamReceiver(joinInputStream.getAllStreamIds().get(0), 1, new Object(), siddhiQueryContext);
                leftProcessStreamReceiver = rightProcessStreamReceiver;
            } else if (streamDefinitionMap.containsKey(joinInputStream.getAllStreamIds().get(0))) {
                rightProcessStreamReceiver = new MultiProcessStreamReceiver(joinInputStream.getAllStreamIds().get(0), 2, new Object(), siddhiQueryContext);
                leftProcessStreamReceiver = rightProcessStreamReceiver;
            } else {
                throw new SiddhiAppCreationException("Input of join is from static source " + leftInputStreamId + " and " + rightInputStreamId);
            }
        }
        SingleStreamRuntime leftStreamRuntime = SingleInputStreamParser.parseInputStream((SingleInputStream) joinInputStream.getLeftInputStream(), executors, streamDefinitionMap, leftMetaStreamEvent.getEventType() != TABLE ? null : tableDefinitionMap, leftMetaStreamEvent.getEventType() != WINDOW ? null : windowDefinitionMap, leftMetaStreamEvent.getEventType() != AGGREGATE ? null : aggregationDefinitionMap, tableMap, leftMetaStreamEvent, leftProcessStreamReceiver, true, outputExpectsExpiredEvents, true, false, siddhiQueryContext);
        for (VariableExpressionExecutor variableExpressionExecutor : executors) {
            variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 0;
        }
        int size = executors.size();
        SingleStreamRuntime rightStreamRuntime = SingleInputStreamParser.parseInputStream((SingleInputStream) joinInputStream.getRightInputStream(), executors, streamDefinitionMap, rightMetaStreamEvent.getEventType() != TABLE ? null : tableDefinitionMap, rightMetaStreamEvent.getEventType() != WINDOW ? null : windowDefinitionMap, rightMetaStreamEvent.getEventType() != AGGREGATE ? null : aggregationDefinitionMap, tableMap, rightMetaStreamEvent, rightProcessStreamReceiver, true, outputExpectsExpiredEvents, true, false, siddhiQueryContext);
        for (int i = size; i < executors.size(); i++) {
            VariableExpressionExecutor variableExpressionExecutor = executors.get(i);
            variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 1;
        }
        setStreamRuntimeProcessorChain(leftMetaStreamEvent, leftStreamRuntime, leftInputStreamId, tableMap, windowMap, aggregationMap, executors, outputExpectsExpiredEvents, joinInputStream.getWithin(), joinInputStream.getPer(), query.getSelector().getGroupByList(), siddhiQueryContext, joinInputStream.getLeftInputStream());
        setStreamRuntimeProcessorChain(rightMetaStreamEvent, rightStreamRuntime, rightInputStreamId, tableMap, windowMap, aggregationMap, executors, outputExpectsExpiredEvents, joinInputStream.getWithin(), joinInputStream.getPer(), query.getSelector().getGroupByList(), siddhiQueryContext, joinInputStream.getRightInputStream());
        MetaStateEvent metaStateEvent = new MetaStateEvent(2);
        metaStateEvent.addEvent(leftMetaStreamEvent);
        metaStateEvent.addEvent(rightMetaStreamEvent);
        switch(joinInputStream.getType()) {
            case FULL_OUTER_JOIN:
                leftOuterJoinProcessor = true;
                rightOuterJoinProcessor = true;
                break;
            case RIGHT_OUTER_JOIN:
                rightOuterJoinProcessor = true;
                break;
            case LEFT_OUTER_JOIN:
                leftOuterJoinProcessor = true;
                break;
        }
        JoinProcessor leftPreJoinProcessor = new JoinProcessor(true, true, leftOuterJoinProcessor, 0, siddhiQueryContext.getSiddhiAppContext().getName(), siddhiQueryContext.getName());
        JoinProcessor leftPostJoinProcessor = new JoinProcessor(true, false, leftOuterJoinProcessor, 0, siddhiQueryContext.getSiddhiAppContext().getName(), siddhiQueryContext.getName());
        FindableProcessor leftFindableProcessor = insertJoinProcessorsAndGetFindable(leftPreJoinProcessor, leftPostJoinProcessor, leftStreamRuntime, outputExpectsExpiredEvents, joinInputStream.getLeftInputStream(), siddhiQueryContext);
        JoinProcessor rightPreJoinProcessor = new JoinProcessor(false, true, rightOuterJoinProcessor, 1, siddhiQueryContext.getSiddhiAppContext().getName(), siddhiQueryContext.getName());
        JoinProcessor rightPostJoinProcessor = new JoinProcessor(false, false, rightOuterJoinProcessor, 1, siddhiQueryContext.getSiddhiAppContext().getName(), siddhiQueryContext.getName());
        FindableProcessor rightFindableProcessor = insertJoinProcessorsAndGetFindable(rightPreJoinProcessor, rightPostJoinProcessor, rightStreamRuntime, outputExpectsExpiredEvents, joinInputStream.getRightInputStream(), siddhiQueryContext);
        leftPreJoinProcessor.setFindableProcessor(rightFindableProcessor);
        leftPostJoinProcessor.setFindableProcessor(rightFindableProcessor);
        rightPreJoinProcessor.setFindableProcessor(leftFindableProcessor);
        rightPostJoinProcessor.setFindableProcessor(leftFindableProcessor);
        Expression compareCondition = joinInputStream.getOnCompare();
        if (compareCondition == null) {
            compareCondition = Expression.value(true);
        }
        QuerySelector querySelector = null;
        if (!(rightFindableProcessor instanceof TableWindowProcessor || rightFindableProcessor instanceof AggregateWindowProcessor) && (joinInputStream.getTrigger() != JoinInputStream.EventTrigger.LEFT)) {
            MatchingMetaInfoHolder leftMatchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(metaStateEvent, 1, leftMetaStreamEvent.getLastInputDefinition(), SiddhiConstants.UNKNOWN_STATE);
            CompiledCondition rightCompiledCondition = leftFindableProcessor.compileCondition(compareCondition, leftMatchingMetaInfoHolder, executors, tableMap, siddhiQueryContext);
            List<Attribute> expectedOutputAttributes = new ArrayList<>();
            CompiledSelection rightCompiledSelection = null;
            if (leftFindableProcessor instanceof TableWindowProcessor && ((TableWindowProcessor) leftFindableProcessor).isOptimisableLookup()) {
                querySelector = SelectorParser.parse(query.getSelector(), query.getOutputStream(), metaStateEvent, tableMap, executors, SiddhiConstants.UNKNOWN_STATE, ProcessingMode.BATCH, outputExpectsExpiredEvents, siddhiQueryContext);
                expectedOutputAttributes = metaStateEvent.getOutputStreamDefinition().getAttributeList();
                try {
                    rightCompiledSelection = ((QueryableProcessor) leftFindableProcessor).compileSelection(query.getSelector(), expectedOutputAttributes, leftMatchingMetaInfoHolder, executors, tableMap, siddhiQueryContext);
                } catch (SiddhiAppCreationException | SiddhiAppValidationException | QueryableRecordTableException e) {
                    if (log.isDebugEnabled()) {
                        log.debug("Performing select clause in databases failed for query: '" + siddhiQueryContext.getName() + "' within Siddhi app '" + siddhiQueryContext.getSiddhiAppContext().getName() + "' hence reverting back to " + "querying only with where clause. Reason for failure: " + e.getMessage(), e);
                    }
                // Nothing to override
                }
            }
            populateJoinProcessors(rightMetaStreamEvent, rightInputStreamId, rightPreJoinProcessor, rightPostJoinProcessor, rightCompiledCondition, rightCompiledSelection, expectedOutputAttributes);
        }
        if (!(leftFindableProcessor instanceof TableWindowProcessor || leftFindableProcessor instanceof AggregateWindowProcessor) && (joinInputStream.getTrigger() != JoinInputStream.EventTrigger.RIGHT)) {
            MatchingMetaInfoHolder rightMatchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(metaStateEvent, 0, rightMetaStreamEvent.getLastInputDefinition(), SiddhiConstants.UNKNOWN_STATE);
            CompiledCondition leftCompiledCondition = rightFindableProcessor.compileCondition(compareCondition, rightMatchingMetaInfoHolder, executors, tableMap, siddhiQueryContext);
            List<Attribute> expectedOutputAttributes = new ArrayList<>();
            CompiledSelection leftCompiledSelection = null;
            if (rightFindableProcessor instanceof TableWindowProcessor && ((TableWindowProcessor) rightFindableProcessor).isOptimisableLookup()) {
                querySelector = SelectorParser.parse(query.getSelector(), query.getOutputStream(), metaStateEvent, tableMap, executors, SiddhiConstants.UNKNOWN_STATE, ProcessingMode.BATCH, outputExpectsExpiredEvents, siddhiQueryContext);
                expectedOutputAttributes = metaStateEvent.getOutputStreamDefinition().getAttributeList();
                try {
                    leftCompiledSelection = ((QueryableProcessor) rightFindableProcessor).compileSelection(query.getSelector(), expectedOutputAttributes, rightMatchingMetaInfoHolder, executors, tableMap, siddhiQueryContext);
                } catch (SiddhiAppCreationException | SiddhiAppValidationException | QueryableRecordTableException e) {
                    if (log.isDebugEnabled()) {
                        log.debug("Performing select clause in databases failed for query: '" + siddhiQueryContext.getName() + "' within Siddhi app '" + siddhiQueryContext.getSiddhiAppContext().getName() + "' hence reverting back to " + "querying only with where clause. Reason for failure: " + e.getMessage(), e);
                    }
                // Nothing to override
                }
            }
            populateJoinProcessors(leftMetaStreamEvent, leftInputStreamId, leftPreJoinProcessor, leftPostJoinProcessor, leftCompiledCondition, leftCompiledSelection, expectedOutputAttributes);
        }
        JoinStreamRuntime joinStreamRuntime = new JoinStreamRuntime(siddhiQueryContext, metaStateEvent);
        joinStreamRuntime.addRuntime(leftStreamRuntime);
        joinStreamRuntime.addRuntime(rightStreamRuntime);
        joinStreamRuntime.setQuerySelector(querySelector);
        return joinStreamRuntime;
    } catch (Throwable t) {
        ExceptionUtil.populateQueryContext(t, joinInputStream, siddhiQueryContext.getSiddhiAppContext(), siddhiQueryContext);
        throw t;
    }
}
Also used : ProcessStreamReceiver(io.siddhi.core.query.input.ProcessStreamReceiver) MultiProcessStreamReceiver(io.siddhi.core.query.input.MultiProcessStreamReceiver) TableWindowProcessor(io.siddhi.core.query.processor.stream.window.TableWindowProcessor) Attribute(io.siddhi.query.api.definition.Attribute) ArrayList(java.util.ArrayList) AggregateWindowProcessor(io.siddhi.core.query.processor.stream.window.AggregateWindowProcessor) SingleInputStream(io.siddhi.query.api.execution.query.input.stream.SingleInputStream) QueryableRecordTableException(io.siddhi.core.exception.QueryableRecordTableException) JoinProcessor(io.siddhi.core.query.input.stream.join.JoinProcessor) FindableProcessor(io.siddhi.core.query.processor.stream.window.FindableProcessor) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) JoinStreamRuntime(io.siddhi.core.query.input.stream.join.JoinStreamRuntime) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) MultiProcessStreamReceiver(io.siddhi.core.query.input.MultiProcessStreamReceiver) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) QuerySelector(io.siddhi.core.query.selector.QuerySelector) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) CompiledCondition(io.siddhi.core.util.collection.operator.CompiledCondition) Expression(io.siddhi.query.api.expression.Expression) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) CompiledSelection(io.siddhi.core.util.collection.operator.CompiledSelection) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 7 with SiddhiAppCreationException

use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.

the class AggregationParser method initAggregateQueryExecutor.

private static Map<TimePeriod.Duration, Processor> initAggregateQueryExecutor(List<TimePeriod.Duration> aggregationDurations, Map<TimePeriod.Duration, List<ExpressionExecutor>> processExpressionExecutorsMap, StreamDefinition incomingOutputStreamDefinition, boolean isDistributed, String shardID, boolean isProcessingOnExternalTime, SiddhiQueryContext siddhiQueryContext, AggregationDefinition aggregationDefinition, ConfigManager configManager, Map<TimePeriod.Duration, Table> aggregationTables, List<Variable> groupByVariableList) {
    Map<TimePeriod.Duration, Processor> cudProcessors = new LinkedHashMap<>();
    String datasourceName = AnnotationHelper.getAnnotationElement(SiddhiConstants.NAMESPACE_STORE, "datasource", aggregationDefinition.getAnnotations()).getValue();
    if (datasourceName == null || datasourceName.isEmpty()) {
        throw new SiddhiAppCreationException("Datasource configuration must be provided inorder to use persisted " + "aggregation mode");
    }
    Database databaseType = getDatabaseType(configManager, datasourceName);
    if (log.isDebugEnabled()) {
        log.debug("Database type " + databaseType);
    }
    SiddhiAppContext cudSiddhiAppContext = new SiddhiAppContext();
    SiddhiContext context = new SiddhiContext();
    context.setConfigManager(configManager);
    cudSiddhiAppContext.setSiddhiContext(context);
    StringConstant datasource = new StringConstant(datasourceName);
    ConstantExpressionExecutor datasourceExecutor = new ConstantExpressionExecutor(datasource.getValue(), Attribute.Type.STRING);
    Expression[] streamHandler;
    ExpressionExecutor[] cudStreamProcessorInputVariables;
    if (isProcessingOnExternalTime) {
        streamHandler = new Expression[7];
    } else {
        streamHandler = new Expression[5];
    }
    try {
        DBAggregationQueryConfigurationEntry dbAggregationQueryConfigurationEntry = DBAggregationQueryUtil.lookupCurrentQueryConfigurationEntry(databaseType);
        if (log.isDebugEnabled()) {
            log.debug("CUD queries for aggregation " + aggregationDefinition.getId());
        }
        for (int i = aggregationDurations.size() - 1; i > 0; i--) {
            if (aggregationDurations.get(i).ordinal() >= 3) {
                if (log.isDebugEnabled()) {
                    log.debug(" Initializing cudProcessors for duration " + aggregationDurations.get(i));
                }
                String databaseSelectQuery = generateDatabaseQuery(processExpressionExecutorsMap.get(aggregationDurations.get(i)), dbAggregationQueryConfigurationEntry, incomingOutputStreamDefinition, isDistributed, shardID, isProcessingOnExternalTime, aggregationTables.get(aggregationDurations.get(i)), aggregationTables.get(aggregationDurations.get(i - 1)), groupByVariableList, aggregationDurations.get(i));
                StringConstant selectQuery = new StringConstant(databaseSelectQuery);
                if (log.isDebugEnabled()) {
                    log.debug(selectQuery);
                }
                ConstantExpressionExecutor selectExecutor = new ConstantExpressionExecutor(selectQuery.getValue(), Attribute.Type.STRING);
                Map<Attribute, int[]> cudInputStreamAttributesMap = generateCUDInputStreamAttributes(isProcessingOnExternalTime);
                if (isProcessingOnExternalTime) {
                    cudStreamProcessorInputVariables = new ExpressionExecutor[7];
                } else {
                    cudStreamProcessorInputVariables = new ExpressionExecutor[5];
                }
                cudStreamProcessorInputVariables[0] = datasourceExecutor;
                cudStreamProcessorInputVariables[1] = selectExecutor;
                streamHandler[0] = datasource;
                streamHandler[1] = selectQuery;
                MetaStreamEvent metaStreamEvent = generateCUDMetaStreamEvent(isProcessingOnExternalTime);
                StreamDefinition outputStream = new StreamDefinition();
                VariableExpressionExecutor variableExpressionExecutor;
                int j = 0;
                for (Map.Entry<Attribute, int[]> entry : cudInputStreamAttributesMap.entrySet()) {
                    Attribute attribute = entry.getKey();
                    Variable timestampVariable = new Variable(attribute.getName());
                    for (int position : entry.getValue()) {
                        streamHandler[position + 2] = timestampVariable;
                        variableExpressionExecutor = new VariableExpressionExecutor(attribute, 0, 0);
                        variableExpressionExecutor.setPosition(new int[] { 2, j });
                        cudStreamProcessorInputVariables[position + 2] = variableExpressionExecutor;
                    }
                    outputStream.attribute(attribute.getName(), attribute.getType());
                    j++;
                }
                StreamFunction cudStreamFunction = new StreamFunction(NAMESPACE_RDBMS, FUNCTION_NAME_CUD, streamHandler);
                cudProcessors.put(aggregationDurations.get(i), getCudProcessor(cudStreamFunction, siddhiQueryContext, metaStreamEvent, cudStreamProcessorInputVariables, aggregationDurations.get(i)));
            }
        }
        return cudProcessors;
    } catch (CannotLoadConfigurationException e) {
        throw new SiddhiAppCreationException("Error occurred while initializing the persisted incremental " + "aggregation. Could not load the db quires for database type " + databaseType);
    }
}
Also used : PersistedAggregationResultsProcessor(io.siddhi.core.aggregation.persistedaggregation.config.PersistedAggregationResultsProcessor) QueryableProcessor(io.siddhi.core.query.processor.stream.window.QueryableProcessor) AbstractStreamProcessor(io.siddhi.core.query.processor.stream.AbstractStreamProcessor) QueuedCudStreamProcessor(io.siddhi.core.aggregation.persistedaggregation.QueuedCudStreamProcessor) StreamProcessor(io.siddhi.core.query.processor.stream.StreamProcessor) Processor(io.siddhi.core.query.processor.Processor) IncrementalAggregationProcessor(io.siddhi.core.aggregation.IncrementalAggregationProcessor) Variable(io.siddhi.query.api.expression.Variable) Attribute(io.siddhi.query.api.definition.Attribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) SiddhiContext(io.siddhi.core.config.SiddhiContext) LinkedHashMap(java.util.LinkedHashMap) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) DBAggregationQueryConfigurationEntry(io.siddhi.core.aggregation.persistedaggregation.config.DBAggregationQueryConfigurationEntry) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) StreamFunction(io.siddhi.query.api.execution.query.input.handler.StreamFunction) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) CannotLoadConfigurationException(io.siddhi.core.exception.CannotLoadConfigurationException) Expression(io.siddhi.query.api.expression.Expression) SiddhiAppContext(io.siddhi.core.config.SiddhiAppContext) StringConstant(io.siddhi.query.api.expression.constant.StringConstant) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 8 with SiddhiAppCreationException

use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.

the class AggregationParser method validateBaseAggregators.

private static void validateBaseAggregators(List<IncrementalAttributeAggregator> incrementalAttributeAggregators, IncrementalAttributeAggregator incrementalAttributeAggregator, Attribute[] baseAttributes, Expression[] baseAttributeInitialValues, Expression[] baseAggregators, int i) {
    for (int i1 = i; i1 < incrementalAttributeAggregators.size(); i1++) {
        IncrementalAttributeAggregator otherAttributeAggregator = incrementalAttributeAggregators.get(i1);
        if (otherAttributeAggregator != incrementalAttributeAggregator) {
            Attribute[] otherBaseAttributes = otherAttributeAggregator.getBaseAttributes();
            Expression[] otherBaseAttributeInitialValues = otherAttributeAggregator.getBaseAttributeInitialValues();
            Expression[] otherBaseAggregators = otherAttributeAggregator.getBaseAggregators();
            for (int j = 0; j < otherBaseAttributes.length; j++) {
                if (baseAttributes[i].equals(otherBaseAttributes[j])) {
                    if (!baseAttributeInitialValues[i].equals(otherBaseAttributeInitialValues[j])) {
                        throw new SiddhiAppCreationException("BaseAttributes having same name should " + "be defined with same initial values, but baseAttribute '" + baseAttributes[i] + "' is defined in '" + incrementalAttributeAggregator.getClass().getName() + "' and '" + otherAttributeAggregator.getClass().getName() + "' with different initial values.");
                    }
                    if (!baseAggregators[i].equals(otherBaseAggregators[j])) {
                        throw new SiddhiAppCreationException("BaseAttributes having same name should " + "be defined with same baseAggregators, but baseAttribute '" + baseAttributes[i] + "' is defined in '" + incrementalAttributeAggregator.getClass().getName() + "' and '" + otherAttributeAggregator.getClass().getName() + "' with different baseAggregators.");
                    }
                }
            }
        }
    }
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) Expression(io.siddhi.query.api.expression.Expression) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) IncrementalAttributeAggregator(io.siddhi.core.query.selector.attribute.aggregator.incremental.IncrementalAttributeAggregator)

Example 9 with SiddhiAppCreationException

use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.

the class TestStoreContainingInMemoryTable method compileSelection.

@Override
protected CompiledSelection compileSelection(List<SelectAttributeBuilder> selectAttributeBuilders, List<ExpressionBuilder> groupByExpressionBuilder, ExpressionBuilder havingExpressionBuilder, List<OrderByAttributeBuilder> orderByAttributeBuilders, Long limit, Long offset) {
    selectAttributeBuilders.forEach((selectAttributeBuilder -> {
        TestStoreConditionVisitor testStoreConditionVisitor = new TestStoreConditionVisitor("");
        selectAttributeBuilder.getExpressionBuilder().build(testStoreConditionVisitor);
        if (testStoreConditionVisitor.getStreamVarCount() > 0) {
            throw new SiddhiAppCreationException("testStoreContainingInMemoryTable does not support " + "lookup with stream variables");
        }
    }));
    CompiledSelectionWithCache compiledSelectionWithCache;
    MetaStateEvent metaStateEvent = matchingMetaInfoHolderForTestOnDemandQuery.getMetaStateEvent().clone();
    ReturnStream returnStream = new ReturnStream(OutputStream.OutputEventType.CURRENT_EVENTS);
    int metaPosition = SiddhiConstants.UNKNOWN_STATE;
    List<VariableExpressionExecutor> variableExpressionExecutorsForQuerySelector = new ArrayList<>();
    if (metaStateEvent.getOutputDataAttributes().size() == 0) {
        // MetaStateEvent metaStateEventWithOutputData = new MetaStateEvent(metaStateEvent.getStreamEventCount());
        for (Attribute outputAttribute : metaStateEvent.getMetaStreamEvents()[0].getOnAfterWindowData()) {
            metaStateEvent.getMetaStreamEvents()[0].addOutputData(outputAttribute);
        }
    }
    if (metaStateEvent.getOutputDataAttributes().size() > 0) {
        while (metaStateEvent.getMetaStreamEvent(0).getOutputData().size() > 0) {
            metaStateEvent.getMetaStreamEvent(0).getOutputData().remove(0);
        }
    }
    QuerySelector querySelector = SelectorParser.parse(selectorForTestOnDemandQuery, returnStream, metaStateEvent, tableMap, variableExpressionExecutorsForQuerySelector, metaPosition, ProcessingMode.BATCH, false, siddhiQueryContextForTestOnDemandQuery);
    QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutorsForQuerySelector);
    querySelector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(metaStateEvent));
    compiledSelectionWithCache = new CompiledSelectionWithCache(null, querySelector, metaStateEvent, 0, null);
    return compiledSelectionWithCache;
}
Also used : MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) Extension(io.siddhi.annotation.Extension) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) Variable(io.siddhi.query.api.expression.Variable) AddingStreamEventExtractor(io.siddhi.core.util.collection.AddingStreamEventExtractor) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) SiddhiConstants(io.siddhi.core.util.SiddhiConstants) CompiledSelection(io.siddhi.core.util.collection.operator.CompiledSelection) Annotation(io.siddhi.query.api.annotation.Annotation) QuerySelector(io.siddhi.core.query.selector.QuerySelector) StreamEvent(io.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList) RecordIterator(io.siddhi.core.table.record.RecordIterator) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ExpressionBuilder(io.siddhi.core.table.record.ExpressionBuilder) Map(java.util.Map) InMemoryTable(io.siddhi.core.table.InMemoryTable) SelectorParser(io.siddhi.core.util.parser.SelectorParser) TableDefinition(io.siddhi.query.api.definition.TableDefinition) LinkedList(java.util.LinkedList) ProcessingMode(io.siddhi.core.query.processor.ProcessingMode) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) Event(io.siddhi.core.event.Event) CompiledUpdateSet(io.siddhi.core.table.CompiledUpdateSet) Example(io.siddhi.annotation.Example) ComplexEvent(io.siddhi.core.event.ComplexEvent) Attribute(io.siddhi.query.api.definition.Attribute) CompiledCondition(io.siddhi.core.util.collection.operator.CompiledCondition) OnDemandQueryRuntimeUtil.executeSelector(io.siddhi.core.util.OnDemandQueryRuntimeUtil.executeSelector) ConfigReader(io.siddhi.core.util.config.ConfigReader) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) StateEventPopulatorFactory(io.siddhi.core.event.state.populater.StateEventPopulatorFactory) AbstractQueryableRecordTable(io.siddhi.core.table.record.AbstractQueryableRecordTable) List(java.util.List) CompiledExpression(io.siddhi.core.util.collection.operator.CompiledExpression) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) MatcherParser(io.siddhi.core.util.parser.MatcherParser) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException) StateEvent(io.siddhi.core.event.state.StateEvent) QueryParserHelper(io.siddhi.core.util.parser.helper.QueryParserHelper) UpdateSet(io.siddhi.query.api.execution.query.output.stream.UpdateSet) ReturnStream(io.siddhi.query.api.execution.query.output.stream.ReturnStream) Attribute(io.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ArrayList(java.util.ArrayList) QuerySelector(io.siddhi.core.query.selector.QuerySelector) ReturnStream(io.siddhi.query.api.execution.query.output.stream.ReturnStream) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 10 with SiddhiAppCreationException

use of io.siddhi.core.exception.SiddhiAppCreationException in project siddhi by wso2.

the class TestStoreForCacheMiss method compileSelection.

@Override
protected CompiledSelection compileSelection(List<SelectAttributeBuilder> selectAttributeBuilders, List<ExpressionBuilder> groupByExpressionBuilder, ExpressionBuilder havingExpressionBuilder, List<OrderByAttributeBuilder> orderByAttributeBuilders, Long limit, Long offset) {
    selectAttributeBuilders.forEach((selectAttributeBuilder -> {
        TestStoreConditionVisitor testStoreConditionVisitor = new TestStoreConditionVisitor("");
        selectAttributeBuilder.getExpressionBuilder().build(testStoreConditionVisitor);
        if (testStoreConditionVisitor.getStreamVarCount() > 0) {
            throw new SiddhiAppCreationException("testStoreContainingInMemoryTable does not support " + "lookup with stream variables");
        }
    }));
    CompiledSelectionWithCache compiledSelectionWithCache;
    MetaStateEvent metaStateEvent = matchingMetaInfoHolderForTestOnDemandQuery.getMetaStateEvent().clone();
    ReturnStream returnStream = new ReturnStream(OutputStream.OutputEventType.CURRENT_EVENTS);
    int metaPosition = SiddhiConstants.UNKNOWN_STATE;
    List<VariableExpressionExecutor> variableExpressionExecutorsForQuerySelector = new ArrayList<>();
    if (metaStateEvent.getOutputDataAttributes().size() == 0) {
        for (Attribute outputAttribute : metaStateEvent.getMetaStreamEvents()[0].getOnAfterWindowData()) {
            metaStateEvent.getMetaStreamEvents()[0].addOutputData(outputAttribute);
        }
    }
    QuerySelector querySelector = SelectorParser.parse(selectorForTestOnDemandQuery, returnStream, metaStateEvent, tableMap, variableExpressionExecutorsForQuerySelector, metaPosition, ProcessingMode.BATCH, false, siddhiQueryContextForTestOnDemandQuery);
    QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutorsForQuerySelector);
    querySelector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(metaStateEvent));
    compiledSelectionWithCache = new CompiledSelectionWithCache(null, querySelector, metaStateEvent, 0, null);
    return compiledSelectionWithCache;
}
Also used : Extension(io.siddhi.annotation.Extension) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) SiddhiConstants(io.siddhi.core.util.SiddhiConstants) CompiledSelection(io.siddhi.core.util.collection.operator.CompiledSelection) Annotation(io.siddhi.query.api.annotation.Annotation) QuerySelector(io.siddhi.core.query.selector.QuerySelector) StreamEvent(io.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList) RecordIterator(io.siddhi.core.table.record.RecordIterator) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ExpressionBuilder(io.siddhi.core.table.record.ExpressionBuilder) Map(java.util.Map) InMemoryTable(io.siddhi.core.table.InMemoryTable) SelectorParser(io.siddhi.core.util.parser.SelectorParser) TableDefinition(io.siddhi.query.api.definition.TableDefinition) LinkedList(java.util.LinkedList) ProcessingMode(io.siddhi.core.query.processor.ProcessingMode) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) Event(io.siddhi.core.event.Event) Example(io.siddhi.annotation.Example) ComplexEvent(io.siddhi.core.event.ComplexEvent) Attribute(io.siddhi.query.api.definition.Attribute) CompiledCondition(io.siddhi.core.util.collection.operator.CompiledCondition) OnDemandQueryRuntimeUtil.executeSelector(io.siddhi.core.util.OnDemandQueryRuntimeUtil.executeSelector) ConfigReader(io.siddhi.core.util.config.ConfigReader) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) StateEventPopulatorFactory(io.siddhi.core.event.state.populater.StateEventPopulatorFactory) AbstractQueryableRecordTable(io.siddhi.core.table.record.AbstractQueryableRecordTable) List(java.util.List) CompiledExpression(io.siddhi.core.util.collection.operator.CompiledExpression) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException) StateEvent(io.siddhi.core.event.state.StateEvent) QueryParserHelper(io.siddhi.core.util.parser.helper.QueryParserHelper) ReturnStream(io.siddhi.query.api.execution.query.output.stream.ReturnStream) Attribute(io.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ArrayList(java.util.ArrayList) QuerySelector(io.siddhi.core.query.selector.QuerySelector) ReturnStream(io.siddhi.query.api.execution.query.output.stream.ReturnStream) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Aggregations

SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)54 Attribute (io.siddhi.query.api.definition.Attribute)23 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)16 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)15 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)12 SiddhiManager (io.siddhi.core.SiddhiManager)12 ArrayList (java.util.ArrayList)12 Expression (io.siddhi.query.api.expression.Expression)11 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)10 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)10 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)10 Annotation (io.siddhi.query.api.annotation.Annotation)10 Variable (io.siddhi.query.api.expression.Variable)10 ConfigReader (io.siddhi.core.util.config.ConfigReader)9 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)9 Element (io.siddhi.query.api.annotation.Element)8 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)8 Table (io.siddhi.core.table.Table)7 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)7