Search in sources :

Example 36 with VariableExpressionExecutor

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

the class StoreQueryParser method constructStoreQueryRuntime.

private static StoreQueryRuntime constructStoreQueryRuntime(Table table, StoreQuery storeQuery, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, String queryName, int metaPosition, Expression onCondition, MetaStreamEvent metaStreamEvent, List<VariableExpressionExecutor> variableExpressionExecutors) {
    metaStreamEvent.setEventType(EventType.TABLE);
    initMetaStreamEvent(metaStreamEvent, table.getTableDefinition());
    MatchingMetaInfoHolder metaStreamInfoHolder = generateMatchingMetaInfoHolder(metaStreamEvent, table.getTableDefinition());
    CompiledCondition compiledCondition = table.compileCondition(onCondition, metaStreamInfoHolder, siddhiAppContext, variableExpressionExecutors, tableMap, queryName);
    if (table instanceof QueryableProcessor) {
        List<Attribute> expectedOutputAttributes = buildExpectedOutputAttributes(storeQuery, siddhiAppContext, tableMap, queryName, metaPosition, metaStreamInfoHolder);
        CompiledSelection compiledSelection = ((QueryableProcessor) table).compileSelection(storeQuery.getSelector(), expectedOutputAttributes, metaStreamInfoHolder, siddhiAppContext, variableExpressionExecutors, tableMap, queryName);
        SelectStoreQueryRuntime storeQueryRuntime = new SelectStoreQueryRuntime((QueryableProcessor) table, compiledCondition, compiledSelection, expectedOutputAttributes, queryName);
        QueryParserHelper.reduceMetaComplexEvent(metaStreamInfoHolder.getMetaStateEvent());
        QueryParserHelper.updateVariablePosition(metaStreamInfoHolder.getMetaStateEvent(), variableExpressionExecutors);
        return storeQueryRuntime;
    } else {
        FindStoreQueryRuntime storeQueryRuntime = new FindStoreQueryRuntime(table, compiledCondition, queryName, metaStreamEvent);
        populateFindStoreQueryRuntime(storeQueryRuntime, metaStreamInfoHolder, storeQuery.getSelector(), variableExpressionExecutors, siddhiAppContext, tableMap, queryName, metaPosition);
        return storeQueryRuntime;
    }
}
Also used : CompiledCondition(org.wso2.siddhi.core.util.collection.operator.CompiledCondition) SelectStoreQueryRuntime(org.wso2.siddhi.core.query.SelectStoreQueryRuntime) Attribute(org.wso2.siddhi.query.api.definition.Attribute) MatchingMetaInfoHolder(org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) CompiledSelection(org.wso2.siddhi.core.util.collection.operator.CompiledSelection) FindStoreQueryRuntime(org.wso2.siddhi.core.query.FindStoreQueryRuntime) QueryableProcessor(org.wso2.siddhi.core.query.processor.stream.window.QueryableProcessor)

Example 37 with VariableExpressionExecutor

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

the class QueryParserHelper method updateVariablePosition.

