Search in sources :

Example 16 with TableDefinition

use of org.wso2.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(org.wso2.siddhi.query.api.SiddhiApp) TableDefinition(org.wso2.siddhi.query.api.definition.TableDefinition) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 17 with TableDefinition

use of org.wso2.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(org.wso2.siddhi.query.api.definition.TableDefinition) Test(org.testng.annotations.Test)

Example 18 with TableDefinition

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

the class SiddhiCompiler method parseTableDefinition.

public static TableDefinition parseTableDefinition(String source) throws SiddhiParserException {
    ANTLRInputStream input = new ANTLRInputStream(source);
    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(org.wso2.siddhi.query.api.definition.TableDefinition) SiddhiQLBaseVisitorImpl(org.wso2.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 19 with TableDefinition

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

the class SiddhiQLBaseVisitorImpl method visitSiddhi_app.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public SiddhiApp visitSiddhi_app(@NotNull SiddhiQLParser.Siddhi_appContext ctx) {
    SiddhiApp siddhiApp = SiddhiApp.siddhiApp();
    for (SiddhiQLParser.App_annotationContext annotationContext : ctx.app_annotation()) {
        siddhiApp.annotation((Annotation) visit(annotationContext));
    }
    for (SiddhiQLParser.Definition_streamContext streamContext : ctx.definition_stream()) {
        siddhiApp.defineStream((StreamDefinition) visit(streamContext));
    }
    for (SiddhiQLParser.Definition_tableContext tableContext : ctx.definition_table()) {
        siddhiApp.defineTable((TableDefinition) visit(tableContext));
    }
    for (SiddhiQLParser.Definition_functionContext functionContext : ctx.definition_function()) {
        siddhiApp.defineFunction((FunctionDefinition) visit(functionContext));
    }
    for (SiddhiQLParser.Definition_windowContext windowContext : ctx.definition_window()) {
        siddhiApp.defineWindow((WindowDefinition) visit(windowContext));
    }
    for (SiddhiQLParser.Definition_aggregationContext aggregationContext : ctx.definition_aggregation()) {
        siddhiApp.defineAggregation((AggregationDefinition) visit(aggregationContext));
    }
    for (SiddhiQLParser.Execution_elementContext executionElementContext : ctx.execution_element()) {
        ExecutionElement executionElement = (ExecutionElement) visit(executionElementContext);
        if (executionElement instanceof Partition) {
            siddhiApp.addPartition((Partition) executionElement);
        } else if (executionElement instanceof Query) {
            siddhiApp.addQuery((Query) executionElement);
        } else {
            throw newSiddhiParserException(ctx);
        }
    }
    for (SiddhiQLParser.Definition_triggerContext triggerContext : ctx.definition_trigger()) {
        siddhiApp.defineTrigger((TriggerDefinition) visit(triggerContext));
    }
    populateQueryContext(siddhiApp, ctx);
    return siddhiApp;
}
Also used : SiddhiQLParser(org.wso2.siddhi.query.compiler.SiddhiQLParser) Partition(org.wso2.siddhi.query.api.execution.partition.Partition) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StoreQuery(org.wso2.siddhi.query.api.execution.query.StoreQuery) Query(org.wso2.siddhi.query.api.execution.query.Query) ExecutionElement(org.wso2.siddhi.query.api.execution.ExecutionElement)

Aggregations

TableDefinition (org.wso2.siddhi.query.api.definition.TableDefinition)11 Attribute (org.wso2.siddhi.query.api.definition.Attribute)6 Test (org.testng.annotations.Test)5 AbstractDefinition (org.wso2.siddhi.query.api.definition.AbstractDefinition)5 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)4 Table (org.wso2.siddhi.core.table.Table)4 HashMap (java.util.HashMap)3 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)3 MatchingMetaInfoHolder (org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)3 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)3 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)3 Map (java.util.Map)2 ZeroStreamEventConverter (org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter)2 CompiledCondition (org.wso2.siddhi.core.util.collection.operator.CompiledCondition)2 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)2 AggregationDefinition (org.wso2.siddhi.query.api.definition.AggregationDefinition)2 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)2 WindowDefinition (org.wso2.siddhi.query.api.definition.WindowDefinition)2 DuplicateDefinitionException (org.wso2.siddhi.query.api.exception.DuplicateDefinitionException)2