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);
}
}
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 };
}
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
}
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);
}
}
}
}
Aggregations