Search in sources :

Example 11 with Element

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);
        }
    }
}
Also used : SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) Element(io.siddhi.query.api.annotation.Element) TemplateBuilder(io.siddhi.core.util.transport.TemplateBuilder)

Example 12 with Element

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;
}
Also used : Element(io.siddhi.query.api.annotation.Element) ArrayList(java.util.ArrayList) Annotation(io.siddhi.query.api.annotation.Annotation) AnnotationHelper.getAnnotation(io.siddhi.query.api.util.AnnotationHelper.getAnnotation)

Example 13 with Element

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);
}
Also used : AnnotationHelper.getAnnotationElement(io.siddhi.query.api.util.AnnotationHelper.getAnnotationElement) Element(io.siddhi.query.api.annotation.Element)

Example 14 with Element

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;
}
Also used : HashMap(java.util.HashMap) Attribute(io.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) Element(io.siddhi.query.api.annotation.Element) ArrayList(java.util.ArrayList) Annotation(io.siddhi.query.api.annotation.Annotation)

Example 15 with Element

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;
}
Also used : Element(io.siddhi.query.api.annotation.Element) ExecutionElement(io.siddhi.query.api.execution.ExecutionElement) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException)

Aggregations

Element (io.siddhi.query.api.annotation.Element)16 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)8 Annotation (io.siddhi.query.api.annotation.Annotation)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 SiddhiAppValidationException (io.siddhi.query.api.exception.SiddhiAppValidationException)5 ExecutionElement (io.siddhi.query.api.execution.ExecutionElement)5 Map (java.util.Map)5 SiddhiAppContext (io.siddhi.core.config.SiddhiAppContext)4 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)3 Attribute (io.siddhi.query.api.definition.Attribute)3 AggregationRuntime (io.siddhi.core.aggregation.AggregationRuntime)2 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)2 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)2 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)2 QueryRuntimeImpl (io.siddhi.core.query.QueryRuntimeImpl)2 Table (io.siddhi.core.table.Table)2 SiddhiConstants (io.siddhi.core.util.SiddhiConstants)2 OptionHolder (io.siddhi.core.util.transport.OptionHolder)2 Window (io.siddhi.core.window.Window)2