Search in sources :

Example 26 with ComplexEventChunk

use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class IncrementalAggregationProcessor method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<>();
    try {
        int noOfEvents = 0;
        if (latencyTrackerInsert != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
            latencyTrackerInsert.markIn();
        }
        while (complexEventChunk.hasNext()) {
            ComplexEvent complexEvent = complexEventChunk.next();
            if (!isFirstEventArrived) {
                aggregationRuntime.initialiseExecutors(true);
                isFirstEventArrived = true;
            }
            StreamEvent newEvent = streamEventFactory.newInstance();
            for (int i = 0; i < incomingExpressionExecutors.size(); i++) {
                ExpressionExecutor expressionExecutor = incomingExpressionExecutors.get(i);
                Object outputData = expressionExecutor.execute(complexEvent);
                if (expressionExecutor instanceof IncrementalUnixTimeFunctionExecutor && outputData == null) {
                    throw new SiddhiAppRuntimeException("Cannot retrieve the timestamp of event");
                }
                newEvent.setOutputData(outputData, i);
            }
            streamEventChunk.add(newEvent);
            noOfEvents++;
        }
        aggregationRuntime.processEvents(streamEventChunk);
        if (throughputTrackerInsert != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
            throughputTrackerInsert.eventsIn(noOfEvents);
        }
    } finally {
        if (latencyTrackerInsert != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
            latencyTrackerInsert.markOut();
        }
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) IncrementalUnixTimeFunctionExecutor(io.siddhi.core.executor.incremental.IncrementalUnixTimeFunctionExecutor)

Example 27 with ComplexEventChunk

use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class OperatorParser method constructOperator.

public static Operator constructOperator(Object storeEvents, Expression expression, MatchingMetaInfoHolder matchingMetaInfoHolder, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, SiddhiQueryContext siddhiQueryContext) {
    if (storeEvents instanceof IndexedEventHolder) {
        CollectionExpression collectionExpression = CollectionExpressionParser.parseCollectionExpression(expression, matchingMetaInfoHolder, (IndexedEventHolder) storeEvents);
        CollectionExecutor collectionExecutor = CollectionExpressionParser.buildCollectionExecutor(collectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, true, ProcessingMode.BATCH, false, siddhiQueryContext, false, null);
        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, siddhiQueryContext.getName());
        } else if (collectionExpression instanceof AndMultiPrimaryKeyCollectionExpression && collectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET) {
            return new OverwriteTableIndexOperator(collectionExecutor, siddhiQueryContext.getName());
        } else {
            return new IndexOperator(collectionExecutor, siddhiQueryContext.getName());
        }
    } else if (storeEvents instanceof ComplexEventChunk) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
        return new EventChunkOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
    } else if (storeEvents instanceof SnapshotableStreamEventQueue) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
        return new SnapshotableEventQueueOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
    } else if (storeEvents instanceof Map) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
        return new MapOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
    } else if (storeEvents instanceof Collection) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
        return new CollectionOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
    } else {
        throw new OperationNotSupportedException(storeEvents.getClass() + " is not supported by OperatorParser!");
    }
}
Also used : OverwriteTableIndexOperator(io.siddhi.core.util.collection.operator.OverwriteTableIndexOperator) OperationNotSupportedException(io.siddhi.core.exception.OperationNotSupportedException) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) AttributeCollectionExpression(io.siddhi.core.util.collection.expression.AttributeCollectionExpression) AndMultiPrimaryKeyCollectionExpression(io.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) EventChunkOperator(io.siddhi.core.util.collection.operator.EventChunkOperator) CollectionOperator(io.siddhi.core.util.collection.operator.CollectionOperator) OverwriteTableIndexOperator(io.siddhi.core.util.collection.operator.OverwriteTableIndexOperator) IndexOperator(io.siddhi.core.util.collection.operator.IndexOperator) MapOperator(io.siddhi.core.util.collection.operator.MapOperator) CompareCollectionExpression(io.siddhi.core.util.collection.expression.CompareCollectionExpression) IndexedEventHolder(io.siddhi.core.table.holder.IndexedEventHolder) CollectionExecutor(io.siddhi.core.util.collection.executor.CollectionExecutor) SnapshotableEventQueueOperator(io.siddhi.core.util.collection.operator.SnapshotableEventQueueOperator) Collection(java.util.Collection) CollectionExpression(io.siddhi.core.util.collection.expression.CollectionExpression) CompareCollectionExpression(io.siddhi.core.util.collection.expression.CompareCollectionExpression) AndMultiPrimaryKeyCollectionExpression(io.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) AttributeCollectionExpression(io.siddhi.core.util.collection.expression.AttributeCollectionExpression) Map(java.util.Map) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)

