Search in sources :

Example 1 with IndexEventHolder

use of org.wso2.siddhi.core.table.holder.IndexEventHolder in project siddhi by wso2.

the class EventHolderPasser method parse.

public static EventHolder parse(AbstractDefinition tableDefinition, StreamEventPool tableStreamEventPool, SiddhiAppContext siddhiAppContext) {
    ZeroStreamEventConverter eventConverter = new ZeroStreamEventConverter();
    PrimaryKeyReferenceHolder[] primaryKeyReferenceHolders = null;
    Map<String, Integer> indexMetaData = new HashMap<String, Integer>();
    // primaryKey.
    Annotation primaryKeyAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_PRIMARY_KEY, tableDefinition.getAnnotations());
    if (primaryKeyAnnotation != null) {
        if (primaryKeyAnnotation.getElements().size() == 0) {
            throw new SiddhiAppValidationException(SiddhiConstants.ANNOTATION_PRIMARY_KEY + " annotation " + "contains " + primaryKeyAnnotation.getElements().size() + " element, at '" + tableDefinition.getId() + "'");
        }
        primaryKeyReferenceHolders = primaryKeyAnnotation.getElements().stream().map(element -> element.getValue().trim()).map(key -> new PrimaryKeyReferenceHolder(key, tableDefinition.getAttributePosition(key))).toArray(PrimaryKeyReferenceHolder[]::new);
    }
    // indexes.
    Annotation indexAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_INDEX, tableDefinition.getAnnotations());
    if (indexAnnotation != null) {
        if (indexAnnotation.getElements().size() == 0) {
            throw new SiddhiAppValidationException(SiddhiConstants.ANNOTATION_INDEX + " annotation contains " + indexAnnotation.getElements().size() + " element");
        }
        for (Element element : indexAnnotation.getElements()) {
            Integer previousValue = indexMetaData.put(element.getValue().trim(), tableDefinition.getAttributePosition(element.getValue().trim()));
            if (previousValue != null) {
                throw new SiddhiAppCreationException("Multiple " + SiddhiConstants.ANNOTATION_INDEX + " " + "annotations defined with same attribute '" + element.getValue().trim() + "', at '" + tableDefinition.getId() + "'", indexAnnotation.getQueryContextStartIndex(), indexAnnotation.getQueryContextEndIndex());
            }
        }
    }
    // not support indexBy.
    Annotation indexByAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_INDEX_BY, tableDefinition.getAnnotations());
    if (indexByAnnotation != null) {
        throw new OperationNotSupportedException(SiddhiConstants.ANNOTATION_INDEX_BY + " annotation is not " + "supported anymore, please use @PrimaryKey or @Index annotations instead," + " at '" + tableDefinition.getId() + "'");
    }
    if (primaryKeyReferenceHolders != null || indexMetaData.size() > 0) {
        boolean isNumeric = false;
        if (primaryKeyReferenceHolders != null) {
            if (primaryKeyReferenceHolders.length == 1) {
                Attribute.Type type = tableDefinition.getAttributeType(primaryKeyReferenceHolders[0].getPrimaryKeyAttribute());
                if (type == Attribute.Type.DOUBLE || type == Attribute.Type.FLOAT || type == Attribute.Type.INT || type == Attribute.Type.LONG) {
                    isNumeric = true;
                }
            }
        }
        return new IndexEventHolder(tableStreamEventPool, eventConverter, primaryKeyReferenceHolders, isNumeric, indexMetaData, tableDefinition, siddhiAppContext);
    } else {
        return new ListEventHolder(tableStreamEventPool, eventConverter);
    }
}
Also used : AnnotationHelper(org.wso2.siddhi.query.api.util.AnnotationHelper) OperationNotSupportedException(org.wso2.siddhi.core.exception.OperationNotSupportedException) AbstractDefinition(org.wso2.siddhi.query.api.definition.AbstractDefinition) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) Attribute(org.wso2.siddhi.query.api.definition.Attribute) HashMap(java.util.HashMap) IndexEventHolder(org.wso2.siddhi.core.table.holder.IndexEventHolder) Annotation(org.wso2.siddhi.query.api.annotation.Annotation) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ListEventHolder(org.wso2.siddhi.core.table.holder.ListEventHolder) Logger(org.apache.log4j.Logger) SiddhiAppContext(org.wso2.siddhi.core.config.SiddhiAppContext) Element(org.wso2.siddhi.query.api.annotation.Element) Map(java.util.Map) EventHolder(org.wso2.siddhi.core.table.holder.EventHolder) PrimaryKeyReferenceHolder(org.wso2.siddhi.core.table.holder.PrimaryKeyReferenceHolder) ZeroStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter) SiddhiConstants(org.wso2.siddhi.core.util.SiddhiConstants) OperationNotSupportedException(org.wso2.siddhi.core.exception.OperationNotSupportedException) IndexEventHolder(org.wso2.siddhi.core.table.holder.IndexEventHolder) HashMap(java.util.HashMap) Attribute(org.wso2.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) Element(org.wso2.siddhi.query.api.annotation.Element) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) PrimaryKeyReferenceHolder(org.wso2.siddhi.core.table.holder.PrimaryKeyReferenceHolder) Annotation(org.wso2.siddhi.query.api.annotation.Annotation) ZeroStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter) ListEventHolder(org.wso2.siddhi.core.table.holder.ListEventHolder)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Logger (org.apache.log4j.Logger)1 SiddhiAppContext (org.wso2.siddhi.core.config.SiddhiAppContext)1 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)1 ZeroStreamEventConverter (org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter)1 OperationNotSupportedException (org.wso2.siddhi.core.exception.OperationNotSupportedException)1 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)1 EventHolder (org.wso2.siddhi.core.table.holder.EventHolder)1 IndexEventHolder (org.wso2.siddhi.core.table.holder.IndexEventHolder)1 ListEventHolder (org.wso2.siddhi.core.table.holder.ListEventHolder)1 PrimaryKeyReferenceHolder (org.wso2.siddhi.core.table.holder.PrimaryKeyReferenceHolder)1 SiddhiConstants (org.wso2.siddhi.core.util.SiddhiConstants)1 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)1 Element (org.wso2.siddhi.query.api.annotation.Element)1 AbstractDefinition (org.wso2.siddhi.query.api.definition.AbstractDefinition)1 Attribute (org.wso2.siddhi.query.api.definition.Attribute)1 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)1 AnnotationHelper (org.wso2.siddhi.query.api.util.AnnotationHelper)1