Search in sources :

Example 1 with MetaStreamEvent

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

the class ExpressionBatchWindowProcessor method constructExpression.

private MetaStateEvent constructExpression(MetaStreamEvent metaStreamEvent, SiddhiQueryContext siddhiQueryContext) {
    Expression expression = SiddhiCompiler.parseExpression(expressionString);
    MetaStreamEvent metaStreamEventFirst = new MetaStreamEventWrapper(metaStreamEvent);
    metaStreamEventFirst.setInputReferenceId("first");
    MetaStreamEvent metaStreamEventLast = new MetaStreamEventWrapper(metaStreamEvent);
    metaStreamEventLast.setInputReferenceId("last");
    MetaStateEvent metaStateEvent = new MetaStateEvent(new MetaStreamEvent[] { metaStreamEvent, metaStreamEventFirst, metaStreamEventLast });
    variableExpressionExecutors = new ArrayList<>();
    SiddhiQueryContext exprQueryContext = new SiddhiOnDemandQueryContext(siddhiQueryContext.getSiddhiAppContext(), siddhiQueryContext.getName(), expressionString);
    expressionExecutor = ExpressionParser.parseExpression(expression, metaStateEvent, 0, new HashMap<>(), variableExpressionExecutors, false, 0, ProcessingMode.SLIDE, true, exprQueryContext);
    if (expressionExecutor.getReturnType() != Attribute.Type.BOOL) {
        throw new SiddhiAppRuntimeException("Expression ('" + expressionString + "') does not return Bool");
    }
    return metaStateEvent;
}
Also used : SiddhiQueryContext(io.siddhi.core.config.SiddhiQueryContext) Expression(io.siddhi.query.api.expression.Expression) HashMap(java.util.HashMap) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiOnDemandQueryContext(io.siddhi.core.config.SiddhiOnDemandQueryContext) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 2 with MetaStreamEvent

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

the class WrappedSnapshotOutputRateLimiter method init.

public void init(int outPutAttributeSize, List<AttributeProcessor> attributeProcessorList, MetaComplexEvent metaComplexEvent) {
    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
        if (attributeProcessor.getExpressionExecutor() instanceof AttributeAggregatorExecutor<?>) {
            aggregateAttributePositionList.add(attributeProcessor.getOutputPosition());
        }
    }
    if (windowed) {
        if (groupBy) {
            if (outPutAttributeSize == aggregateAttributePositionList.size()) {
                // All Aggregation
                outputRateLimiter = new AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            } else if (aggregateAttributePositionList.size() > 0) {
                // Some Aggregation
                outputRateLimiter = new AggregationGroupByWindowedPerSnapshotOutputRateLimiter(value, aggregateAttributePositionList, this, groupBy, siddhiQueryContext);
            } else {
                // No aggregation
                // GroupBy is same as Non GroupBy
                outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            }
        } else {
            if (outPutAttributeSize == aggregateAttributePositionList.size()) {
                // All Aggregation
                outputRateLimiter = new AllAggregationPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            } else if (aggregateAttributePositionList.size() > 0) {
                // Some Aggregation
                outputRateLimiter = new AggregationWindowedPerSnapshotOutputRateLimiter(value, aggregateAttributePositionList, this, groupBy, siddhiQueryContext);
            } else {
                // No aggregation
                outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            }
        }
    } else {
        if (groupBy) {
            outputRateLimiter = new GroupByPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
        } else {
            outputRateLimiter = new PerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
        }
    }
    if (metaComplexEvent instanceof MetaStateEvent) {
        StateEventFactory stateEventFactory = new StateEventFactory((MetaStateEvent) metaComplexEvent);
        outputRateLimiter.setStateEventCloner(new StateEventCloner((MetaStateEvent) metaComplexEvent, stateEventFactory));
    } else {
        StreamEventFactory streamEventFactory = new StreamEventFactory((MetaStreamEvent) metaComplexEvent);
        outputRateLimiter.setStreamEventCloner(new StreamEventCloner((MetaStreamEvent) metaComplexEvent, streamEventFactory));
    }
}
Also used : StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) AttributeProcessor(io.siddhi.core.query.selector.attribute.processor.AttributeProcessor) StateEventCloner(io.siddhi.core.event.state.StateEventCloner) AttributeAggregatorExecutor(io.siddhi.core.query.selector.attribute.aggregator.AttributeAggregatorExecutor) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 3 with MetaStreamEvent

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

