Search in sources :

Example 1 with IndexedEventHolder

use of org.ballerinalang.siddhi.core.table.holder.IndexedEventHolder 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 IndexedEventHolder

use of org.ballerinalang.siddhi.core.table.holder.IndexedEventHolder in project ballerina by ballerina-lang.

the class OverwriteTableIndexOperator method tryUpdate.

@Override
public ComplexEventChunk<StreamEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    updatingOrAddingEventChunk.reset();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
        ((IndexedEventHolder) storeEvents).overwrite(addingStreamEventExtractor.getAddingStreamEvent(overwritingOrAddingEvent));
    }
    return null;
}
Also used : IndexedEventHolder(org.ballerinalang.siddhi.core.table.holder.IndexedEventHolder) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Aggregations

IndexedEventHolder (org.ballerinalang.siddhi.core.table.holder.IndexedEventHolder)2 Collection (java.util.Collection)1 Map (java.util.Map)1 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)1 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)1 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)1 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)1 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)1 CollectionExecutor (org.ballerinalang.siddhi.core.util.collection.executor.CollectionExecutor)1 AndMultiPrimaryKeyCollectionExpression (org.ballerinalang.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression)1 AttributeCollectionExpression (org.ballerinalang.siddhi.core.util.collection.expression.AttributeCollectionExpression)1 CollectionExpression (org.ballerinalang.siddhi.core.util.collection.expression.CollectionExpression)1 CompareCollectionExpression (org.ballerinalang.siddhi.core.util.collection.expression.CompareCollectionExpression)1 CollectionOperator (org.ballerinalang.siddhi.core.util.collection.operator.CollectionOperator)1 EventChunkOperator (org.ballerinalang.siddhi.core.util.collection.operator.EventChunkOperator)1 IndexOperator (org.ballerinalang.siddhi.core.util.collection.operator.IndexOperator)1 MapOperator (org.ballerinalang.siddhi.core.util.collection.operator.MapOperator)1 OverwriteTableIndexOperator (org.ballerinalang.siddhi.core.util.collection.operator.OverwriteTableIndexOperator)1