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);
}
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());
}
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());
}
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());
}
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;
}
Aggregations