the class ExpressionWindowProcessor method constructExpression.

private MetaStateEvent constructExpression(MetaStreamEvent metaStreamEvent, SiddhiQueryContext siddhiQueryContext) {
    Expression expression = SiddhiCompiler.parseExpression(expressionString);
    MetaStreamEvent metaStreamEventFirst = new MetaStreamEventWrapper(metaStreamEvent);
    metaStreamEventFirst.setInputReferenceId("first");
    MetaStreamEvent metaStreamEventLast = new MetaStreamEventWrapper(metaStreamEvent);
    metaStreamEventLast.setInputReferenceId("last");
    MetaStateEvent metaStateEvent = new MetaStateEvent(new MetaStreamEvent[] { metaStreamEvent, metaStreamEventFirst, metaStreamEventLast });
    variableExpressionExecutors = new ArrayList<>();
    SiddhiQueryContext exprQueryContext = new SiddhiOnDemandQueryContext(siddhiQueryContext.getSiddhiAppContext(), siddhiQueryContext.getName(), expressionString);
    expressionExecutor = ExpressionParser.parseExpression(expression, metaStateEvent, 0, new HashMap<>(), variableExpressionExecutors, false, 0, ProcessingMode.SLIDE, true, exprQueryContext);
    if (expressionExecutor.getReturnType() != Attribute.Type.BOOL) {
        throw new SiddhiAppRuntimeException("Expression ('" + expressionString + "') does not return Bool");
    }
    return metaStateEvent;
}
Also used : SiddhiQueryContext(io.siddhi.core.config.SiddhiQueryContext) Expression(io.siddhi.query.api.expression.Expression) HashMap(java.util.HashMap) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiOnDemandQueryContext(io.siddhi.core.config.SiddhiOnDemandQueryContext) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 4 with MetaStreamEvent

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

the class SnapshotableEventQueueTestCase method incrementalPersistenceTest3.

@Test
public void incrementalPersistenceTest3() throws InterruptedException, IOException, ClassNotFoundException {
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addOutputData(new Attribute("symbol", Attribute.Type.STRING));
    metaStreamEvent.addOutputData(new Attribute("price", Attribute.Type.FLOAT));
    metaStreamEvent.addOutputData(new Attribute("volume", Attribute.Type.LONG));
    StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, new StreamEventFactory(metaStreamEvent));
    SnapshotableStreamEventQueue snapshotableStreamEventQueue = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setOutputData(new Object[] { "IBM", 500.6f, 1 });
    for (int i = 0; i < 10; i++) {
        streamEvent.getOutputData()[2] = i;
        snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
    }
    HashMap<Long, String> snapshots = new HashMap<>();
    Snapshot snapshot1 = snapshotableStreamEventQueue.getSnapshot();
    StreamEvent streamEvents = (StreamEvent) snapshot1.getState();
    Assert.assertTrue(streamEvents != null);
    snapshots.put(3L, toString(snapshot1));
    snapshotableStreamEventQueue.next();
    snapshotableStreamEventQueue.next();
    snapshotableStreamEventQueue.next();
    for (int i = 7; i < 10; i++) {
        snapshotableStreamEventQueue.next();
        snapshotableStreamEventQueue.remove();
    }
    Snapshot snapshot2 = snapshotableStreamEventQueue.getSnapshot();
    ArrayList<Operation> operationLog = (ArrayList<Operation>) snapshot2.getState();
    Assert.assertTrue(operationLog != null);
    snapshots.put(4L, toString(snapshot2));
    for (int i = 10; i < 15; i++) {
        streamEvent.getOutputData()[2] = i;
        snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
    }
    Snapshot snapshot3 = snapshotableStreamEventQueue.getSnapshot();
    operationLog = (ArrayList<Operation>) snapshot3.getState();
    Assert.assertTrue(operationLog != null);
    snapshots.put(5L, toString(snapshot3));
    SnapshotableStreamEventQueue snapshotableStreamEventQueue2 = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
    SnapshotStateList snapshotStateList = new SnapshotStateList();
    for (Map.Entry<Long, String> entry : snapshots.entrySet()) {
        snapshotStateList.putSnapshotState(entry.getKey(), (Snapshot) fromString(entry.getValue()));
    }
    snapshotableStreamEventQueue2.restore(snapshotStateList);
    Assert.assertEquals(snapshotableStreamEventQueue, snapshotableStreamEventQueue2);
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) HashMap(java.util.HashMap) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) Operation(io.siddhi.core.event.stream.Operation) StreamEventClonerHolder(io.siddhi.core.event.stream.holder.StreamEventClonerHolder) Snapshot(io.siddhi.core.util.snapshot.state.Snapshot) SnapshotStateList(io.siddhi.core.util.snapshot.state.SnapshotStateList) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) HashMap(java.util.HashMap) Map(java.util.Map) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue) Test(org.testng.annotations.Test)

