ExprEvaluatorContextStatement exprEvaluatorContext = new ExprEvaluatorContextStatement(statementContext);
this.isExprRequiresMultimatchState = new boolean[variableStreams.size()];
for (int defineIndex = 0; defineIndex < matchRecognizeSpec.getDefines().size(); defineIndex++)
{
MatchRecognizeDefineItem defineItem = matchRecognizeSpec.getDefines().get(defineIndex);
if (definedVariables.contains(defineItem.getIdentifier()))
{
throw new ExprValidationException("Variable '" + defineItem.getIdentifier() + "' has already been defined");
}
definedVariables.add(defineItem.getIdentifier());
// stream-type visibilities handled here
StreamTypeService typeServiceDefines = EventRowRegexNFAViewFactoryHelper.buildDefineStreamTypeServiceDefine(statementContext, variableStreams, defineItem, visibility, parentViewType);
ExprNode exprNodeResult = handlePreviousFunctions(defineItem.getExpression());
ExprValidationContext validationContext = new ExprValidationContext(typeServiceDefines, statementContext.getMethodResolutionService(), null, statementContext.getSchedulingService(), statementContext.getVariableService(), exprEvaluatorContext, statementContext.getEventAdapterService(), statementContext.getStatementName(), statementContext.getStatementId(), statementContext.getAnnotations(), statementContext.getContextDescriptor(), true, false);
ExprNode validated;
try {
// validate
validated = ExprNodeUtility.getValidatedSubtree(ExprNodeOrigin.MATCHRECOGDEFINE, exprNodeResult, validationContext);
// check aggregates
defineItem.setExpression(validated);
ExprAggregateNodeUtil.getAggregatesBottomUp(validated, aggregateNodes);
if (!aggregateNodes.isEmpty()) {
throw new ExprValidationException("An aggregate function may not appear in a DEFINE clause");
}
}
catch (ExprValidationException ex) {
throw new ExprValidationException("Failed to validate condition expression for variable '" + defineItem.getIdentifier() + "': " + ex.getMessage(), ex);
}
// determine access to event properties from multi-matches
ExprNodeIdentifierCollectVisitor visitor = new ExprNodeIdentifierCollectVisitor();
validated.accept(visitor);
Set<Integer> streamsRequired = visitor.getStreamsRequired();
for (int streamRequired : streamsRequired) {
if (streamRequired >= variableStreams.size()) {
int streamNumIdent = variableStreams.get(defineItem.getIdentifier()).getFirst();
isExprRequiresMultimatchState[streamNumIdent] = true;
break;
}
}
}