use of io.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.
the class AggregationParser method processAggregationSelectors.
private static void processAggregationSelectors(AggregationDefinition aggregationDefinition, SiddhiQueryContext siddhiQueryContext, Map<String, Table> tableMap, List<VariableExpressionExecutor> incomingVariableExpressionExecutors, MetaStreamEvent incomingMetaStreamEvent, List<ExpressionExecutor> incomingExpressionExecutors, List<Expression> outputExpressions, OutputAttribute outputAttribute, Expression expression) {
ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, incomingMetaStreamEvent, 0, tableMap, incomingVariableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
incomingExpressionExecutors.add(expressionExecutor);
incomingMetaStreamEvent.addOutputData(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
outputExpressions.add(Expression.variable(outputAttribute.getRename()));
}
use of io.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.
the class InputParameterValidator method validateExpressionExecutors.
/**
* The method which validates the extension specific parameters of siddhi App with the pattern specified in the
* {@link ParameterOverload} annotation in the extension class
*
* @param objectHavingAnnotation the object which has Extension annotation
* @param attributeExpressionExecutors the executors of each function parameters
* @throws SiddhiAppValidationException SiddhiAppValidation exception
*/
public static void validateExpressionExecutors(Object objectHavingAnnotation, ExpressionExecutor[] attributeExpressionExecutors) throws SiddhiAppValidationException {
Extension annotation = objectHavingAnnotation.getClass().getAnnotation(Extension.class);
if (annotation == null) {
return;
}
ParameterOverload[] parameterOverloads = annotation.parameterOverloads();
Parameter[] parameters = annotation.parameters();
String key = AnnotationHelper.createAnnotationKey(annotation);
// Count the mandatory number of parameters specified in @Extension
int mandatoryCount = 0;
Map<String, Parameter> parameterMap = new HashMap<>();
for (Parameter parameter : parameters) {
if (!parameter.optional()) {
mandatoryCount++;
}
parameterMap.put(parameter.name(), parameter);
}
// Find the parameterOverLoad
ParameterOverload parameterOverload = null;
for (ParameterOverload aParameterOverload : parameterOverloads) {
String[] overloadParameterNames = aParameterOverload.parameterNames();
if (overloadParameterNames.length == attributeExpressionExecutors.length && (overloadParameterNames.length == 0 || !overloadParameterNames[overloadParameterNames.length - 1].equals(REPETITIVE_PARAMETER_NOTATION))) {
boolean isExpectedParameterOverload = true;
for (int i = 0; i < overloadParameterNames.length; i++) {
String overloadParameterName = overloadParameterNames[i];
Parameter parameter = parameterMap.get(overloadParameterName);
boolean supportedReturnType = false;
for (DataType type : parameter.type()) {
if (attributeExpressionExecutors[i].getReturnType().toString().equalsIgnoreCase(type.toString())) {
supportedReturnType = true;
break;
}
}
if (!supportedReturnType) {
isExpectedParameterOverload = false;
break;
}
}
if (isExpectedParameterOverload) {
parameterOverload = aParameterOverload;
break;
}
} else if (overloadParameterNames.length - 1 <= attributeExpressionExecutors.length && overloadParameterNames.length > 0 && overloadParameterNames[overloadParameterNames.length - 1].equals(REPETITIVE_PARAMETER_NOTATION)) {
if (attributeExpressionExecutors.length > 0) {
boolean isExpectedParameterOverload = true;
for (int i = 0; i < attributeExpressionExecutors.length; i++) {
Parameter parameter = null;
String overloadParameterName = null;
if (i < overloadParameterNames.length - 1) {
overloadParameterName = overloadParameterNames[i];
} else {
overloadParameterName = overloadParameterNames[overloadParameterNames.length - 2];
}
parameter = parameterMap.get(overloadParameterName);
boolean supportedReturnType = false;
for (DataType type : parameter.type()) {
if (attributeExpressionExecutors[i].getReturnType().toString().equalsIgnoreCase(type.toString())) {
supportedReturnType = true;
break;
}
}
if (!supportedReturnType) {
isExpectedParameterOverload = false;
break;
}
}
if (isExpectedParameterOverload) {
parameterOverload = aParameterOverload;
break;
}
}
}
}
if (parameterOverload == null) {
if (parameterOverloads.length > 0) {
List<Attribute.Type> returnTypes = new ArrayList<>();
for (ExpressionExecutor expressionExecutor : attributeExpressionExecutors) {
returnTypes.add(expressionExecutor.getReturnType());
}
String formattedParamOverloadString = getSupportedParamOverloads(parameterMap, parameterOverloads);
throw new SiddhiAppValidationException("There is no parameterOverload for '" + key + "' that matches attribute types '" + returnTypes.stream().map(String::valueOf).collect(Collectors.joining(", ", "<", ">")) + "'. Supported parameter overloads are " + formattedParamOverloadString + ".");
} else {
if (mandatoryCount > attributeExpressionExecutors.length) {
throw new SiddhiAppValidationException("The '" + key + "' expects at least " + mandatoryCount + " parameters, but found only " + attributeExpressionExecutors.length + " input parameters.");
}
}
} else {
String[] overloadParameterNames = parameterOverload.parameterNames();
for (int i = 0; i < overloadParameterNames.length; i++) {
String overloadParameterName = overloadParameterNames[i];
Parameter parameter = parameterMap.get(overloadParameterName);
if (parameter != null && !parameter.dynamic() && !(attributeExpressionExecutors[i] instanceof ConstantExpressionExecutor)) {
throw new SiddhiAppValidationException("The '" + key + "' expects input parameter '" + parameter.name() + "' at position '" + i + "' to be static," + " but found a dynamic attribute.");
}
}
}
}
use of io.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.
the class ExpressionBuilder method buildStreamVariableExecutor.
private void buildStreamVariableExecutor(Variable variable, int streamEventChainIndex, ExpressionVisitor expressionVisitor, Attribute.Type type) {
String id = variable.getAttributeName();
if (variable.getStreamId() != null) {
id = variable.getStreamId() + "." + id;
}
expressionVisitor.beginVisitStreamVariable(id, variable.getStreamId(), variable.getAttributeName(), type);
if (!variableExpressionExecutorMap.containsKey(id)) {
ExpressionExecutor variableExpressionExecutor = ExpressionParser.parseExpression(variable, matchingMetaInfoHolder.getMetaStateEvent(), streamEventChainIndex, tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
variableExpressionExecutorMap.put(id, variableExpressionExecutor);
}
expressionVisitor.endVisitStreamVariable(id, variable.getStreamId(), variable.getAttributeName(), type);
}
use of io.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.
the class UpdateOrInsertReducer method reduceEventsForInsert.
public List<Object[]> reduceEventsForInsert(List<Object[]> failedRecords, Map<String, ExpressionExecutor> inMemorySetExecutors) {
ComplexEventChunk<StreamEvent> toInsertEventChunk = new ComplexEventChunk<>();
StateEvent joinEvent = stateEventFactory.newInstance();
for (Object[] data : failedRecords) {
StreamEvent failedEvent = streamEventFactory.newInstance();
failedEvent.setOutputData(data);
joinEvent.setEvent(streamEventIndex, failedEvent);
boolean updated = false;
toInsertEventChunk.reset();
while (toInsertEventChunk.hasNext()) {
StreamEvent toInsertEvent = toInsertEventChunk.next();
joinEvent.setEvent(storeEventIndex, toInsertEvent);
if ((Boolean) inMemoryCompiledCondition.execute(joinEvent)) {
for (Map.Entry<String, ExpressionExecutor> entry : inMemorySetExecutors.entrySet()) {
toInsertEvent.setOutputData(entry.getValue().execute(failedEvent), attributeMap.get(entry.getKey()));
}
updated = true;
}
}
if (!updated) {
toInsertEventChunk.add(failedEvent);
}
}
List<Object[]> toInsertRecords = new LinkedList<>();
toInsertEventChunk.reset();
while (toInsertEventChunk.hasNext()) {
StreamEvent streamEvent = toInsertEventChunk.next();
toInsertRecords.add(streamEvent.getOutputData());
}
return toInsertRecords;
}
use of io.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.
the class AbstractRecordTable method compileUpdateSet.
public CompiledUpdateSet compileUpdateSet(UpdateSet updateSet, MatchingMetaInfoHolder matchingMetaInfoHolder, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, SiddhiQueryContext siddhiQueryContext) {
RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = new RecordTableCompiledUpdateSet();
Map<String, ExpressionExecutor> parentExecutorMap = new HashMap<>();
for (UpdateSet.SetAttribute setAttribute : updateSet.getSetAttributeList()) {
ExpressionExecutor inMemoryAssignmentExecutor = ExpressionParser.parseExpression(setAttribute.getAssignmentExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
ExpressionBuilder expressionBuilder = new ExpressionBuilder(setAttribute.getAssignmentExpression(), matchingMetaInfoHolder, variableExpressionExecutors, tableMap, null, inMemoryAssignmentExecutor, siddhiQueryContext);
CompiledExpression compiledExpression = compileSetAttribute(expressionBuilder);
recordTableCompiledUpdateSet.put(setAttribute.getTableVariable().getAttributeName(), compiledExpression);
Map<String, ExpressionExecutor> expressionExecutorMap = expressionBuilder.getVariableExpressionExecutorMap();
parentExecutorMap.putAll(expressionExecutorMap);
}
recordTableCompiledUpdateSet.setExpressionExecutorMap(parentExecutorMap);
return recordTableCompiledUpdateSet;
}
Aggregations