activatorResultEventType = eventType;
}
else if (streamSpec instanceof NamedWindowConsumerStreamSpec)
{
NamedWindowConsumerStreamSpec namedSpec = (NamedWindowConsumerStreamSpec) streamSpec;
NamedWindowProcessor processor = services.getNamedWindowService().getProcessor(namedSpec.getWindowName());
if (processor == null) {
throw new ExprValidationException("A named window by name '" + namedSpec.getWindowName() + "' does not exist");
}
triggereventTypeName = namedSpec.getWindowName();
activator = new ViewableActivatorNamedWindow(processor, namedSpec.getFilterExpressions(), namedSpec.getOptPropertyEvaluator());
activatorResultEventType = processor.getNamedWindowType();
if (namedSpec.getOptPropertyEvaluator() != null) {
activatorResultEventType = namedSpec.getOptPropertyEvaluator().getFragmentEventType();
}
}
else
{
throw new ExprValidationException("Unknown stream specification type: " + streamSpec);
}
// validation
SubSelectStrategyCollection subSelectStrategyCollection;
ResultSetProcessorFactoryDesc resultSetProcessorPrototype = null;
ExprNode validatedJoin = null;
StatementAgentInstanceFactoryOnTriggerSplitDesc splitDesc = null;
ResultSetProcessorFactoryDesc outputResultSetProcessorPrototype = null;
EventType outputEventType = null;
OnSetVariableViewFactory onSetVariableViewFactory = null;
NamedWindowOnExprFactory onExprFactory = null;
// validation: For on-delete and on-select and on-update triggers
if (statementSpec.getOnTriggerDesc() instanceof OnTriggerWindowDesc)
{
// Determine event types
OnTriggerWindowDesc onTriggerDesc = (OnTriggerWindowDesc) statementSpec.getOnTriggerDesc();
NamedWindowProcessor processor = services.getNamedWindowService().getProcessor(onTriggerDesc.getWindowName());
if (processor == null) {
throw new ExprValidationException("A named window by name '" + onTriggerDesc.getWindowName() + "' does not exist");
}
// validate context
processor.validateOnExpressionContext(contextName);
EventType namedWindowType = processor.getNamedWindowType();
outputEventType = namedWindowType;
services.getStatementEventTypeRefService().addReferences(statementContext.getStatementName(), new String[] {onTriggerDesc.getWindowName()});
String namedWindowName = onTriggerDesc.getOptionalAsName();
if (namedWindowName == null)
{
namedWindowName = "stream_0";
}
String streamName = streamSpec.getOptionalStreamName();
if (streamName == null)
{
streamName = "stream_1";
}
String namedWindowTypeName = onTriggerDesc.getWindowName();
// Materialize sub-select views
// 0 - named window stream
// 1 - arriving stream
// 2 - initial value before update
subSelectStrategyCollection = EPStatementStartMethodHelperSubselect.planSubSelect(services, statementContext, isQueryPlanLogging(services), subSelectStreamDesc, new String[]{namedWindowName, streamSpec.getOptionalStreamName()}, new EventType[]{processor.getNamedWindowType(), activatorResultEventType}, new String[]{namedWindowTypeName, triggereventTypeName}, stopCallbacks, statementSpec.getAnnotations(), statementSpec.getDeclaredExpressions(), contextPropertyRegistry);
StreamTypeServiceImpl typeService = new StreamTypeServiceImpl(new EventType[] {namedWindowType, activatorResultEventType}, new String[] {namedWindowName, streamName}, new boolean[] {false, true}, services.getEngineURI(), true);
// allow "initial" as a prefix to properties
StreamTypeServiceImpl assignmentTypeService;
if (namedWindowName.equals(INITIAL_VALUE_STREAM_NAME) || streamName.equals(INITIAL_VALUE_STREAM_NAME)) {
assignmentTypeService = typeService;
}
else {
assignmentTypeService = new StreamTypeServiceImpl(new EventType[] {namedWindowType, activatorResultEventType, namedWindowType}, new String[] {namedWindowName, streamName, INITIAL_VALUE_STREAM_NAME}, new boolean[] {false, true, true}, services.getEngineURI(), false);
assignmentTypeService.setStreamZeroUnambigous(true);
}
if (onTriggerDesc instanceof OnTriggerWindowUpdateDesc) {
OnTriggerWindowUpdateDesc updateDesc = (OnTriggerWindowUpdateDesc) onTriggerDesc;
ExprValidationContext validationContext = new ExprValidationContext(assignmentTypeService, statementContext.getMethodResolutionService(), null, statementContext.getSchedulingService(), statementContext.getVariableService(), getDefaultAgentInstanceContext(statementContext), statementContext.getEventAdapterService(), statementContext.getStatementName(), statementContext.getStatementId(), statementContext.getAnnotations(), statementContext.getContextDescriptor());
for (OnTriggerSetAssignment assignment : updateDesc.getAssignments())
{
ExprNode validated = ExprNodeUtility.getValidatedAssignment(assignment, validationContext);
assignment.setExpression(validated);
EPStatementStartMethodHelperValidate.validateNoAggregations(validated, "Aggregation functions may not be used within an on-update-clause");
}
}
if (onTriggerDesc instanceof OnTriggerMergeDesc) {
OnTriggerMergeDesc mergeDesc = (OnTriggerMergeDesc) onTriggerDesc;
validateMergeDesc(mergeDesc, statementContext, processor.getNamedWindowType(), namedWindowName, activatorResultEventType, streamName);
}
// validate join expression
validatedJoin = validateJoinNamedWindow(services.getEngineURI(), statementContext, statementSpec.getFilterRootNode(),
namedWindowType, namedWindowName, namedWindowTypeName,
activatorResultEventType, streamName, triggereventTypeName);
// validate filter, output rate limiting
EPStatementStartMethodHelperValidate.validateNodes(statementSpec, statementContext, typeService, null);
// Construct a processor for results; for use in on-select to process selection results
// Use a wildcard select if the select-clause is empty, such as for on-delete.
// For on-select the select clause is not empty.
if (statementSpec.getSelectClauseSpec().getSelectExprList().length == 0) {
statementSpec.getSelectClauseSpec().setSelectExprList(new SelectClauseElementWildcard());
}
resultSetProcessorPrototype = ResultSetProcessorFactoryFactory.getProcessorPrototype(
statementSpec, statementContext, typeService, null, new boolean[0], true, contextPropertyRegistry, null);
InternalEventRouter routerService = null;
boolean addToFront = false;
if (statementSpec.getInsertIntoDesc() != null || onTriggerDesc instanceof OnTriggerMergeDesc) {
routerService = services.getInternalEventRouter();
}
if (statementSpec.getInsertIntoDesc() != null) {
addToFront = statementContext.getNamedWindowService().isNamedWindow(statementSpec.getInsertIntoDesc().getEventTypeName());
}
boolean isDistinct = statementSpec.getSelectClauseSpec().isDistinct();
EventType selectResultEventType = resultSetProcessorPrototype.getResultSetProcessorFactory().getResultEventType();
StatementMetricHandle createNamedWindowMetricsHandle = processor.getCreateNamedWindowMetricsHandle();
onExprFactory = NamedWindowOnExprFactoryFactory.make(namedWindowType, onTriggerDesc.getWindowName(), namedWindowName,
onTriggerDesc,
activatorResultEventType, streamSpec.getOptionalStreamName(), addToFront, routerService,
selectResultEventType,