Search in sources :

Example 46 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent 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 47 with StreamEvent

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

the class IncrementalDataPurger method createStreamEvent.

/**
 * creating stream event method
 */
private StateEvent createStreamEvent(Object[] values, Long timestamp) {
    StreamEvent streamEvent = streamEventFactory.newInstance();
    streamEvent.setTimestamp(timestamp);
    streamEvent.setOutputData(values);
    StateEvent stateEvent = new StateEvent(2, 1);
    stateEvent.addEvent(0, streamEvent);
    return stateEvent;
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 48 with StreamEvent

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

the class ErrorHandlerUtils method constructAddErrorRecordString.

public static String constructAddErrorRecordString(ComplexEventChunk<StreamEvent> eventChunk, boolean isObjectColumnPresent, TableDefinition tableDefinition, Exception e) {
    JsonObject payloadJson = new JsonObject();
    payloadJson.addProperty("isEditable", !(isObjectColumnPresent || e instanceof ConnectionUnavailableException));
    JsonArray attributes = new JsonArray();
    JsonArray records = new JsonArray();
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        JsonObject attributeJson = new JsonObject();
        attributeJson.add("name", new JsonPrimitive(attribute.getName()));
        attributeJson.add("type", new JsonPrimitive(String.valueOf(attribute.getType())));
        attributes.add(attributeJson);
    }
    payloadJson.add("attributes", attributes);
    while (eventChunk.hasNext()) {
        StreamEvent streamEvent = eventChunk.next();
        JsonArray record = new JsonArray();
        for (Object item : streamEvent.getOutputData()) {
            if (item == null) {
                record.add(JsonNull.INSTANCE);
            } else {
                record.add(String.valueOf(item));
            }
        }
        records.add(record);
    }
    payloadJson.add("records", records);
    return payloadJson.toString();
}
Also used : JsonArray(com.google.gson.JsonArray) Attribute(io.siddhi.query.api.definition.Attribute) JsonPrimitive(com.google.gson.JsonPrimitive) StreamEvent(io.siddhi.core.event.stream.StreamEvent) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException)

Example 49 with StreamEvent

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

the class SnapshotableEventQueueOperator method delete.

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

Example 50 with StreamEvent

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

the class TestStoreContainingInMemoryTable method query.

@Override
protected RecordIterator<Object[]> query(Map<String, Object> parameterMap, CompiledCondition compiledCondition, CompiledSelection compiledSelection, Attribute[] outputAttributes) {
    StreamEvent outEvent = inMemoryTable.find(compiledCondition, findMatchingEvent);
    List<Object[]> objects = new LinkedList<>();
    CompiledSelectionWithCache compiledSelectionWithCache = null;
    if (outEvent != null) {
        compiledSelectionWithCache = (CompiledSelectionWithCache) compiledSelection;
        StateEventFactory stateEventFactory = new StateEventFactory(compiledSelectionWithCache.getMetaStateEvent());
        Event[] cacheResultsAfterSelection = executeSelector(stateEventFactory, null, outEvent, compiledSelectionWithCache.getStoreEventIndex(), compiledSelectionWithCache.getQuerySelector());
        if (compiledSelectionWithCache.getQuerySelector() != null & compiledSelectionWithCache.getQuerySelector().getAttributeProcessorList().size() != 0) {
            compiledSelectionWithCache.getQuerySelector().process(generateResetComplexEventChunk(outEvent.getOutputData().length, stateEventFactory));
        }
        if (cacheResultsAfterSelection != null) {
            for (Event event : cacheResultsAfterSelection) {
                objects.add(event.getData());
            }
        }
    }
    return new TestStoreWithCacheIterator(objects.iterator());
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) StateEvent(io.siddhi.core.event.state.StateEvent) LinkedList(java.util.LinkedList)

Aggregations

StreamEvent (io.siddhi.core.event.stream.StreamEvent)203 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)92 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)74 StateEvent (io.siddhi.core.event.state.StateEvent)52 ComplexEvent (io.siddhi.core.event.ComplexEvent)33 ArrayList (java.util.ArrayList)27 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)26 Map (java.util.Map)24 Event (io.siddhi.core.event.Event)23 Test (org.testng.annotations.Test)23 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)20 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)18 Attribute (io.siddhi.query.api.definition.Attribute)17 HashMap (java.util.HashMap)17 Operation (io.siddhi.core.event.stream.Operation)12 LinkedList (java.util.LinkedList)12 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)11 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)10 HashSet (java.util.HashSet)10 StreamEventConverter (io.siddhi.core.event.stream.converter.StreamEventConverter)8