Search in sources :

Example 66 with StreamDefinition

use of org.wso2.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class DefineStreamTestCase method testCreatingStreamDefinition.

// define stream StockStream (symbol string, price int, volume float );
@Test
public void testCreatingStreamDefinition() {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream StockStream ( symbol " + "string, price int, volume float );");
    StreamDefinition api = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT);
    AssertJUnit.assertEquals(api, streamDefinition);
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 67 with StreamDefinition

use of org.wso2.siddhi.query.api.definition.StreamDefinition 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 68 with StreamDefinition

use of org.wso2.siddhi.query.api.definition.StreamDefinition 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 69 with StreamDefinition

use of org.wso2.siddhi.query.api.definition.StreamDefinition 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 70 with StreamDefinition

use of org.wso2.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class SiddhiApp method defineTrigger.

public SiddhiApp defineTrigger(TriggerDefinition triggerDefinition) {
    if (triggerDefinition == null) {
        throw new SiddhiAppValidationException("Trigger Definition should not be null");
    } else if (triggerDefinition.getId() == null) {
        throw new SiddhiAppValidationException("Trigger Id should not be null for Trigger Definition", triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex());
    }
    StreamDefinition streamDefinition = StreamDefinition.id(triggerDefinition.getId()).attribute(SiddhiConstants.TRIGGERED_TIME, Attribute.Type.LONG);
    streamDefinition.setQueryContextStartIndex(triggerDefinition.getQueryContextStartIndex());
    streamDefinition.setQueryContextEndIndex(triggerDefinition.getQueryContextEndIndex());
    try {
        checkDuplicateDefinition(streamDefinition);
    } catch (DuplicateDefinitionException e) {
        throw new DuplicateDefinitionException("Trigger '" + triggerDefinition.getId() + "' cannot be defined as," + " " + e.getMessageWithOutContext(), e, triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex());
    }
    if (triggerDefinitionMap.containsKey(triggerDefinition.getId())) {
        throw new DuplicateDefinitionException("Trigger Definition with same Id '" + triggerDefinition.getId() + "' already exist '" + triggerDefinitionMap.get(triggerDefinition.getId()) + "', hence cannot add '" + triggerDefinition + "'", triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex());
    }
    this.triggerDefinitionMap.put(triggerDefinition.getId(), triggerDefinition);
    this.streamDefinitionMap.put(streamDefinition.getId(), streamDefinition);
    return this;
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) DuplicateDefinitionException(org.wso2.siddhi.query.api.exception.DuplicateDefinitionException) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)

Aggregations

StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)110 Test (org.testng.annotations.Test)105 Event (org.wso2.siddhi.core.event.Event)84 Query (org.wso2.siddhi.query.api.execution.query.Query)83 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)81 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)80 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)80 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)77 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)73 Attribute (org.wso2.siddhi.query.api.definition.Attribute)15 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)12 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)11 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)10 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)10 ArrayList (java.util.ArrayList)9 TableDefinition (org.wso2.siddhi.query.api.definition.TableDefinition)8 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)7 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)6 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)6 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)5