ContextDetailPartitioned segmented = (ContextDetailPartitioned) contextDetail;
for (ContextDetailPartitionItem partition : segmented.getItems()) {
FilterStreamSpecRaw raw = new FilterStreamSpecRaw(partition.getFilterSpecRaw(), ViewSpec.EMPTY_VIEWSPEC_ARRAY, null, new StreamSpecOptions());
StreamSpecCompiled compiled = raw.compile(statementContext, eventTypesReferenced, false, Collections.<Integer>emptyList(), false, true, false);
if (!(compiled instanceof FilterStreamSpecCompiled)) {
throw new ExprValidationException("Partition criteria may not include named windows");
}
FilterStreamSpecCompiled result = (FilterStreamSpecCompiled) compiled;
partition.setFilterSpecCompiled(result.getFilterSpec());
}
}
else if (contextDetail instanceof ContextDetailCategory) {
// compile filter
ContextDetailCategory category = (ContextDetailCategory) contextDetail;
FilterStreamSpecRaw raw = new FilterStreamSpecRaw(category.getFilterSpecRaw(), ViewSpec.EMPTY_VIEWSPEC_ARRAY, null, new StreamSpecOptions());
FilterStreamSpecCompiled result = (FilterStreamSpecCompiled) raw.compile(statementContext, eventTypesReferenced, false, Collections.<Integer>emptyList(), false, true, false);
category.setFilterSpecCompiled(result.getFilterSpec());
servicesContext.getStatementEventTypeRefService().addReferences(statementContext.getStatementName(), CollectionUtil.toArray(eventTypesReferenced));
// compile expressions
for (ContextDetailCategoryItem item : category.getItems()) {
FilterSpecRaw filterSpecRaw = new FilterSpecRaw(category.getFilterSpecRaw().getEventTypeName(), Collections.singletonList(item.getExpression()), null);
FilterStreamSpecRaw rawExpr = new FilterStreamSpecRaw(filterSpecRaw, ViewSpec.EMPTY_VIEWSPEC_ARRAY, null, new StreamSpecOptions());
FilterStreamSpecCompiled compiled = (FilterStreamSpecCompiled) rawExpr.compile(statementContext, eventTypesReferenced, false, Collections.<Integer>emptyList(), false, true, false);
item.setCompiledFilter(compiled.getFilterSpec());
}
}
else if (contextDetail instanceof ContextDetailHash) {
ContextDetailHash hashed = (ContextDetailHash) contextDetail;
for (ContextDetailHashItem hashItem : hashed.getItems()) {
FilterStreamSpecRaw raw = new FilterStreamSpecRaw(hashItem.getFilterSpecRaw(), ViewSpec.EMPTY_VIEWSPEC_ARRAY, null, new StreamSpecOptions());
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]);