Search in sources :

Example 26 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class IndexEventHolder method deleteAll.

@Override
public void deleteAll(Collection<StreamEvent> storeEventSet) {
    for (StreamEvent streamEvent : storeEventSet) {
        if (primaryKeyData != null) {
            Object primaryKey = constructPrimaryKey(streamEvent, primaryKeyReferenceHolders);
            StreamEvent deletedEvent = primaryKeyData.remove(primaryKey);
            if (indexData != null) {
                deleteFromIndexes(deletedEvent);
            }
        } else if (indexData != null) {
            deleteFromIndexes(streamEvent);
        }
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 27 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class IndexEventHolder method add.

@Override
public void add(ComplexEventChunk<StreamEvent> addingEventChunk) {
    addingEventChunk.reset();
    while (addingEventChunk.hasNext()) {
        ComplexEvent complexEvent = addingEventChunk.next();
        StreamEvent streamEvent = tableStreamEventPool.borrowEvent();
        eventConverter.convertComplexEvent(complexEvent, streamEvent);
        add(streamEvent);
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 28 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class IndexEventHolder method overwrite.

@Override
public void overwrite(StreamEvent streamEvent) {
    StreamEvent deletedEvent = null;
    if (primaryKeyData != null) {
        Object primaryKey = constructPrimaryKey(streamEvent, primaryKeyReferenceHolders);
        deletedEvent = primaryKeyData.put(primaryKey, streamEvent);
    }
    if (indexData != null) {
        for (Map.Entry<String, Integer> indexEntry : indexMetaData.entrySet()) {
            TreeMap<Object, Set<StreamEvent>> indexMap = indexData.get(indexEntry.getKey());
            Object key = streamEvent.getOutputData()[indexEntry.getValue()];
            if (deletedEvent != null) {
                Set<StreamEvent> values = indexMap.get(key);
                values.remove(deletedEvent);
                if (values.size() == 0) {
                    indexMap.remove(key);
                }
            }
            Set<StreamEvent> values = indexMap.get(key);
            if (values == null) {
                values = new HashSet<StreamEvent>();
                values.add(streamEvent);
                indexMap.put(streamEvent.getOutputData()[indexEntry.getValue()], values);
            } else {
                values.add(streamEvent);
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 29 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class IndexEventHolder method delete.

@Override
public void delete(String attribute, Compare.Operator operator, Object value) {
    if (primaryKeyData != null && attribute.equals(primaryKeyAttributes)) {
        switch(operator) {
            case LESS_THAN:
                for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, false).values().iterator(); iterator.hasNext(); ) {
                    StreamEvent toDeleteEvent = iterator.next();
                    iterator.remove();
                    deleteFromIndexes(toDeleteEvent);
                }
                return;
            case GREATER_THAN:
                for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, false).values().iterator(); iterator.hasNext(); ) {
                    StreamEvent toDeleteEvent = iterator.next();
                    iterator.remove();
                    deleteFromIndexes(toDeleteEvent);
                }
                return;
            case LESS_THAN_EQUAL:
                for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, true).values().iterator(); iterator.hasNext(); ) {
                    StreamEvent toDeleteEvent = iterator.next();
                    iterator.remove();
                    deleteFromIndexes(toDeleteEvent);
                }
                return;
            case GREATER_THAN_EQUAL:
                for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, true).values().iterator(); iterator.hasNext(); ) {
                    StreamEvent toDeleteEvent = iterator.next();
                    iterator.remove();
                    deleteFromIndexes(toDeleteEvent);
                }
                return;
            case EQUAL:
                StreamEvent deletedEvent = primaryKeyData.remove(value);
                if (deletedEvent != null) {
                    deleteFromIndexes(deletedEvent);
                }
                return;
            case NOT_EQUAL:
                StreamEvent streamEvent = primaryKeyData.get(value);
                deleteAll();
                if (streamEvent != null) {
                    add(streamEvent);
                }
                return;
        }
    } else {
        switch(operator) {
            case LESS_THAN:
                for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).headMap(value, false).values().iterator(); iterator.hasNext(); ) {
                    Set<StreamEvent> deletedEventSet = iterator.next();
                    deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
                    iterator.remove();
                }
                return;
            case GREATER_THAN:
                for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).tailMap(value, false).values().iterator(); iterator.hasNext(); ) {
                    Set<StreamEvent> deletedEventSet = iterator.next();
                    deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
                    iterator.remove();
                }
                return;
            case LESS_THAN_EQUAL:
                for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).headMap(value, true).values().iterator(); iterator.hasNext(); ) {
                    Set<StreamEvent> deletedEventSet = iterator.next();
                    deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
                    iterator.remove();
                }
                return;
            case GREATER_THAN_EQUAL:
                for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).tailMap(value, true).values().iterator(); iterator.hasNext(); ) {
                    Set<StreamEvent> deletedEventSet = iterator.next();
                    deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
                    iterator.remove();
                }
                return;
            case EQUAL:
                Set<StreamEvent> deletedEventSet = indexData.get(attribute).remove(value);
                if (deletedEventSet != null && deletedEventSet.size() > 0) {
                    deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
                }
                return;
            case NOT_EQUAL:
                Set<StreamEvent> matchingEventSet = indexData.get(attribute).get(value);
                deleteAll();
                for (StreamEvent matchingEvent : matchingEventSet) {
                    add(matchingEvent);
                }
                return;
        }
    }
    throw new OperationNotSupportedException(operator + " not supported for '" + value + "' by " + getClass().getName());
}
Also used : OperationNotSupportedException(org.wso2.siddhi.core.exception.OperationNotSupportedException) Set(java.util.Set) HashSet(java.util.HashSet) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) TreeMap(java.util.TreeMap)

Example 30 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

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 : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) HashMap(java.util.HashMap) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)121 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)42 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)41 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)23 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)20 Test (org.testng.annotations.Test)19 Event (org.wso2.siddhi.core.event.Event)16 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)16 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)10 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)9 HashSet (java.util.HashSet)8 StreamEventConverter (org.wso2.siddhi.core.event.stream.converter.StreamEventConverter)8 Attribute (org.wso2.siddhi.query.api.definition.Attribute)8 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)8 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)7 ConversionStreamEventChunk (org.wso2.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)6 HashMap (java.util.HashMap)5