Search in sources :

Example 21 with ConstantExpressionExecutor

use of io.siddhi.core.executor.ConstantExpressionExecutor in project siddhi by wso2.

the class EventTestCase method testExpressionExecutors.

@Test
public void testExpressionExecutors() {
    // StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute
    // .Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    VariableExpressionExecutor priceVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("price", Attribute.Type.FLOAT), 0, 0);
    priceVariableExpressionExecutor.setPosition(new int[] { 0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants.OUTPUT_DATA_INDEX, 1 });
    ExpressionExecutor addExecutor = new AddExpressionExecutorFloat(new ConstantExpressionExecutor(10f, Attribute.Type.FLOAT), priceVariableExpressionExecutor);
    StreamEvent event = new StreamEvent(0, 0, 3);
    event.setOutputData(new Object[] { "WSO2", 10f, 5 });
    AssertJUnit.assertEquals("Result of adding should be 20.0", 20f, addExecutor.execute(event));
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) AndConditionExpressionExecutor(io.siddhi.core.executor.condition.AndConditionExpressionExecutor) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) Attribute(io.siddhi.query.api.definition.Attribute) AddExpressionExecutorFloat(io.siddhi.core.executor.math.add.AddExpressionExecutorFloat) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) Test(org.testng.annotations.Test)

Aggregations

ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)21 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)14 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)14 Attribute (io.siddhi.query.api.definition.Attribute)14 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)8 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)7 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)6 Variable (io.siddhi.query.api.expression.Variable)6 ArrayList (java.util.ArrayList)6 SiddhiAppValidationException (io.siddhi.query.api.exception.SiddhiAppValidationException)5 Expression (io.siddhi.query.api.expression.Expression)5 HashMap (java.util.HashMap)5 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)4 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)4 AndConditionExpressionExecutor (io.siddhi.core.executor.condition.AndConditionExpressionExecutor)3 QueryableProcessor (io.siddhi.core.query.processor.stream.window.QueryableProcessor)3 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)3 Map (java.util.Map)3 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)2 MetaStateEventAttribute (io.siddhi.core.event.state.MetaStateEventAttribute)2