public static void updateVariablePosition(MetaComplexEvent metaComplexEvent, List<VariableExpressionExecutor> variableExpressionExecutorList) {
    for (VariableExpressionExecutor variableExpressionExecutor : variableExpressionExecutorList) {
        int streamEventChainIndex = variableExpressionExecutor.getPosition()[STREAM_EVENT_CHAIN_INDEX];
        if (streamEventChainIndex == HAVING_STATE) {
            if (metaComplexEvent instanceof MetaStreamEvent) {
                variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = OUTPUT_DATA_INDEX;
            } else {
                variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = STATE_OUTPUT_DATA_INDEX;
            }
            variableExpressionExecutor.getPosition()[STREAM_EVENT_CHAIN_INDEX] = UNKNOWN_STATE;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaComplexEvent.getOutputStreamDefinition().getAttributeList().indexOf(variableExpressionExecutor.getAttribute());
            continue;
        } else if (metaComplexEvent instanceof MetaStreamEvent && streamEventChainIndex >= 1) {
            // VariableExpressionExecutor on Event table
            continue;
        } else if (metaComplexEvent instanceof MetaStateEvent && streamEventChainIndex >= ((MetaStateEvent) metaComplexEvent).getMetaStreamEvents().length) {
            // for VariableExpressionExecutor on Event table
            continue;
        }
        MetaStreamEvent metaStreamEvent;
        if (metaComplexEvent instanceof MetaStreamEvent) {
            metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
        } else {
            metaStreamEvent = ((MetaStateEvent) metaComplexEvent).getMetaStreamEvent(streamEventChainIndex);
        }
        if (metaStreamEvent.getOutputData().contains(variableExpressionExecutor.getAttribute())) {
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = OUTPUT_DATA_INDEX;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaStreamEvent.getOutputData().indexOf(variableExpressionExecutor.getAttribute());
        } else if (metaStreamEvent.getOnAfterWindowData().contains(variableExpressionExecutor.getAttribute())) {
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = ON_AFTER_WINDOW_DATA_INDEX;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaStreamEvent.getOnAfterWindowData().indexOf(variableExpressionExecutor.getAttribute());
        } else if (metaStreamEvent.getBeforeWindowData().contains(variableExpressionExecutor.getAttribute())) {
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = BEFORE_WINDOW_DATA_INDEX;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaStreamEvent.getBeforeWindowData().indexOf(variableExpressionExecutor.getAttribute());
        }
    }
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent)

Example 38 with VariableExpressionExecutor

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

the class PartitionRuntime method addPartitionReceiver.

public void addPartitionReceiver(QueryRuntime queryRuntime, List<VariableExpressionExecutor> executors, MetaStateEvent metaEvent) {
    Query query = queryRuntime.getQuery();
    List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(), partition, metaEvent, executors, siddhiAppContext, null).getPartitionExecutorLists();
    if (queryRuntime.getStreamRuntime() instanceof SingleStreamRuntime) {
        SingleInputStream singleInputStream = (SingleInputStream) query.getInputStream();
        addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
    } else if (queryRuntime.getStreamRuntime() instanceof JoinStreamRuntime) {
        SingleInputStream leftSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream();
        addPartitionReceiver(leftSingleInputStream.getStreamId(), leftSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
        SingleInputStream rightSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getRightInputStream();
        addPartitionReceiver(rightSingleInputStream.getStreamId(), rightSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(1), partitionExecutors.get(1));
    } else if (queryRuntime.getStreamRuntime() instanceof StateStreamRuntime) {
        StateElement stateElement = ((StateInputStream) query.getInputStream()).getStateElement();
        addPartitionReceiverForStateElement(stateElement, metaEvent, partitionExecutors, 0);
    }
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinStreamRuntime(org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime) JoinInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream) StateElement(org.wso2.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement) LogicalStateElement(org.wso2.siddhi.query.api.execution.query.input.state.LogicalStateElement) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) ArrayList(java.util.ArrayList) List(java.util.List) StateInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream) StateStreamRuntime(org.wso2.siddhi.core.query.input.stream.state.StateStreamRuntime)

Example 39 with VariableExpressionExecutor

use of org.wso2.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, SiddhiAppContext siddhiAppContext, String queryName) {
    createExecutors(inputStream.getLeftInputStream(), partition, metaEvent.getMetaStreamEvent(0), executors, siddhiAppContext, queryName);
    int size = executors.size();
    for (VariableExpressionExecutor variableExpressionExecutor : executors) {
        variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 0;
    }
    createExecutors(inputStream.getRightInputStream(), partition, metaEvent.getMetaStreamEvent(1), executors, siddhiAppContext, queryName);
    for (int i = size; i < executors.size(); i++) {
        executors.get(i).getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 1;
    }
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor)

Example 40 with VariableExpressionExecutor

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

the class ExternalTimeBatchWindowProcessor method init.

