Search in sources :

Example 6 with TableDefinition

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

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

Example 8 with TableDefinition

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

Example 9 with TableDefinition

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

Example 10 with TableDefinition

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;
}
Also used : SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)

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