Search in sources :

Example 16 with VariableExpressionExecutor

use of io.siddhi.core.executor.VariableExpressionExecutor in project siddhi by wso2.

the class PartitionParser method parse.

public static PartitionRuntimeImpl parse(SiddhiAppRuntimeBuilder siddhiAppRuntimeBuilder, Partition partition, SiddhiAppContext siddhiAppContext, int queryIndex, int partitionIndex) {
    ConcurrentMap<String, AbstractDefinition> streamDefinitionMap = siddhiAppRuntimeBuilder.getStreamDefinitionMap();
    ConcurrentMap<String, AbstractDefinition> windowDefinitionMap = siddhiAppRuntimeBuilder.getWindowDefinitionMap();
    validateStreamPartitions(partition.getPartitionTypeMap(), streamDefinitionMap, windowDefinitionMap);
    PartitionRuntimeImpl partitionRuntime = new PartitionRuntimeImpl(streamDefinitionMap, windowDefinitionMap, siddhiAppRuntimeBuilder.getStreamJunctions(), partition, partitionIndex, siddhiAppContext);
    for (Query query : partition.getQueryList()) {
        List<VariableExpressionExecutor> executors = new ArrayList<VariableExpressionExecutor>();
        ConcurrentMap<String, AbstractDefinition> combinedStreamMap = new ConcurrentHashMap<String, AbstractDefinition>();
        combinedStreamMap.putAll(streamDefinitionMap);
        combinedStreamMap.putAll(windowDefinitionMap);
        combinedStreamMap.putAll(partitionRuntime.getLocalStreamDefinitionMap());
        QueryRuntimeImpl queryRuntime = QueryParser.parse(query, siddhiAppContext, combinedStreamMap, siddhiAppRuntimeBuilder.getTableDefinitionMap(), siddhiAppRuntimeBuilder.getWindowDefinitionMap(), siddhiAppRuntimeBuilder.getAggregationDefinitionMap(), siddhiAppRuntimeBuilder.getTableMap(), siddhiAppRuntimeBuilder.getAggregationMap(), siddhiAppRuntimeBuilder.getWindowMap(), siddhiAppRuntimeBuilder.getLockSynchronizer(), String.valueOf(queryIndex), true, partitionRuntime.getPartitionName());
        queryIndex++;
        MetaStateEvent metaStateEvent = createMetaEventForPartitioner(queryRuntime.getMetaComplexEvent());
        partitionRuntime.addQuery(queryRuntime);
        partitionRuntime.addPartitionReceiver(queryRuntime, executors, metaStateEvent);
        QueryParserHelper.reduceMetaComplexEvent(metaStateEvent);
        if (queryRuntime.getMetaComplexEvent() instanceof MetaStateEvent) {
            QueryParserHelper.updateVariablePosition(metaStateEvent, executors);
        } else {
            QueryParserHelper.updateVariablePosition(metaStateEvent.getMetaStreamEvent(0), executors);
        }
    }
    partitionRuntime.init();
    return partitionRuntime;
}
Also used : QueryRuntimeImpl(io.siddhi.core.query.QueryRuntimeImpl) Query(io.siddhi.query.api.execution.query.Query) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ArrayList(java.util.ArrayList) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PartitionRuntimeImpl(io.siddhi.core.partition.PartitionRuntimeImpl) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 17 with VariableExpressionExecutor

use of io.siddhi.core.executor.VariableExpressionExecutor in project siddhi by wso2.

the class AggregationParser method processAggregationSelectors.

private static void processAggregationSelectors(AggregationDefinition aggregationDefinition, SiddhiQueryContext siddhiQueryContext, Map<String, Table> tableMap, List<VariableExpressionExecutor> incomingVariableExpressionExecutors, MetaStreamEvent incomingMetaStreamEvent, List<ExpressionExecutor> incomingExpressionExecutors, List<Expression> outputExpressions, OutputAttribute outputAttribute, Expression expression) {
    ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, incomingMetaStreamEvent, 0, tableMap, incomingVariableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
    incomingExpressionExecutors.add(expressionExecutor);
    incomingMetaStreamEvent.addOutputData(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
    aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
    outputExpressions.add(Expression.variable(outputAttribute.getRename()));
}
Also used : ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) Attribute(io.siddhi.query.api.definition.Attribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute)

Example 18 with VariableExpressionExecutor

use of io.siddhi.core.executor.VariableExpressionExecutor 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 19 with VariableExpressionExecutor

use of io.siddhi.core.executor.VariableExpressionExecutor 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)

Example 20 with VariableExpressionExecutor

use of io.siddhi.core.executor.VariableExpressionExecutor in project siddhi by wso2.

the class StreamPartitioner method createJoinInputStreamExecutors.

private void createJoinInputStreamExecutors(JoinInputStream inputStream, Partition partition, MetaStateEvent metaEvent, List<VariableExpressionExecutor> executors, SiddhiQueryContext siddhiQueryContext) {
    createExecutors(inputStream.getLeftInputStream(), partition, metaEvent.getMetaStreamEvent(0), executors, siddhiQueryContext);
    int size = executors.size();
    for (VariableExpressionExecutor variableExpressionExecutor : executors) {
        variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 0;
    }
    createExecutors(inputStream.getRightInputStream(), partition, metaEvent.getMetaStreamEvent(1), executors, siddhiQueryContext);
    for (int i = size; i < executors.size(); i++) {
        executors.get(i).getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 1;
    }
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor)

Aggregations

VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)48 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)32 Attribute (io.siddhi.query.api.definition.Attribute)27 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)23 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)23 ArrayList (java.util.ArrayList)20 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)18 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)15 Variable (io.siddhi.query.api.expression.Variable)14 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)13 Expression (io.siddhi.query.api.expression.Expression)13 Map (java.util.Map)13 HashMap (java.util.HashMap)11 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)10 StreamEvent (io.siddhi.core.event.stream.StreamEvent)9 Table (io.siddhi.core.table.Table)8 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)8 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)7 CompiledCondition (io.siddhi.core.util.collection.operator.CompiledCondition)7 AndConditionExpressionExecutor (io.siddhi.core.executor.condition.AndConditionExpressionExecutor)5