Example 28 with ComplexEventChunk

use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class TestStoreContainingInMemoryTable method objectListToComplexEventChunk.

private ComplexEventChunk<StreamEvent> objectListToComplexEventChunk(List<Object[]> records) {
    ComplexEventChunk<StreamEvent> complexEventChunk = new ComplexEventChunk<>();
    for (Object[] record : records) {
        StreamEvent event = storeEventPool.newInstance();
        event.setOutputData(record);
        complexEventChunk.add(event);
    }
    return complexEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 29 with ComplexEventChunk

use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class TestStoreForCacheMiss method objectListToComplexEventChunk.

private ComplexEventChunk<StreamEvent> objectListToComplexEventChunk(List<Object[]> records) {
    ComplexEventChunk<StreamEvent> complexEventChunk = new ComplexEventChunk<>();
    for (Object[] record : records) {
        StreamEvent event = storeEventPool.newInstance();
        event.setOutputData(record);
        complexEventChunk.add(event);
    }
    return complexEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 30 with ComplexEventChunk

use of io.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class TestStoreForCacheMiss method convForDelete.

private ComplexEventChunk<StreamEvent> convForDelete(List<Map<String, Object>> deleteConditionParameterMaps) {
    List<Object[]> objectList = new LinkedList<>();
    for (Map<String, Object> parameterMap : deleteConditionParameterMaps) {
        List<Object> outputData = new ArrayList<>();
        List<Attribute> attributeList = inMemoryTable.getTableDefinition().getAttributeList();
        for (int i = 0; i < attributeList.size(); i++) {
            if (parameterMap.get(attributeList.get(i).getName()) != null) {
                outputData.add(parameterMap.get(attributeList.get(i).getName()));
            } else {
                outputData.add(null);
            }
        }
        objectList.add(outputData.toArray());
    }
    ComplexEventChunk<StreamEvent> complexEventChunk = new ComplexEventChunk<>();
    for (Object[] record : objectList) {
        StreamEvent event = new StreamEvent(0, 0, record.length);
        // StateEvent stateEvent = new StateEvent(2, record.length);
        event.setOutputData(record);
        // stateEvent.addEvent(0, event);
        complexEventChunk.add(event);
    }
    return complexEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) Attribute(io.siddhi.query.api.definition.Attribute) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)114 StreamEvent (io.siddhi.core.event.stream.StreamEvent)75 ComplexEvent (io.siddhi.core.event.ComplexEvent)41 StateEvent (io.siddhi.core.event.state.StateEvent)38 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)34 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)14 GroupedComplexEvent (io.siddhi.core.event.GroupedComplexEvent)13 LinkedList (java.util.LinkedList)12 Map (java.util.Map)12 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)10 ArrayList (java.util.ArrayList)10 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)7 HashMap (java.util.HashMap)7 Attribute (io.siddhi.query.api.definition.Attribute)5 Event (io.siddhi.core.event.Event)4 TimePeriod (io.siddhi.query.api.aggregation.TimePeriod)4 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)3 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)3 Table (io.siddhi.core.table.Table)3 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)2