use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class DefineStreamTestCase method test1.
@Test
public void test1() throws SiddhiParserException {
StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream cseStream ( symbol " + "string, price int, volume float )");
AssertJUnit.assertEquals(StreamDefinition.id("cseStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).toString(), streamDefinition.toString());
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class DefineStreamTestCase method test2.
@Test
public void test2() throws SiddhiParserException {
StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream `define` ( `string` " + "string, price int, volume float );");
AssertJUnit.assertEquals(StreamDefinition.id("define").attribute("string", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).toString(), streamDefinition.toString());
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class SiddhiAppParser method createFaultStreamDefinition.
private static StreamDefinition createFaultStreamDefinition(StreamDefinition streamDefinition) {
List<Attribute> attributeList = streamDefinition.getAttributeList();
StreamDefinition faultStreamDefinition = new StreamDefinition();
faultStreamDefinition.setId(SiddhiConstants.FAULT_STREAM_PREFIX.concat(streamDefinition.getId()));
for (Attribute attribute : attributeList) {
faultStreamDefinition.attribute(attribute.getName(), attribute.getType());
}
faultStreamDefinition.attribute("_error", Attribute.Type.OBJECT);
faultStreamDefinition.setQueryContextStartIndex(streamDefinition.getQueryContextStartIndex());
faultStreamDefinition.setQueryContextEndIndex(streamDefinition.getQueryContextEndIndex());
return faultStreamDefinition;
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class DefinitionParserHelper method validateDefinition.
public static void validateDefinition(AbstractDefinition definition, ConcurrentMap<String, AbstractDefinition> streamDefinitionMap, ConcurrentMap<String, AbstractDefinition> tableDefinitionMap, ConcurrentMap<String, AbstractDefinition> windowDefinitionMap, ConcurrentMap<String, AbstractDefinition> aggregationDefinitionMap) {
AbstractDefinition 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());
}
AbstractDefinition 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());
}
AbstractDefinition existingWindowDefinition = windowDefinitionMap.get(definition.getId());
if (existingWindowDefinition != null && (!existingWindowDefinition.equals(definition) || definition instanceof WindowDefinition)) {
throw new DuplicateDefinitionException("Window Definition with same Window Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
}
AbstractDefinition existingAggregationDefinition = aggregationDefinitionMap.get(definition.getId());
if (existingAggregationDefinition != null && (!existingAggregationDefinition.equals(definition) || definition instanceof AggregationDefinition)) {
throw new DuplicateDefinitionException("Aggregation Definition with same Aggregation Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
}
}
use of io.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