use of io.siddhi.query.api.definition.AbstractDefinition in project siddhi by wso2.
the class SiddhiAppRuntimeBuilder method defineTable.
public void defineTable(TableDefinition tableDefinition) {
DefinitionParserHelper.validateDefinition(tableDefinition, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap);
AbstractDefinition currentDefinition = tableDefinitionMap.putIfAbsent(tableDefinition.getId(), tableDefinition);
if (currentDefinition != null) {
tableDefinition = (TableDefinition) currentDefinition;
}
DefinitionParserHelper.addTable(tableDefinition, tableMap, siddhiAppContext);
}
use of io.siddhi.query.api.definition.AbstractDefinition in project siddhi by wso2.
the class SiddhiAppRuntimeBuilder method defineWindow.
public void defineWindow(WindowDefinition windowDefinition) {
DefinitionParserHelper.validateDefinition(windowDefinition, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap);
DefinitionParserHelper.addStreamJunction(windowDefinition, streamJunctionMap, siddhiAppContext);
AbstractDefinition currentDefinition = windowDefinitionMap.putIfAbsent(windowDefinition.getId(), windowDefinition);
if (currentDefinition != null) {
windowDefinition = (WindowDefinition) currentDefinition;
}
DefinitionParserHelper.addWindow(windowDefinition, windowMap, siddhiAppContext);
}
use of io.siddhi.query.api.definition.AbstractDefinition 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.AbstractDefinition in project siddhi by wso2.
the class SiddhiAppRuntimeBuilder method defineStream.
public void defineStream(StreamDefinition streamDefinition) {
DefinitionParserHelper.validateDefinition(streamDefinition, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap);
AbstractDefinition currentDefinition = streamDefinitionMap.putIfAbsent(streamDefinition.getId(), streamDefinition);
if (currentDefinition != null) {
streamDefinition = (StreamDefinition) currentDefinition;
}
try {
DefinitionParserHelper.addStreamJunction(streamDefinition, streamJunctionMap, siddhiAppContext);
} catch (Throwable t) {
ExceptionUtil.populateQueryContext(t, streamDefinition, siddhiAppContext);
throw t;
}
DefinitionParserHelper.addEventSource(streamDefinition, sourceMap, siddhiAppContext);
StreamJunction streamJunction = streamJunctionMap.get(streamDefinition.getId());
DefinitionParserHelper.addEventSink(streamDefinition, streamJunction, sinkMap, siddhiAppContext);
}
use of io.siddhi.query.api.definition.AbstractDefinition in project siddhi by wso2.
the class StreamEventConverterFactory method getConversionElements.
private static List<StreamEventConverter.ConversionMapping> getConversionElements(MetaStreamEvent metaStreamEvent, int size) {
AbstractDefinition inputDefinition = metaStreamEvent.getInputDefinitions().get(0);
List<StreamEventConverter.ConversionMapping> conversionMappings = new ArrayList<StreamEventConverter.ConversionMapping>(size);
for (int j = 0; j < 3; j++) {
List<Attribute> currentDataList = null;
if (j == 0) {
currentDataList = metaStreamEvent.getBeforeWindowData();
} else if (j == 1) {
currentDataList = metaStreamEvent.getOnAfterWindowData();
} else if (j == 2) {
currentDataList = metaStreamEvent.getOutputData();
}
if (currentDataList != null) {
int i = 0;
for (Attribute attribute : currentDataList) {
// Only variable slots will be filled.
if (attribute == null) {
i++;
} else if (!inputDefinition.getAttributeList().contains(attribute)) {
i++;
} else {
int fromPosition = inputDefinition.getAttributePosition(attribute.getName());
StreamEventConverter.ConversionMapping conversionMapping = new StreamEventConverter.ConversionMapping();
conversionMapping.setFromPosition(fromPosition);
int[] toPosition = new int[2];
toPosition[0] = j;
toPosition[1] = i;
conversionMapping.setToPosition(toPosition);
conversionMappings.add(conversionMapping);
i++;
}
}
}
}
return conversionMappings;
}
Aggregations