Search in sources :

Example 16 with ExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.ExpressionExecutor in project ballerina by ballerina-lang.

the class AbstractRecordTable method find.

@Override
public StreamEvent find(CompiledCondition compiledCondition, StateEvent matchingEvent) throws ConnectionUnavailableException {
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    Map<String, Object> findConditionParameterMap = new HashMap<>();
    for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
        findConditionParameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
    }
    Iterator<Object[]> records;
    if (recordTableHandler != null) {
        records = recordTableHandler.find(matchingEvent.getTimestamp(), findConditionParameterMap, recordStoreCompiledCondition.compiledCondition);
    } else {
        records = find(findConditionParameterMap, recordStoreCompiledCondition.compiledCondition);
    }
    ComplexEventChunk<StreamEvent> streamEventComplexEventChunk = new ComplexEventChunk<>(true);
    if (records != null) {
        while (records.hasNext()) {
            Object[] record = records.next();
            StreamEvent streamEvent = storeEventPool.borrowEvent();
            System.arraycopy(record, 0, streamEvent.getOutputData(), 0, record.length);
            streamEventComplexEventChunk.add(streamEvent);
        }
    }
    return streamEventComplexEventChunk.getFirst();
}
Also used : ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) HashMap(java.util.HashMap) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with ExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.ExpressionExecutor in project ballerina by ballerina-lang.

the class AbstractRecordTable method updateOrAdd.

@Override
public void updateOrAdd(ComplexEventChunk<StateEvent> updateOrAddingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) throws ConnectionUnavailableException {
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = (RecordTableCompiledUpdateSet) compiledUpdateSet;
    List<Map<String, Object>> updateConditionParameterMaps = new ArrayList<>();
    List<Map<String, Object>> updateSetParameterMaps = new ArrayList<>();
    List<Object[]> addingRecords = new ArrayList<>();
    updateOrAddingEventChunk.reset();
    long timestamp = 0L;
    while (updateOrAddingEventChunk.hasNext()) {
        StateEvent stateEvent = updateOrAddingEventChunk.next();
        Map<String, Object> variableMap = new HashMap<>();
        for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
            variableMap.put(entry.getKey(), entry.getValue().execute(stateEvent));
        }
        updateConditionParameterMaps.add(variableMap);
        Map<String, Object> variableMapForUpdateSet = new HashMap<>();
        for (Map.Entry<String, ExpressionExecutor> entry : recordTableCompiledUpdateSet.getExpressionExecutorMap().entrySet()) {
            variableMapForUpdateSet.put(entry.getKey(), entry.getValue().execute(stateEvent));
        }
        updateSetParameterMaps.add(variableMapForUpdateSet);
        addingRecords.add(stateEvent.getStreamEvent(0).getOutputData());
        timestamp = stateEvent.getTimestamp();
    }
    if (recordTableHandler != null) {
        recordTableHandler.updateOrAdd(timestamp, recordStoreCompiledCondition.compiledCondition, updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
    } else {
        updateOrAdd(recordStoreCompiledCondition.compiledCondition, updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
    }
}
Also used : ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with ExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.ExpressionExecutor in project ballerina by ballerina-lang.

the class AbstractRecordTable method update.

@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet) throws ConnectionUnavailableException {
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = (RecordTableCompiledUpdateSet) compiledUpdateSet;
    List<Map<String, Object>> updateConditionParameterMaps = new ArrayList<>();
    List<Map<String, Object>> updateSetParameterMaps = new ArrayList<>();
    updatingEventChunk.reset();
    long timestamp = 0L;
    while (updatingEventChunk.hasNext()) {
        StateEvent stateEvent = updatingEventChunk.next();
        Map<String, Object> variableMap = new HashMap<>();
        for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
            variableMap.put(entry.getKey(), entry.getValue().execute(stateEvent));
        }
        updateConditionParameterMaps.add(variableMap);
        Map<String, Object> variableMapForUpdateSet = new HashMap<>();
        for (Map.Entry<String, ExpressionExecutor> entry : recordTableCompiledUpdateSet.getExpressionExecutorMap().entrySet()) {
            variableMapForUpdateSet.put(entry.getKey(), entry.getValue().execute(stateEvent));
        }
        updateSetParameterMaps.add(variableMapForUpdateSet);
        timestamp = stateEvent.getTimestamp();
    }
    if (recordTableHandler != null) {
        recordTableHandler.update(timestamp, recordStoreCompiledCondition.compiledCondition, updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps);
    } else {
        update(recordStoreCompiledCondition.compiledCondition, updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps);
    }
}
Also used : ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with ExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.ExpressionExecutor in project ballerina by ballerina-lang.

