Search in sources :

Example 1 with ComplexEventChunk

use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.

the class OperatorParser method constructOperator.

public static Operator constructOperator(Object storeEvents, Expression expression, MatchingMetaInfoHolder matchingMetaInfoHolder, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, String queryName) {
    if (storeEvents instanceof IndexedEventHolder) {
        CollectionExpression collectionExpression = CollectionExpressionParser.parseCollectionExpression(expression, matchingMetaInfoHolder, (IndexedEventHolder) storeEvents);
        CollectionExecutor collectionExecutor = CollectionExpressionParser.buildCollectionExecutor(collectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, true, queryName);
        if (collectionExpression instanceof CompareCollectionExpression && ((CompareCollectionExpression) collectionExpression).getOperator() == Compare.Operator.EQUAL && (collectionExpression.getCollectionScope() == INDEXED_RESULT_SET || collectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET) && ((IndexedEventHolder) storeEvents).getPrimaryKeyReferenceHolders() != null && ((IndexedEventHolder) storeEvents).getPrimaryKeyReferenceHolders().length == 1 && ((IndexedEventHolder) storeEvents).getPrimaryKeyReferenceHolders()[0].getPrimaryKeyAttribute().equals(((AttributeCollectionExpression) ((CompareCollectionExpression) collectionExpression).getAttributeCollectionExpression()).getAttribute())) {
            return new OverwriteTableIndexOperator(collectionExecutor, queryName);
        } else if (collectionExpression instanceof AndMultiPrimaryKeyCollectionExpression && collectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET) {
            return new OverwriteTableIndexOperator(collectionExecutor, queryName);
        } else {
            return new IndexOperator(collectionExecutor, queryName);
        }
    } else if (storeEvents instanceof ComplexEventChunk) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        return new EventChunkOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
    } else if (storeEvents instanceof Map) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        return new MapOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
    } else if (storeEvents instanceof Collection) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        return new CollectionOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
    } else {
        throw new OperationNotSupportedException(storeEvents.getClass() + " is not supported by OperatorParser!");
    }
}
Also used : OverwriteTableIndexOperator(org.ballerinalang.siddhi.core.util.collection.operator.OverwriteTableIndexOperator) OperationNotSupportedException(org.ballerinalang.siddhi.core.exception.OperationNotSupportedException) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) AttributeCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.AttributeCollectionExpression) AndMultiPrimaryKeyCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) EventChunkOperator(org.ballerinalang.siddhi.core.util.collection.operator.EventChunkOperator) CollectionOperator(org.ballerinalang.siddhi.core.util.collection.operator.CollectionOperator) IndexOperator(org.ballerinalang.siddhi.core.util.collection.operator.IndexOperator) OverwriteTableIndexOperator(org.ballerinalang.siddhi.core.util.collection.operator.OverwriteTableIndexOperator) MapOperator(org.ballerinalang.siddhi.core.util.collection.operator.MapOperator) CompareCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.CompareCollectionExpression) IndexedEventHolder(org.ballerinalang.siddhi.core.table.holder.IndexedEventHolder) CollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.CollectionExecutor) Collection(java.util.Collection) AttributeCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.AttributeCollectionExpression) CompareCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.CompareCollectionExpression) AndMultiPrimaryKeyCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) CollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.CollectionExpression) Map(java.util.Map)

Example 2 with ComplexEventChunk

use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.

the class CollectionOperator method find.

@Override
public StreamEvent find(StateEvent matchingEvent, Object storeEvents, StreamEventCloner storeEventCloner) {
    ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
    for (StreamEvent storeEvent : (Collection<StreamEvent>) storeEvents) {
        matchingEvent.setEvent(storeEventPosition, storeEvent);
        if ((Boolean) expressionExecutor.execute(matchingEvent)) {
            returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
        }
        matchingEvent.setEvent(storeEventPosition, null);
    }
    return returnEventChunk.getFirst();
}
Also used : ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) Collection(java.util.Collection)

Example 3 with ComplexEventChunk

use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.

the class EventChunkOperator method delete.

@Override
public void delete(ComplexEventChunk<StateEvent> deletingEventChunk, Object storeEvents) {
    ComplexEventChunk<StreamEvent> storeEventChunk = (ComplexEventChunk<StreamEvent>) storeEvents;
    deletingEventChunk.reset();
    while (deletingEventChunk.hasNext()) {
        StateEvent deletingEvent = deletingEventChunk.next();
        try {
            storeEventChunk.reset();
            while (storeEventChunk.hasNext()) {
                StreamEvent storeEvent = storeEventChunk.next();
                deletingEvent.setEvent(storeEventPosition, storeEvent);
                if ((Boolean) expressionExecutor.execute(deletingEvent)) {
                    storeEventChunk.remove();
                }
            }
        } finally {
            deletingEvent.setEvent(storeEventPosition, null);
        }
    }
}
Also used : ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Example 4 with ComplexEventChunk

use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.

the class IndexOperator method tryUpdate.

@Override
public ComplexEventChunk<StreamEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    ComplexEventChunk<StreamEvent> failedEventChunk = new ComplexEventChunk<StreamEvent>(updatingOrAddingEventChunk.isBatch());
    updatingOrAddingEventChunk.reset();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
        StreamEvent streamEvents = collectionExecutor.find(overwritingOrAddingEvent, (IndexedEventHolder) storeEvents, null);
        ComplexEventChunk<StreamEvent> foundEventChunk = new ComplexEventChunk<>(false);
        foundEventChunk.add(streamEvents);
        if (foundEventChunk.getFirst() != null) {
            // for cases when indexed attribute is also updated but that not changed
            // to reduce number of passes needed to update the events
            update((IndexedEventHolder) storeEvents, compiledUpdateSet, overwritingOrAddingEvent, foundEventChunk);
        } else {
            failedEventChunk.add(addingStreamEventExtractor.getAddingStreamEvent(overwritingOrAddingEvent));
        }
    }
    return failedEventChunk;
}
Also used : ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Example 5 with ComplexEventChunk

use of org.ballerinalang.siddhi.core.event.ComplexEventChunk in project ballerina by ballerina-lang.

the class IndexOperator method update.

@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet) {
    updatingEventChunk.reset();
    while (updatingEventChunk.hasNext()) {
        StateEvent updatingEvent = updatingEventChunk.next();
        StreamEvent streamEvents = collectionExecutor.find(updatingEvent, (IndexedEventHolder) storeEvents, null);
        if (streamEvents != null) {
            ComplexEventChunk<StreamEvent> foundEventChunk = new ComplexEventChunk<>(false);
            foundEventChunk.add(streamEvents);
            update((IndexedEventHolder) storeEvents, compiledUpdateSet, updatingEvent, foundEventChunk);
        }
    }
}
Also used : ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Aggregations

ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)69 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)41 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)30 ArrayList (java.util.ArrayList)23 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)19 GroupedComplexEvent (org.ballerinalang.siddhi.core.event.GroupedComplexEvent)13 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)12 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)10 Map (java.util.Map)8 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)4 HashMap (java.util.HashMap)3 Table (org.ballerinalang.siddhi.core.table.Table)3 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Event (org.ballerinalang.siddhi.core.event.Event)2 SiddhiAppRuntimeException (org.ballerinalang.siddhi.core.exception.SiddhiAppRuntimeException)2 StreamPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor)2 TimePeriod (org.ballerinalang.siddhi.query.api.aggregation.TimePeriod)2 IncrementalDataAggregator (org.ballerinalang.siddhi.core.aggregation.IncrementalDataAggregator)1 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)1