use of org.wso2.siddhi.query.api.definition.TableDefinition in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitDefinition_table.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public TableDefinition visitDefinition_table(@NotNull SiddhiQLParser.Definition_tableContext ctx) {
// definition_table
// : annotation* DEFINE TABLE source '(' attribute_name attribute_type (',' attribute_name attribute_type )*
// ')' definition_store?
// ;
Source source = (Source) visit(ctx.source());
if (source.isInnerStream) {
throw newSiddhiParserException(ctx, "'#' cannot be used, because Tables can't be defined as " + "InnerStream!");
}
TableDefinition tableDefinition = TableDefinition.id(source.streamId);
List<SiddhiQLParser.Attribute_nameContext> attribute_names = ctx.attribute_name();
List<SiddhiQLParser.Attribute_typeContext> attribute_types = ctx.attribute_type();
for (int i = 0; i < attribute_names.size(); i++) {
SiddhiQLParser.Attribute_nameContext attributeNameContext = attribute_names.get(i);
SiddhiQLParser.Attribute_typeContext attributeTypeContext = attribute_types.get(i);
tableDefinition.attribute((String) visit(attributeNameContext), (Attribute.Type) visit(attributeTypeContext));
}
for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
tableDefinition.annotation((Annotation) visit(annotationContext));
}
populateQueryContext(tableDefinition, ctx);
return tableDefinition;
}
use of org.wso2.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());
}
use of org.wso2.siddhi.query.api.definition.TableDefinition in project siddhi by wso2.
the class DefineTableTestCase method test2.
@Test
public void test2() throws SiddhiParserException {
TableDefinition streamDefinition = SiddhiCompiler.parseTableDefinition("define table `define` ( `string` " + "string, price int, volume float );");
AssertJUnit.assertEquals(TableDefinition.id("define").attribute("string", 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 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());
}
use of org.wso2.siddhi.query.api.definition.TableDefinition in project siddhi by wso2.
the class SiddhiApp method defineTable.
public SiddhiApp defineTable(TableDefinition tableDefinition) {
if (tableDefinition == null) {
throw new SiddhiAppValidationException("Table Definition should not be null");
} else if (tableDefinition.getId() == null) {
throw new SiddhiAppValidationException("Table Id should not be null for Table Definition", tableDefinition.getQueryContextStartIndex(), tableDefinition.getQueryContextEndIndex());
}
checkDuplicateDefinition(tableDefinition);
this.tableDefinitionMap.put(tableDefinition.getId(), tableDefinition);
return this;
}
Aggregations