Search in sources :

Example 86 with Attribute

use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.

the class OnDemandQueryTableTestCase method test12.

@Test
public void test12() throws InterruptedException {
    log.info("Test12 - Test output attributes and its types for table");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long);" + "@PrimaryKey('symbol') " + "define table StockTable (symbol string, price float, volume long); ";
    String onDemandQuery = "" + "from StockTable " + "select * ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
    siddhiAppRuntime.start();
    Attribute[] actualAttributeArray = siddhiAppRuntime.getOnDemandQueryOutputAttributes(SiddhiCompiler.parseOnDemandQuery(onDemandQuery));
    Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
    Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
    Attribute volumeAttribute = new Attribute("volume", Attribute.Type.LONG);
    Attribute[] expectedAttributeArray = new Attribute[] { symbolAttribute, priceAttribute, volumeAttribute };
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
    onDemandQuery = "" + "from StockTable " + "select symbol, sum(volume) as totalVolume ;";
    actualAttributeArray = siddhiAppRuntime.getOnDemandQueryOutputAttributes(SiddhiCompiler.parseOnDemandQuery(onDemandQuery));
    Attribute totalVolumeAttribute = new Attribute("totalVolume", Attribute.Type.LONG);
    expectedAttributeArray = new Attribute[] { symbolAttribute, totalVolumeAttribute };
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

Attribute (io.siddhi.query.api.definition.Attribute)86 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)43 ArrayList (java.util.ArrayList)29 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)27 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)23 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)23 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)22 StreamEvent (io.siddhi.core.event.stream.StreamEvent)21 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)19 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)18 Variable (io.siddhi.query.api.expression.Variable)18 Expression (io.siddhi.query.api.expression.Expression)17 Test (org.testng.annotations.Test)17 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)15 HashMap (java.util.HashMap)15 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)14 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)14 TableDefinition (io.siddhi.query.api.definition.TableDefinition)13 Map (java.util.Map)13 Annotation (io.siddhi.query.api.annotation.Annotation)12