Search in sources :

Example 56 with StreamEvent

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

the class TestStoreForCachePreLoading 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)

Example 57 with StreamEvent

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

the class TestStoreForCachePreLoading method init.

@Override
protected void init(TableDefinition tableDefinition, ConfigReader configReader) {
    inMemoryTable = new InMemoryTable();
    MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
    cacheTableMetaStreamEvent.addInputDefinition(tableDefinition);
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        cacheTableMetaStreamEvent.addOutputData(attribute);
    }
    StreamEventCloner testTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, storeEventPool);
    TableDefinition testStoreContainingIMTableDefinition = TableDefinition.id(tableDefinition.getId());
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        testStoreContainingIMTableDefinition.attribute(attribute.getName(), attribute.getType());
    }
    for (Annotation annotation : tableDefinition.getAnnotations()) {
        if (!annotation.getName().equalsIgnoreCase("Store")) {
            testStoreContainingIMTableDefinition.annotation(annotation);
        }
    }
    inMemoryTable.init(testStoreContainingIMTableDefinition, storeEventPool, testTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
    ComplexEventChunk<StreamEvent> originalData = new ComplexEventChunk<>();
    StreamEvent data1 = new StreamEvent(0, 0, 3);
    data1.setOutputData(new Object[] { "WSO2", 55.6f, 100L });
    originalData.add(data1);
    StreamEvent data2 = new StreamEvent(0, 0, 3);
    data2.setOutputData(new Object[] { "IBM", 75.6f, 100L });
    originalData.add(data2);
    inMemoryTable.add(originalData);
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) 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) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) TableDefinition(io.siddhi.query.api.definition.TableDefinition) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Annotation(io.siddhi.query.api.annotation.Annotation)

Example 58 with StreamEvent

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

the class FindOnDemandQueryRuntime method generateResetComplexEventChunk.

private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setType(ComplexEvent.Type.RESET);
    StateEvent stateEvent = stateEventFactory.newInstance();
    if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
        stateEvent.addEvent(1, streamEvent);
    } else {
        stateEvent.addEvent(0, streamEvent);
    }
    stateEvent.setType(ComplexEvent.Type.RESET);
    ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
    complexEventChunk.add(stateEvent);
    return complexEventChunk;
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 59 with StreamEvent

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

the class FindOnDemandQueryRuntime method execute.

@Override
public Event[] execute() {
    try {
        StateEvent stateEvent = new StateEvent(1, 0);
        StreamEvent streamEvents = null;
        switch(eventType) {
            case TABLE:
                streamEvents = table.find(stateEvent, compiledCondition);
                break;
            case WINDOW:
                streamEvents = window.find(stateEvent, compiledCondition);
                break;
            case AGGREGATE:
                stateEvent = new StateEvent(2, 0);
                streamEvents = aggregation.find(stateEvent, compiledCondition, siddhiQueryContext);
                break;
            case DEFAULT:
                break;
        }
        if (streamEvents == null) {
            return null;
        } else {
            if (selector != null) {
                if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
                    return executeSelector(stateEventFactory, null, streamEvents, 1, selector);
                } else {
                    return executeSelector(stateEventFactory, null, streamEvents, 0, selector);
                }
            } else {
                List<Event> events = new ArrayList<Event>();
                while (streamEvents != null) {
                    events.add(new Event(streamEvents.getTimestamp(), streamEvents.getOutputData()));
                    streamEvents = streamEvents.getNext();
                }
                return events.toArray(new Event[0]);
            }
        }
    } catch (Throwable t) {
        throw new OnDemandQueryRuntimeException("Error executing '" + queryName + "', " + t.getMessage(), t);
    }
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) StateEvent(io.siddhi.core.event.state.StateEvent) OnDemandQueryRuntimeException(io.siddhi.core.exception.OnDemandQueryRuntimeException)

Example 60 with StreamEvent

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

the class UpdateOnDemandQueryRuntime method generateResetComplexEventChunk.

private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setType(ComplexEvent.Type.RESET);
    StateEvent stateEvent = stateEventFactory.newInstance();
    stateEvent.addEvent(0, streamEvent);
    stateEvent.setType(ComplexEvent.Type.RESET);
    ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
    complexEventChunk.add(stateEvent);
    return complexEventChunk;
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

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