Search in sources :

Example 16 with SiddhiAppRuntimeException

use of io.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.

the class PartitionStateHolder method returnGroupByStates.

@Override
public void returnGroupByStates(Map states) {
    String partitionFlowId = SiddhiAppContext.getPartitionFlowId();
    for (Iterator<Map.Entry<String, State>> iterator = ((Set<Map.Entry<String, State>>) states.entrySet()).iterator(); iterator.hasNext(); ) {
        Map.Entry<String, State> stateEntry = iterator.next();
        State state = stateEntry.getValue();
        if (state.activeUseCount == 0) {
            try {
                if (state.canDestroy()) {
                    iterator.remove();
                }
            } catch (Throwable t) {
                log.error("Dropping partition state for partition key '" + partitionFlowId + "' and the group by key '" + stateEntry.getKey() + "', due to error! " + t.getMessage(), t);
                iterator.remove();
            }
        } else if (state.activeUseCount < 0) {
            throw new SiddhiAppRuntimeException("State active count has reached less then zero for partition key '" + partitionFlowId + "' and the group by key '" + stateEntry.getKey() + "', current value is " + state.activeUseCount);
        }
    }
    if (states.isEmpty()) {
        states.remove(partitionFlowId);
    }
}
Also used : Set(java.util.Set) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 17 with SiddhiAppRuntimeException

use of io.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.

the class DistinctCountIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    Attribute set;
    Expression setInitialValue;
    // distinct-count is not supported for object types.
    if (attributeType.equals(Attribute.Type.FLOAT) || attributeType.equals(Attribute.Type.DOUBLE) || attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG) || attributeType.equals(Attribute.Type.STRING) || attributeType.equals(Attribute.Type.BOOL)) {
        set = new Attribute("AGG_SET_".concat(attributeName), Attribute.Type.OBJECT);
        setInitialValue = Expression.function("createSet", Expression.variable(attributeName));
    } else {
        throw new SiddhiAppRuntimeException("Distinct count aggregation cannot be executed on attribute type " + attributeType.toString());
    }
    this.baseAttributes = new Attribute[] { set };
    this.baseAttributesInitialValues = new Expression[] { setInitialValue };
}
Also used : ReturnAttribute(io.siddhi.annotation.ReturnAttribute) Attribute(io.siddhi.query.api.definition.Attribute) Expression(io.siddhi.query.api.expression.Expression) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException)

Example 18 with SiddhiAppRuntimeException

use of io.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.

the class SumIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    Attribute sum;
    Expression sumInitialValue;
    if (attributeName == null) {
        throw new SiddhiAppCreationException("Sum incremental attribute aggregation cannot be executed " + "when no parameters are given");
    }
    if (attributeType.equals(Attribute.Type.FLOAT) || attributeType.equals(Attribute.Type.DOUBLE)) {
        sum = new Attribute("AGG_SUM_".concat(attributeName), Attribute.Type.DOUBLE);
        sumInitialValue = Expression.function("convert", Expression.variable(attributeName), Expression.value("double"));
        returnType = Attribute.Type.DOUBLE;
    } else if (attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG)) {
        sum = new Attribute("AGG_SUM_".concat(attributeName), Attribute.Type.LONG);
        sumInitialValue = Expression.function("convert", Expression.variable(attributeName), Expression.value("long"));
        returnType = Attribute.Type.LONG;
    } else {
        throw new SiddhiAppRuntimeException("Sum aggregation cannot be executed on attribute type " + attributeType.toString());
    }
    this.baseAttributes = new Attribute[] { sum };
    // Original attribute names
    this.baseAttributesInitialValues = new Expression[] { sumInitialValue };
// used for initial values, since those would be executed using original meta
}
Also used : ReturnAttribute(io.siddhi.annotation.ReturnAttribute) Attribute(io.siddhi.query.api.definition.Attribute) Expression(io.siddhi.query.api.expression.Expression) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException)

Example 19 with SiddhiAppRuntimeException

use of io.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.

the class IndexEventHolder method add.

private void add(StreamEvent streamEvent) {
    StreamEvent existingValue = null;
    if (primaryKeyData != null) {
        Object primaryKey = constructPrimaryKey(streamEvent, primaryKeyReferenceHolders);
        existingValue = primaryKeyData.putIfAbsent(primaryKey, streamEvent);
        if (existingValue != null) {
            Exception e = new SiddhiAppRuntimeException("Siddhi App '" + siddhiAppName + "' table '" + tableName + "' dropping event : " + streamEvent + ", as there is already an event stored " + "with primary key '" + primaryKey + "'");
            if (siddhiAppContext.getRuntimeExceptionListener() != null) {
                siddhiAppContext.getRuntimeExceptionListener().exceptionThrown(e);
            }
            log.error(e.getMessage(), e);
        }
    }
    if (indexData != null) {
        for (Map.Entry<String, Integer> indexEntry : indexMetaData.entrySet()) {
            TreeMap<Object, Set<StreamEvent>> indexMap = indexData.get(indexEntry.getKey());
            Object key = streamEvent.getOutputData()[indexEntry.getValue()];
            Set<StreamEvent> values = indexMap.get(key);
            if (values == null) {
                values = new HashSet<StreamEvent>();
                values.add(streamEvent);
                indexMap.put(streamEvent.getOutputData()[indexEntry.getValue()], values);
            } else {
                values.add(streamEvent);
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StreamEvent(io.siddhi.core.event.stream.StreamEvent) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) OperationNotSupportedException(io.siddhi.core.exception.OperationNotSupportedException)

Aggregations

SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)19 HashMap (java.util.HashMap)7 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)5 StreamEvent (io.siddhi.core.event.stream.StreamEvent)5 Attribute (io.siddhi.query.api.definition.Attribute)5 ReturnAttribute (io.siddhi.annotation.ReturnAttribute)4 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)4 Expression (io.siddhi.query.api.expression.Expression)4 Map (java.util.Map)4 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)3 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)3 Set (java.util.Set)3 SiddhiOnDemandQueryContext (io.siddhi.core.config.SiddhiOnDemandQueryContext)2 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)2 ComplexEvent (io.siddhi.core.event.ComplexEvent)2 StateEvent (io.siddhi.core.event.state.StateEvent)2 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)2 TreeMap (java.util.TreeMap)2 IncrementalDataAggregator (io.siddhi.core.aggregation.IncrementalDataAggregator)1 OutOfOrderEventsDataAggregator (io.siddhi.core.aggregation.OutOfOrderEventsDataAggregator)1