the class AggregateWindowProcessor method cloneProcessor.

@Override
public Processor cloneProcessor(String key) {
    try {
        AggregateWindowProcessor streamProcessor = new AggregateWindowProcessor(aggregationRuntime, within, per);
        streamProcessor.inputDefinition = inputDefinition;
        ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength];
        ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors;
        for (int i = 0; i < attributeExpressionLength; i++) {
            innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key);
        }
        streamProcessor.attributeExpressionExecutors = innerExpressionExecutors;
        streamProcessor.attributeExpressionLength = attributeExpressionLength;
        streamProcessor.additionalAttributes = additionalAttributes;
        streamProcessor.complexEventPopulater = complexEventPopulater;
        streamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
        streamProcessor.start();
        return streamProcessor;
    } catch (Exception e) {
        throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
    }
}
Also used : ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) SiddhiAppRuntimeException(org.ballerinalang.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppRuntimeException(org.ballerinalang.siddhi.core.exception.SiddhiAppRuntimeException)

Example 20 with ExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.ExpressionExecutor in project ballerina by ballerina-lang.

the class SortWindowProcessor method init.

@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
    if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
        lengthToKeep = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue()));
    } else {
        throw new UnsupportedOperationException("The first parameter should be an integer");
    }
    parameterInfo = new ArrayList<Object[]>();
    eventComparator = new EventComparator();
    for (int i = 1, parametersLength = attributeExpressionExecutors.length; i < parametersLength; i++) {
        if (!(attributeExpressionExecutors[i] instanceof VariableExpressionExecutor)) {
            throw new UnsupportedOperationException("Required a variable, but found a string parameter");
        } else {
            ExpressionExecutor variableExpressionExecutor = attributeExpressionExecutors[i];
            int order;
            String nextParameter;
            if (i + 1 < parametersLength && attributeExpressionExecutors[i + 1].getReturnType() == Attribute.Type.STRING) {
                nextParameter = (String) ((ConstantExpressionExecutor) attributeExpressionExecutors[i + 1]).getValue();
                if (nextParameter.equalsIgnoreCase(DESC)) {
                    order = -1;
                    i++;
                } else if (nextParameter.equalsIgnoreCase(ASC)) {
                    order = 1;
                    i++;
                } else {
                    throw new UnsupportedOperationException("Parameter string literals should only be \"asc\" or " + "\"desc\"");
                }
            } else {
                // assigning the default order: "asc"
                order = 1;
            }
            parameterInfo.add(new Object[] { variableExpressionExecutor, order });
        }
    }
}
Also used : ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)

Aggregations

ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)46 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)33 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)15 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)14 Map (java.util.Map)13 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)13 HashMap (java.util.HashMap)11 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)11 ArrayList (java.util.ArrayList)10 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)10 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)10 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)8 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)7 SiddhiAppRuntimeException (org.ballerinalang.siddhi.core.exception.SiddhiAppRuntimeException)7 Expression (org.ballerinalang.siddhi.query.api.expression.Expression)7 AndConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.AndConditionExpressionExecutor)5 AbstractDefinition (org.ballerinalang.siddhi.query.api.definition.AbstractDefinition)5 OutputAttribute (org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute)5 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)4 ConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor)4