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();
}
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());
}
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);
}
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;
}
Aggregations