Search in sources :

Example 16 with TableDefinition

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

the class SiddhiCompiler method parseTableDefinition.

public static TableDefinition parseTableDefinition(String tableDefinition) throws SiddhiParserException {
    CharStream input = CharStreams.fromString(tableDefinition);
    SiddhiQLLexer lexer = new SiddhiQLLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    SiddhiQLParser parser = new SiddhiQLParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(SiddhiErrorListener.INSTANCE);
    ParseTree tree = parser.definition_table_final();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (TableDefinition) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) TableDefinition(io.siddhi.query.api.definition.TableDefinition) SiddhiQLBaseVisitorImpl(io.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) CharStream(org.antlr.v4.runtime.CharStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 17 with TableDefinition

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

the class DefineTableTestCase method test1.

@Test
public void test1() throws SiddhiParserException {
    TableDefinition streamDefinition = SiddhiCompiler.parseTableDefinition("define table cseStream ( symbol " + "string, price int, volume float )");
    AssertJUnit.assertEquals(TableDefinition.id("cseStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).toString(), streamDefinition.toString());
}
Also used : TableDefinition(io.siddhi.query.api.definition.TableDefinition) Test(org.testng.annotations.Test)

Example 18 with TableDefinition

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

the class DefineTableTestCase method test4.

@Test
public void test4() throws SiddhiParserException {
    TableDefinition streamDefinition = SiddhiCompiler.parseTableDefinition("" + " @from(datasource='MyDatabase','CUSTOM')" + " define table cseStream ( symbol string, price int, volume float )");
    AssertJUnit.assertEquals(TableDefinition.id("cseStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).annotation(Annotation.annotation("from").element("datasource", "MyDatabase").element("CUSTOM")).toString(), streamDefinition.toString());
}
Also used : TableDefinition(io.siddhi.query.api.definition.TableDefinition) Test(org.testng.annotations.Test)

Example 19 with TableDefinition

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

the class DefineTableTestCase method test3.

@Test
public void test3() throws SiddhiParserException {
    TableDefinition streamDefinition = SiddhiCompiler.parseTableDefinition("define table cseStream ( symbol " + "string, price int, volume float )");
    AssertJUnit.assertEquals(TableDefinition.id("cseStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).toString(), streamDefinition.toString());
}
Also used : TableDefinition(io.siddhi.query.api.definition.TableDefinition) Test(org.testng.annotations.Test)

Example 20 with TableDefinition

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

the class DefineTableTestCase method testQuery1.

@Test
public void testQuery1() throws InterruptedException {
    log.info("testTableDefinition1 - OUT 0");
    SiddhiManager siddhiManager = new SiddhiManager();
    TableDefinition tableDefinition = TableDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT);
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineTable(tableDefinition);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.shutdown();
}
Also used : SiddhiApp(io.siddhi.query.api.SiddhiApp) TableDefinition(io.siddhi.query.api.definition.TableDefinition) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

TableDefinition (io.siddhi.query.api.definition.TableDefinition)21 Attribute (io.siddhi.query.api.definition.Attribute)11 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)8 Test (org.testng.annotations.Test)7 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)6 Annotation (io.siddhi.query.api.annotation.Annotation)5 Variable (io.siddhi.query.api.expression.Variable)5 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)4 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)3 CompiledUpdateSet (io.siddhi.core.table.CompiledUpdateSet)3 InMemoryTable (io.siddhi.core.table.InMemoryTable)3 OrderByAttribute (io.siddhi.query.api.execution.query.selection.OrderByAttribute)3 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)2 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)2 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)2 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)2 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)2 Table (io.siddhi.core.table.Table)2 UpdateSet (io.siddhi.query.api.execution.query.output.stream.UpdateSet)2 ArrayList (java.util.ArrayList)2