Search in sources :

Example 6 with TableDefinition

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());
    }
}
Also used : StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) DuplicateDefinitionException(org.ballerinalang.siddhi.query.api.exception.DuplicateDefinitionException) AggregationDefinition(org.ballerinalang.siddhi.query.api.definition.AggregationDefinition) TableDefinition(org.ballerinalang.siddhi.query.api.definition.TableDefinition) WindowDefinition(org.ballerinalang.siddhi.query.api.definition.WindowDefinition)

Example 7 with TableDefinition

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();
}
Also used : SiddhiApp(org.ballerinalang.siddhi.query.api.SiddhiApp) TableDefinition(org.ballerinalang.siddhi.query.api.definition.TableDefinition) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 8 with TableDefinition

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;
}
Also used : SiddhiQLParser(org.ballerinalang.siddhi.query.compiler.SiddhiQLParser) OrderByAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OrderByAttribute) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) OutputAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute) TableDefinition(org.ballerinalang.siddhi.query.api.definition.TableDefinition)

Example 9 with 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());
}
Also used : TableDefinition(org.ballerinalang.siddhi.query.api.definition.TableDefinition) Test(org.testng.annotations.Test)

Example 10 with TableDefinition

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());
}
Also used : TableDefinition(org.ballerinalang.siddhi.query.api.definition.TableDefinition) Test(org.testng.annotations.Test)

Aggregations

TableDefinition (org.ballerinalang.siddhi.query.api.definition.TableDefinition)11 Test (org.testng.annotations.Test)5 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)3 Table (org.ballerinalang.siddhi.core.table.Table)2 AggregationDefinition (org.ballerinalang.siddhi.query.api.definition.AggregationDefinition)2 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)2 WindowDefinition (org.ballerinalang.siddhi.query.api.definition.WindowDefinition)2 DuplicateDefinitionException (org.ballerinalang.siddhi.query.api.exception.DuplicateDefinitionException)2 OutputAttribute (org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute)2 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)2 HashMap (java.util.HashMap)1 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)1 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)1 StateEventPool (org.ballerinalang.siddhi.core.event.state.StateEventPool)1 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)1 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)1 StreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter)1