use of io.siddhi.query.api.annotation.Element in project siddhi by wso2.
the class SinkMapper method buildMapperTemplate.
/**
* Method to create mapper template.
*
* @param streamDefinition Stream definition corresponding to mapper
* @param unmappedPayloadList mapper payload template list
*/
protected void buildMapperTemplate(StreamDefinition streamDefinition, List<Element> unmappedPayloadList) {
if (unmappedPayloadList != null && !unmappedPayloadList.isEmpty()) {
templateBuilderMap = new HashMap<>();
for (Element e : unmappedPayloadList) {
TemplateBuilder templateBuilder = new TemplateBuilder(streamDefinition, e.getValue());
if (templateBuilderMap.containsKey(e.getKey())) {
throw new SiddhiAppCreationException("Duplicate Keys, " + e.getKey() + ", in @payload() ");
}
templateBuilderMap.put(e.getKey(), templateBuilder);
}
}
}
use of io.siddhi.query.api.annotation.Element in project siddhi by wso2.
the class CacheTable method checkConditionToRouteToCache.
private boolean checkConditionToRouteToCache(Expression condition, MatchingMetaInfoHolder matchingMetaInfoHolder) {
List<String> primaryKeysArray = new ArrayList<>();
Annotation primaryKeys = getAnnotation("PrimaryKey", tableDefinition.getAnnotations());
if (primaryKeys == null) {
return false;
}
List<Element> keys = primaryKeys.getElements();
for (Element element : keys) {
primaryKeysArray.add(element.getValue());
}
recursivelyCheckConditionToRouteToCache(condition, primaryKeysArray, matchingMetaInfoHolder);
return primaryKeysArray.size() == 0;
}
use of io.siddhi.query.api.annotation.Element in project siddhi by wso2.
the class Table method initTable.
public void initTable(TableDefinition tableDefinition, StreamEventFactory storeEventPool, StreamEventCloner storeEventCloner, ConfigReader configReader, SiddhiAppContext siddhiAppContext, RecordTableHandler recordTableHandler) {
this.tableDefinition = tableDefinition;
this.scheduledExecutorService = siddhiAppContext.getScheduledExecutorService();
this.siddhiAppContext = siddhiAppContext;
this.recordTableHandler = recordTableHandler;
Element onErrorElement = getAnnotationElement(ANNOTATION_STORE, ANNOTATION_ELEMENT_ON_ERROR, tableDefinition.getAnnotations());
if (onErrorElement != null) {
this.onErrorAction = OnErrorAction.valueOf(onErrorElement.getValue());
}
if (this.onErrorAction == OnErrorAction.STORE && siddhiAppContext.getSiddhiContext().getErrorStore() == null) {
LOG.error("On error action is 'STORE' for table " + tableDefinition.getId() + " in Siddhi App " + siddhiAppContext.getName() + " but error store is not configured in Siddhi Manager");
}
this.isObjectColumnPresent = isObjectColumnPresent(tableDefinition);
if (siddhiAppContext.getStatisticsManager() != null) {
latencyTrackerFind = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_FIND);
latencyTrackerInsert = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_INSERT);
latencyTrackerUpdate = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_UPDATE);
latencyTrackerDelete = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_DELETE);
latencyTrackerUpdateOrInsert = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_UPDATE_OR_INSERT);
latencyTrackerContains = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_CONTAINS);
throughputTrackerFind = QueryParserHelper.createThroughputTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_FIND);
throughputTrackerInsert = QueryParserHelper.createThroughputTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_INSERT);
throughputTrackerUpdate = QueryParserHelper.createThroughputTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_UPDATE);
throughputTrackerDelete = QueryParserHelper.createThroughputTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_DELETE);
throughputTrackerUpdateOrInsert = QueryParserHelper.createThroughputTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_UPDATE_OR_INSERT);
throughputTrackerContains = QueryParserHelper.createThroughputTracker(siddhiAppContext, tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_CONTAINS);
}
init(tableDefinition, storeEventPool, storeEventCloner, configReader, siddhiAppContext, recordTableHandler);
}
use of io.siddhi.query.api.annotation.Element in project siddhi by wso2.
the class DefinitionParserHelper method getAttributeMappings.
private static AttributesHolder getAttributeMappings(Annotation mapAnnotation, String mapType, StreamDefinition streamDefinition) {
List<Annotation> attributeAnnotations = mapAnnotation.getAnnotations(SiddhiConstants.ANNOTATION_ATTRIBUTES);
DefinitionParserHelper.AttributesHolder attributesHolder = new DefinitionParserHelper.AttributesHolder();
if (attributeAnnotations.size() > 0) {
Map<String, String> elementMap = new HashMap<>();
List<String> elementList = new ArrayList<>();
Boolean attributesNameDefined = null;
for (Element element : attributeAnnotations.get(0).getElements()) {
if (element.getKey() == null) {
if (attributesNameDefined != null && attributesNameDefined) {
throw new SiddhiAppCreationException("Error at '" + mapType + "' defined at stream'" + streamDefinition.getId() + "', some attributes are defined and some are not defined.", element.getQueryContextStartIndex(), element.getQueryContextEndIndex());
}
attributesNameDefined = false;
elementList.add(element.getValue());
} else {
if (attributesNameDefined != null && !attributesNameDefined) {
throw new SiddhiAppCreationException("Error at '" + mapType + "' defined at stream '" + streamDefinition.getId() + "', some attributes are defined and some are not defined.", element.getQueryContextStartIndex(), element.getQueryContextEndIndex());
}
attributesNameDefined = true;
elementMap.put(element.getKey(), element.getValue());
}
}
if (elementMap.size() > 0) {
List<Attribute> attributeList = streamDefinition.getAttributeList();
for (int i = 0, attributeListSize = attributeList.size(); i < attributeListSize; i++) {
Attribute attribute = attributeList.get(i);
String value = elementMap.get(attribute.getName());
if (value == null) {
throw new SiddhiAppCreationException("Error at '" + mapType + "' defined at stream '" + streamDefinition.getId() + "', attribute '" + attribute.getName() + "' is not mapped.", mapAnnotation.getQueryContextStartIndex(), mapAnnotation.getQueryContextEndIndex());
}
assignMapping(attributesHolder, elementMap, i, attribute);
}
} else {
List<Attribute> attributeList = streamDefinition.getAttributeList();
if (elementList.size() != attributeList.size()) {
throw new SiddhiAppCreationException("Error at '" + mapType + "' defined at stream '" + streamDefinition.getId() + "', '" + elementList.size() + "' mapping attributes are " + "provided but expected attributes are '" + attributeList.size() + "'.", mapAnnotation.getQueryContextStartIndex(), mapAnnotation.getQueryContextEndIndex());
} else {
for (int i = 0; i < attributeList.size(); i++) {
Attribute attribute = attributeList.get(i);
String value = elementList.get(i);
elementMap.put(attribute.getName(), value);
}
}
for (int i = 0; i < attributeList.size(); i++) {
Attribute attribute = attributeList.get(i);
assignMapping(attributesHolder, elementMap, i, attribute);
}
}
}
return attributesHolder;
}
use of io.siddhi.query.api.annotation.Element in project siddhi by wso2.
the class SiddhiApp method addPartition.
public SiddhiApp addPartition(Partition partition) {
if (partition == null) {
throw new SiddhiAppValidationException("Partition should not be null");
}
String name = null;
Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants.ANNOTATION_ELEMENT_NAME, partition.getAnnotations());
if (element != null) {
name = element.getValue();
}
if (name != null && executionElementNameList.contains(name)) {
throw new SiddhiAppValidationException("Cannot add Partition as another Execution Element already " + "uses its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex());
}
executionElementNameList.add(name);
this.executionElementList.add(partition);
return this;
}
Aggregations