arrayCompositeEventTypes.put(tag, pair);
}
}
}
StreamTypeService streamTypeService = new StreamTypeServiceImpl(filterTypes, context.getEngineURI(), true, false);
List<ExprNode> exprNodes = filterNode.getRawFilterSpec().getFilterExpressions();
FilterSpecCompiled spec = FilterSpecCompiler.makeFilterSpec(resolvedEventType, eventName, exprNodes, filterNode.getRawFilterSpec().getOptionalPropertyEvalSpec(), filterTaggedEventTypes, arrayCompositeEventTypes, streamTypeService, context.getMethodResolutionService(), context.getSchedulingService(), context.getVariableService(), context.getEventAdapterService(), context.getEngineURI(), null, context);
filterNode.setFilterSpec(spec);
}
else if (evalNode instanceof EvalObserverNode)
{
EvalObserverNode observerNode = (EvalObserverNode) evalNode;
try
{
ObserverFactory observerFactory = context.getPatternResolutionService().create(observerNode.getPatternObserverSpec());
StreamTypeService streamTypeService = getStreamTypeService(context.getEngineURI(), context.getEventAdapterService(), tags.taggedEventTypes, tags.arrayEventTypes);
ExprValidationContext validationContext = new ExprValidationContext(streamTypeService, context.getMethodResolutionService(), null, context.getSchedulingService(), context.getVariableService(), context, context.getEventAdapterService(), context.getStatementName(), context.getAnnotations());
List<ExprNode> validated = validateExpressions(observerNode.getPatternObserverSpec().getObjectParameters(), validationContext);
MatchedEventConvertor convertor = new MatchedEventConvertorImpl(tags.taggedEventTypes, tags.arrayEventTypes, context.getEventAdapterService());
observerNode.setObserverFactory(observerFactory);
observerFactory.setObserverParameters(validated, convertor);
}
catch (ObserverParameterException e)
{
throw new ExprValidationException("Invalid parameter for pattern observer: " + e.getMessage(), e);
}
catch (PatternObjectException e)
{
throw new ExprValidationException("Failed to resolve pattern observer: " + e.getMessage(), e);
}
}
else if (evalNode instanceof EvalGuardNode)
{
EvalGuardNode guardNode = (EvalGuardNode) evalNode;
try
{
GuardFactory guardFactory = context.getPatternResolutionService().create(guardNode.getPatternGuardSpec());
StreamTypeService streamTypeService = getStreamTypeService(context.getEngineURI(), context.getEventAdapterService(), tags.taggedEventTypes, tags.arrayEventTypes);
ExprValidationContext validationContext = new ExprValidationContext(streamTypeService, context.getMethodResolutionService(), null, context.getSchedulingService(), context.getVariableService(), context, context.getEventAdapterService(), context.getStatementName(), context.getAnnotations());
List<ExprNode> validated = validateExpressions(guardNode.getPatternGuardSpec().getObjectParameters(), validationContext);
MatchedEventConvertor convertor = new MatchedEventConvertorImpl(tags.taggedEventTypes, tags.arrayEventTypes, context.getEventAdapterService());
guardNode.setGuardFactory(guardFactory);
guardFactory.setGuardParameters(validated, convertor);
}
catch (GuardParameterException e)
{
throw new ExprValidationException("Invalid parameter for pattern guard: " + e.getMessage(), e);
}
catch (PatternObjectException e)
{
throw new ExprValidationException("Failed to resolve pattern guard: " + e.getMessage(), e);
}
}
else if (evalNode instanceof EvalEveryDistinctNode)
{
EvalEveryDistinctNode distinctNode = (EvalEveryDistinctNode) evalNode;
MatchEventSpec matchEventFromChildNodes = analyzeMatchEvent(distinctNode);
StreamTypeService streamTypeService = getStreamTypeService(context.getEngineURI(), context.getEventAdapterService(), matchEventFromChildNodes.getTaggedEventTypes(), matchEventFromChildNodes.getArrayEventTypes());
ExprValidationContext validationContext = new ExprValidationContext(streamTypeService, context.getMethodResolutionService(), null, context.getSchedulingService(), context.getVariableService(), context, context.getEventAdapterService(), context.getStatementName(), context.getAnnotations());
List<ExprNode> validated;
try
{
validated = validateExpressions(distinctNode.getExpressions(), validationContext);
}
catch (ExprValidationPropertyException ex)
{
throw new ExprValidationPropertyException(ex.getMessage() + ", every-distinct requires that all properties resolve from sub-expressions to the every-distinct", ex.getCause());
}
MatchedEventConvertor convertor = new MatchedEventConvertorImpl(matchEventFromChildNodes.getTaggedEventTypes(), matchEventFromChildNodes.getArrayEventTypes(), context.getEventAdapterService());
distinctNode.setConvertor(convertor);
// Determine whether some expressions are constants or time period
List<ExprNode> distinctExpressions = new ArrayList<ExprNode>();
Long msecToExpire = null;
for (ExprNode expr : validated) {
if (expr instanceof ExprTimePeriod) {
Double secondsExpire = (Double) ((ExprTimePeriod) expr).evaluate(null, true, context);
if ((secondsExpire != null) && (secondsExpire > 0)) {
msecToExpire = Math.round(1000d * secondsExpire);
}
log.debug("Setting every-distinct msec-to-expire to " + msecToExpire);
}
else if (expr.isConstantResult()) {
log.warn("Every-distinct node utilizes an expression returning a constant value, please check expression '" + expr.toExpressionString() + "', not adding expression to distinct-value expression list");
}
else {
distinctExpressions.add(expr);
}
}
if (distinctExpressions.isEmpty()) {
throw new ExprValidationException("Every-distinct node requires one or more distinct-value expressions that each return non-constant result values");
}
distinctNode.setExpressions(distinctExpressions, msecToExpire);
}
else if (evalNode instanceof EvalMatchUntilNode)
{
EvalMatchUntilNode matchUntilNode = (EvalMatchUntilNode) evalNode;
// compile bounds expressions, if any
MatchEventSpec untilMatchEventSpec = new MatchEventSpec(tags.getTaggedEventTypes(), tags.getArrayEventTypes());
StreamTypeService streamTypeService = getStreamTypeService(context.getEngineURI(), context.getEventAdapterService(), untilMatchEventSpec.getTaggedEventTypes(), untilMatchEventSpec.getArrayEventTypes());
ExprValidationContext validationContext = new ExprValidationContext(streamTypeService, context.getMethodResolutionService(), null, context.getSchedulingService(), context.getVariableService(), context, context.getEventAdapterService(), context.getStatementName(), context.getAnnotations());
String message = "Match-until bounds value expressions must return a numeric value";
if (matchUntilNode.getLowerBounds() != null) {
ExprNode validated = ExprNodeUtil.getValidatedSubtree(matchUntilNode.getLowerBounds(), validationContext);
matchUntilNode.setLowerBounds(validated);
if ((validated.getExprEvaluator().getType() == null) || (!JavaClassHelper.isNumeric(validated.getExprEvaluator().getType()))) {
throw new ExprValidationException(message);
}
}
if (matchUntilNode.getUpperBounds() != null) {
ExprNode validated = ExprNodeUtil.getValidatedSubtree(matchUntilNode.getUpperBounds(), validationContext);
matchUntilNode.setUpperBounds(validated);
if ((validated.getExprEvaluator().getType() == null) || (!JavaClassHelper.isNumeric(validated.getExprEvaluator().getType()))) {
throw new ExprValidationException(message);
}
}
MatchedEventConvertor convertor = new MatchedEventConvertorImpl(untilMatchEventSpec.getTaggedEventTypes(), untilMatchEventSpec.getArrayEventTypes(), context.getEventAdapterService());
matchUntilNode.setConvertor(convertor);
// compile new tag lists
Set<String> arrayTags = null;
EvalNodeAnalysisResult matchUntilAnalysisResult = EvalNodeUtil.recursiveAnalyzeChildNodes(matchUntilNode.getChildNodes().get(0));
for (EvalFilterNode filterNode : matchUntilAnalysisResult.getFilterNodes())
{
String optionalTag = filterNode.getEventAsName();
if (optionalTag != null)
{
if (arrayTags == null)
{
arrayTags = new HashSet<String>();
}
arrayTags.add(optionalTag);
}
}
if (arrayTags != null)
{
for (String arrayTag : arrayTags)
{
if (!tags.arrayEventTypes.containsKey(arrayTag))
{
tags.arrayEventTypes.put(arrayTag, tags.taggedEventTypes.get(arrayTag));
tags.taggedEventTypes.remove(arrayTag);
}
}
}
matchUntilNode.setTagsArrayedSet(arrayTags);
}
else if (evalNode instanceof EvalFollowedByNode)
{
EvalFollowedByNode followedByNode = (EvalFollowedByNode) evalNode;
StreamTypeService streamTypeService = new StreamTypeServiceImpl(context.getEngineURI(), false);
ExprValidationContext validationContext = new ExprValidationContext(streamTypeService, context.getMethodResolutionService(), null, context.getSchedulingService(), context.getVariableService(), context, context.getEventAdapterService(), context.getStatementName(), context.getAnnotations());
if (followedByNode.getOptionalMaxExpressions() != null) {
List<ExprNode> validated = new ArrayList<ExprNode>();
for (ExprNode maxExpr : followedByNode.getOptionalMaxExpressions()) {