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());
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations