FilterStreamSpecCompiled result = (FilterStreamSpecCompiled) raw.compile(statementContext, eventTypesReferenced, false, Collections.<Integer>emptyList(), false, true, false);
hashItem.setFilterSpecCompiled(result.getFilterSpec());
// validate parameters
StreamTypeServiceImpl streamTypes = new StreamTypeServiceImpl(result.getFilterSpec().getFilterForEventType(), null, true, statementContext.getEngineURI());
ExprValidationContext validationContext = new ExprValidationContext(streamTypes, statementContext.getMethodResolutionService(), null, statementContext.getSchedulingService(), statementContext.getVariableService(), getDefaultAgentInstanceContext(statementContext), statementContext.getEventAdapterService(), statementContext.getStatementName(), statementContext.getStatementId(), statementContext.getAnnotations(), statementContext.getContextDescriptor(), false);
ExprNodeUtility.validate(Collections.singletonList(hashItem.getFunction()), validationContext);
}
}
else if (contextDetail instanceof ContextDetailInitiatedTerminated) {
ContextDetailInitiatedTerminated def = (ContextDetailInitiatedTerminated) contextDetail;
ContextDetailMatchPair startCondition = validateRewriteContextCondition(servicesContext, statementContext, def.getStart(), eventTypesReferenced, new MatchEventSpec(), new LinkedHashSet<String>());
ContextDetailMatchPair endCondition = validateRewriteContextCondition(servicesContext, statementContext, def.getEnd(), eventTypesReferenced, startCondition.getMatches(), startCondition.getAllTags());
def.setStart(startCondition.getCondition());
def.setEnd(endCondition.getCondition());
if (def.getDistinctExpressions() != null) {
if (!(startCondition.getCondition() instanceof ContextDetailConditionFilter)) {
throw new ExprValidationException("Distinct-expressions require a stream as the initiated-by condition");
}
ExprNode[] distinctExpressions = def.getDistinctExpressions();
if (distinctExpressions.length == 0) {
throw new ExprValidationException("Distinct-expressions have not been provided");
}
ContextDetailConditionFilter filter = (ContextDetailConditionFilter) startCondition.getCondition();
if (filter.getOptionalFilterAsName() == null) {
throw new ExprValidationException("Distinct-expressions require that a stream name is assigned to the stream using 'as'");
}
StreamTypeServiceImpl types = new StreamTypeServiceImpl(filter.getFilterSpecCompiled().getFilterForEventType(), filter.getOptionalFilterAsName(), true, servicesContext.getEngineURI());
ExprValidationContext validationContext = new ExprValidationContext(types, statementContext.getMethodResolutionService(), null, statementContext.getSchedulingService(), statementContext.getVariableService(), getDefaultAgentInstanceContext(statementContext), statementContext.getEventAdapterService(), statementContext.getStatementName(), statementContext.getStatementId(), statementContext.getAnnotations(), statementContext.getContextDescriptor(), false);
for (int i = 0; i < distinctExpressions.length; i++) {
ExprNodeUtility.validatePlainExpression("distinct-clause", distinctExpressions[i].toExpressionString(), distinctExpressions[i]);
distinctExpressions[i] = ExprNodeUtility.getValidatedSubtree(distinctExpressions[i], validationContext);
}
}