use of org.ballerinalang.siddhi.query.api.definition.TableDefinition in project ballerina by ballerina-lang.
the class SiddhiApp method checkDuplicateDefinition.
private void checkDuplicateDefinition(AbstractDefinition definition) {
TableDefinition existingTableDefinition = tableDefinitionMap.get(definition.getId());
if (existingTableDefinition != null && (!existingTableDefinition.equals(definition) || definition instanceof StreamDefinition)) {
throw new DuplicateDefinitionException("Table Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingTableDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
}
StreamDefinition existingStreamDefinition = streamDefinitionMap.get(definition.getId());
if (existingStreamDefinition != null && (!existingStreamDefinition.equals(definition) || definition instanceof TableDefinition)) {
throw new DuplicateDefinitionException("Stream Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingStreamDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
}
WindowDefinition existingWindowDefinition = windowDefinitionMap.get(definition.getId());
if (existingWindowDefinition != null && (!existingWindowDefinition.equals(definition) || definition instanceof WindowDefinition)) {
throw new DuplicateDefinitionException("Stream Definition with same Window Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
}
AggregationDefinition existingAggregationDefinition = aggregationDefinitionMap.get(definition.getId());
if (existingAggregationDefinition != null && (!existingAggregationDefinition.equals(definition) || definition instanceof AggregationDefinition)) {
throw new DuplicateDefinitionException("Aggregate Definition with same Aggregate Id '" + definition.getId() + "' already exist : " + existingAggregationDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
}
}
use of org.ballerinalang.siddhi.query.api.definition.TableDefinition in project ballerina by ballerina-lang.
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.ballerinalang.siddhi.query.api.definition.TableDefinition in project ballerina by ballerina-lang.
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.ballerinalang.siddhi.query.api.definition.TableDefinition in project ballerina by ballerina-lang.
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.ballerinalang.siddhi.query.api.definition.TableDefinition in project ballerina by ballerina-lang.
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());
}
Aggregations