Example 5 with MetaStreamEvent

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

the class SnapshotableEventQueueTestCase method incrementalPersistenceTest5.

@Test
public void incrementalPersistenceTest5() throws InterruptedException, IOException, ClassNotFoundException {
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addOutputData(new Attribute("symbol", Attribute.Type.STRING));
    metaStreamEvent.addOutputData(new Attribute("price", Attribute.Type.FLOAT));
    metaStreamEvent.addOutputData(new Attribute("volume", Attribute.Type.LONG));
    StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, new StreamEventFactory(metaStreamEvent));
    SnapshotableStreamEventQueue snapshotableStreamEventQueue = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setOutputData(new Object[] { "IBM", 500.6f, 1 });
    for (int i = 0; i < 10; i++) {
        streamEvent.getOutputData()[2] = i;
        snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
    }
    HashMap<Long, String> snapshots = new HashMap<>();
    Snapshot snapshot1 = snapshotableStreamEventQueue.getSnapshot();
    StreamEvent streamEvents = (StreamEvent) snapshot1.getState();
    Assert.assertTrue(streamEvents != null);
    snapshots.put(3L, toString(snapshot1));
    snapshotableStreamEventQueue.next();
    snapshotableStreamEventQueue.next();
    snapshotableStreamEventQueue.next();
    for (int i = 7; i < 10; i++) {
        snapshotableStreamEventQueue.next();
        streamEvent.getOutputData()[2] = i + 20;
        snapshotableStreamEventQueue.overwrite(streamEventCloner.copyStreamEvent(streamEvent));
    }
    Snapshot snapshot2 = snapshotableStreamEventQueue.getSnapshot();
    ArrayList<Operation> operationLog = (ArrayList<Operation>) snapshot2.getState();
    Assert.assertTrue(operationLog != null);
    snapshots.put(4L, toString(snapshot2));
    for (int i = 10; i < 15; i++) {
        streamEvent.getOutputData()[2] = i;
        snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
    }
    Snapshot snapshot3 = snapshotableStreamEventQueue.getSnapshot();
    operationLog = (ArrayList<Operation>) snapshot3.getState();
    Assert.assertTrue(operationLog != null);
    snapshots.put(5L, toString(snapshot3));
    SnapshotableStreamEventQueue snapshotableStreamEventQueue2 = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
    SnapshotStateList snapshotStateList = new SnapshotStateList();
    for (Map.Entry<Long, String> entry : snapshots.entrySet()) {
        snapshotStateList.putSnapshotState(entry.getKey(), (Snapshot) fromString(entry.getValue()));
    }
    snapshotableStreamEventQueue2.restore(snapshotStateList);
    Assert.assertEquals(snapshotableStreamEventQueue, snapshotableStreamEventQueue2);
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) HashMap(java.util.HashMap) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) Operation(io.siddhi.core.event.stream.Operation) StreamEventClonerHolder(io.siddhi.core.event.stream.holder.StreamEventClonerHolder) Snapshot(io.siddhi.core.util.snapshot.state.Snapshot) SnapshotStateList(io.siddhi.core.util.snapshot.state.SnapshotStateList) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) HashMap(java.util.HashMap) Map(java.util.Map) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue) Test(org.testng.annotations.Test)

Aggregations

MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)63 Attribute (io.siddhi.query.api.definition.Attribute)35 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)34 StreamEvent (io.siddhi.core.event.stream.StreamEvent)21 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)17 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)17 ArrayList (java.util.ArrayList)17 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)14 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)14 Variable (io.siddhi.query.api.expression.Variable)14 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)13 HashMap (java.util.HashMap)13 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)12 Expression (io.siddhi.query.api.expression.Expression)12 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)10 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)10 Map (java.util.Map)10 Test (org.testng.annotations.Test)10 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)9 TableDefinition (io.siddhi.query.api.definition.TableDefinition)9