@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
    this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
    if (outputExpectsExpiredEvents) {
        this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
        this.storeExpiredEvents = true;
    }
    if (attributeExpressionExecutors.length >= 2 && attributeExpressionExecutors.length <= 5) {
        if (!(attributeExpressionExecutors[0] instanceof VariableExpressionExecutor)) {
            throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timestamp should be a" + " variable, but found " + attributeExpressionExecutors[0].getClass());
        }
        if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.LONG) {
            throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timestamp should be " + "type long, but found " + attributeExpressionExecutors[0].getReturnType());
        }
        timestampExpressionExecutor = (VariableExpressionExecutor) attributeExpressionExecutors[0];
        if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
            timeToKeep = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
        } else if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.LONG) {
            timeToKeep = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
        } else {
            throw new SiddhiAppValidationException("ExternalTimeBatch window's 2nd parameter windowTime " + "should be either int or long, but found " + attributeExpressionExecutors[1].getReturnType());
        }
        if (attributeExpressionExecutors.length >= 3) {
            isStartTimeEnabled = true;
            if ((attributeExpressionExecutors[2] instanceof ConstantExpressionExecutor)) {
                if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.INT) {
                    startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
                } else if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.LONG) {
                    startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[2]).getValue()));
                } else {
                    throw new SiddhiAppValidationException("ExternalTimeBatch window's 3rd parameter " + "startTime should either be a constant (of type int or long) or an attribute (of type" + " long), but found " + attributeExpressionExecutors[2].getReturnType());
                }
            } else if (attributeExpressionExecutors[2].getReturnType() != Attribute.Type.LONG) {
                throw new SiddhiAppValidationException("ExternalTimeBatch window's 3rd parameter startTime " + "should either be a constant (of type int or long) or an attribute (of type long), but " + "found " + attributeExpressionExecutors[2].getReturnType());
            } else {
                startTimeAsVariable = attributeExpressionExecutors[2];
            }
        }
        if (attributeExpressionExecutors.length >= 4) {
            if (attributeExpressionExecutors[3].getReturnType() == Attribute.Type.INT) {
                schedulerTimeout = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[3]).getValue()));
            } else if (attributeExpressionExecutors[3].getReturnType() == Attribute.Type.LONG) {
                schedulerTimeout = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[3]).getValue()));
            } else {
                throw new SiddhiAppValidationException("ExternalTimeBatch window's 4th parameter timeout " + "should be either int or long, but found " + attributeExpressionExecutors[3].getReturnType());
            }
        }
        if (attributeExpressionExecutors.length == 5) {
            if (attributeExpressionExecutors[4].getReturnType() == Attribute.Type.BOOL) {
                replaceTimestampWithBatchEndTime = Boolean.parseBoolean(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[4]).getValue()));
            } else {
                throw new SiddhiAppValidationException("ExternalTimeBatch window's 5th parameter " + "replaceTimestampWithBatchEndTime should be bool, but found " + attributeExpressionExecutors[4].getReturnType());
            }
        }
    } else {
        throw new SiddhiAppValidationException("ExternalTimeBatch window should only have two to five " + "parameters (<long> timestamp, <int|long|time> windowTime, <long> startTime, <int|long|time> " + "timeout, <bool> replaceTimestampWithBatchEndTime), but found " + attributeExpressionExecutors.length + " input attributes");
    }
    if (schedulerTimeout > 0) {
        if (expiredEventChunk == null) {
            this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
        }
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Aggregations

VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)32 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)23 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)18 Attribute (org.wso2.siddhi.query.api.definition.Attribute)18 ArrayList (java.util.ArrayList)14 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)13 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)12 Expression (org.wso2.siddhi.query.api.expression.Expression)10 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)8 Variable (org.wso2.siddhi.query.api.expression.Variable)8 HashMap (java.util.HashMap)7 CompiledCondition (org.wso2.siddhi.core.util.collection.operator.CompiledCondition)7 AbstractDefinition (org.wso2.siddhi.query.api.definition.AbstractDefinition)7 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)6 MatchingMetaInfoHolder (org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)6 AndConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.AndConditionExpressionExecutor)5 ConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.ConditionExpressionExecutor)5 Map (java.util.Map)4 Test (org.testng.annotations.Test)4 Table (org.wso2.siddhi.core.table.Table)4