public static EvalNode MakeEvalNodeSingleChild( EvalFactoryNode child, PatternAgentInstanceContext agentInstanceContext, EvalNode parentNode) { return(child.MakeEvalNode(agentInstanceContext, parentNode)); }
private static EvalFactoryNode RecursiveAddAuditNode( PatternNodeFactory patternNodeFactory, EvalFactoryNode parentNode, bool auditPattern, bool auditPatternInstance, EvalFactoryNode evalNode, EvalAuditInstanceCount instanceCount) { var writer = new StringWriter(); evalNode.ToEPL(writer, PatternExpressionPrecedenceEnum.MINIMUM); var expressionText = writer.ToString(); var filterChildNonQuitting = parentNode != null && parentNode.IsFilterChildNonQuitting; EvalFactoryNode audit = patternNodeFactory.MakeAuditNode( auditPattern, auditPatternInstance, expressionText, instanceCount, filterChildNonQuitting); audit.AddChildNode(evalNode); IList <EvalFactoryNode> newChildNodes = new List <EvalFactoryNode>(); foreach (var child in evalNode.ChildNodes) { newChildNodes.Add( RecursiveAddAuditNode( patternNodeFactory, evalNode, auditPattern, auditPatternInstance, child, instanceCount)); } evalNode.ChildNodes.Clear(); evalNode.AddChildNodes(newChildNodes); return(audit); }
/// <summary>Searched recursivly for pattern evaluation filter nodes. </summary> /// <param name="currentNode">is the root node</param> /// <returns>list of filter nodes</returns> public static EvalNodeAnalysisResult RecursiveAnalyzeChildNodes(EvalFactoryNode currentNode) { var evalNodeAnalysisResult = new EvalNodeAnalysisResult(); RecursiveAnalyzeChildNodes(evalNodeAnalysisResult, currentNode); return(evalNodeAnalysisResult); }
public void PatternTrue( EvalFactoryNode factoryNode, object from, MatchedEventMapMinimal matchEvent, bool isQuitted, AgentInstanceContext agentInstanceContext) { }
private static void CollectFactoriesRecursive(EvalFactoryNode factoryNode, IList <EvalFactoryNode> factories) { factories.Add(factoryNode); foreach (EvalFactoryNode childNode in factoryNode.ChildNodes) { CollectFactoriesRecursive(childNode, factories); } }
public void PatternFalse( EvalFactoryNode factoryNode, object from, AgentInstanceContext agentInstanceContext) { ProcPatternFalse?.Invoke( factoryNode, from, agentInstanceContext); }
public void PatternInstance( bool increase, EvalFactoryNode factoryNode, AgentInstanceContext agentInstanceContext) { ProcPatternInstance?.Invoke( increase, factoryNode, agentInstanceContext); }
/// <summary> /// Returns all child nodes as a set. /// </summary> /// <param name="currentNode">parent node</param> /// <param name="filter">The filter.</param> /// <returns>all child nodes</returns> public static ICollection <EvalFactoryNode> RecursiveGetChildNodes(EvalFactoryNode currentNode, EvalNodeUtilFactoryFilter filter) { ICollection <EvalFactoryNode> result = new LinkedHashSet <EvalFactoryNode>(); if (filter.Consider(currentNode)) { result.Add(currentNode); } RecursiveGetChildNodes(result, currentNode, filter); return(result); }
private static void CollectPatternExpressions(IList<ExprNode> expressions, EvalFactoryNode patternExpression) { if (patternExpression is EvalFilterFactoryNode) { var filter = (EvalFilterFactoryNode) patternExpression; if (filter.RawFilterSpec.FilterExpressions != null) { expressions.AddAll(filter.RawFilterSpec.FilterExpressions); } } foreach (var child in patternExpression.ChildNodes) { CollectPatternExpressions(expressions, child); } }
/// <summary> /// Ctor. /// </summary> /// <param name="evalFactoryNode">pattern evaluation node representing pattern statement</param> /// <param name="viewSpecs">specifies what view to use to derive data</param> /// <param name="optionalStreamName">stream name, or null if none supplied</param> /// <param name="streamSpecOptions">additional options, such as unidirectional stream in a join</param> /// <param name="suppressSameEventMatches">if set to <c>true</c> [suppress same event matches].</param> /// <param name="discardPartialsOnMatch">if set to <c>true</c> [discard partials on match].</param> public PatternStreamSpecRaw( EvalFactoryNode evalFactoryNode, ViewSpec[] viewSpecs, string optionalStreamName, StreamSpecOptions streamSpecOptions, bool suppressSameEventMatches, bool discardPartialsOnMatch) : base(optionalStreamName, viewSpecs, streamSpecOptions) { _evalFactoryNode = evalFactoryNode; _suppressSameEventMatches = suppressSameEventMatches; _discardPartialsOnMatch = discardPartialsOnMatch; }
internal static bool IsConsumingFilters(EvalFactoryNode evalNode) { if (evalNode is EvalFilterFactoryNode) { return(((EvalFilterFactoryNode)evalNode).ConsumptionLevel != null); } bool consumption = false; foreach (EvalFactoryNode child in evalNode.ChildNodes) { consumption = consumption || IsConsumingFilters(child); } return(consumption); }
private static MatchEventSpec AnalyzeMatchEvent(EvalFactoryNode relativeNode) { var taggedEventTypes = new LinkedHashMap <string, Pair <EventType, string> >(); var arrayEventTypes = new LinkedHashMap <string, Pair <EventType, string> >(); // Determine all the filter nodes used in the pattern var evalNodeAnalysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes(relativeNode); // collect all filters underneath foreach (var filterNode in evalNodeAnalysisResult.FilterNodes) { var optionalTag = filterNode.EventAsName; if (optionalTag != null) { taggedEventTypes.Put( optionalTag, new Pair <EventType, string>( filterNode.FilterSpec.FilterForEventType, filterNode.FilterSpec.FilterForEventTypeName)); } } // collect those filters under a repeat since they are arrays var arrayTags = new HashSet <string>(); foreach (var matchUntilNode in evalNodeAnalysisResult.RepeatNodes) { var matchUntilAnalysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes(matchUntilNode.ChildNodes[0]); foreach (var filterNode in matchUntilAnalysisResult.FilterNodes) { var optionalTag = filterNode.EventAsName; if (optionalTag != null) { arrayTags.Add(optionalTag); } } } // for each array tag change collection foreach (var arrayTag in arrayTags) { if (taggedEventTypes.Get(arrayTag) != null) { arrayEventTypes.Put(arrayTag, taggedEventTypes.Get(arrayTag)); taggedEventTypes.Remove(arrayTag); } } return(new MatchEventSpec(taggedEventTypes, arrayEventTypes)); }
public void IncreaseRefCount(EvalFactoryNode evalNode, EvalAuditStateNode current, String patternExpr, String statementName, String engineURI) { int?count = _counts.Get(evalNode); if (count == null) { count = 1; } else { count++; } _counts.Put(evalNode, count); Print(current, patternExpr, engineURI, statementName, true, count); }
private static bool IsParentMatchUntil(EvalFactoryNode currentNode, Stack <EvalFactoryNode> parentNodeStack) { if (parentNodeStack.Count == 0) { return(false); } foreach (var deepParent in parentNodeStack.OfType <EvalMatchUntilFactoryNode>()) { var matchUntilFactoryNode = deepParent; if (matchUntilFactoryNode.ChildNodes[0] == currentNode) { return(true); } } return(false); }
public static void PatternCollectAddSubnodesAddParentNode(EvalFactoryNode evalNode, ITree node, IDictionary <ITree, EvalFactoryNode> astPatternNodeMap) { if (evalNode == null) { throw ASTWalkException.From("Invalid null expression node for '" + ASTUtil.PrintNode(node) + "'"); } for (var i = 0; i < node.ChildCount; i++) { var childNode = node.GetChild(i); var childEvalNode = PatternGetRemoveTopNode(childNode, astPatternNodeMap); if (childEvalNode != null) { evalNode.AddChildNode(childEvalNode); } } astPatternNodeMap.Put(node, evalNode); }
/// <summary> /// Ctor. /// </summary> /// <param name="evalFactoryNode">pattern evaluation node representing pattern statement</param> /// <param name="taggedEventTypes">event tags and their types as specified in the pattern, copied to allow original collection to change</param> /// <param name="arrayEventTypes">event tags and their types as specified in the pattern for any repeat-expressions that generate an array of events</param> /// <param name="allTags">All tags.</param> /// <param name="viewSpecs">specifies what view to use to derive data</param> /// <param name="optionalStreamName">stream name, or null if none supplied</param> /// <param name="streamSpecOptions">additional stream options such as unidirectional stream in a join, applicable for joins</param> /// <param name="suppressSameEventMatches">if set to <c>true</c> [suppress same event matches].</param> /// <param name="discardPartialsOnMatch">if set to <c>true</c> [discard partials on match].</param> public PatternStreamSpecCompiled(EvalFactoryNode evalFactoryNode, IDictionary <string, Pair <EventType, string> > taggedEventTypes, IDictionary <string, Pair <EventType, string> > arrayEventTypes, ISet <String> allTags, ViewSpec[] viewSpecs, String optionalStreamName, StreamSpecOptions streamSpecOptions, bool suppressSameEventMatches, bool discardPartialsOnMatch) : base(optionalStreamName, viewSpecs, streamSpecOptions) { _suppressSameEventMatches = suppressSameEventMatches; _discardPartialsOnMatch = discardPartialsOnMatch; _evalFactoryNode = evalFactoryNode; _allTags = allTags; var copy = new LinkedHashMap <String, Pair <EventType, String> >(); copy.PutAll(taggedEventTypes); _taggedEventTypes = copy; copy = new LinkedHashMap <String, Pair <EventType, String> >(); copy.PutAll(arrayEventTypes); _arrayEventTypes = copy; }
public void DecreaseRefCount(EvalFactoryNode evalNode, EvalAuditStateNode current, String patternExpr, String statementName, String engineURI) { int?count = _counts.Get(evalNode); if (count == null) { return; } count--; if (count <= 0) { _counts.Remove(evalNode); Print(current, patternExpr, engineURI, statementName, false, 0); return; } _counts.Put(evalNode, count); Print(current, patternExpr, engineURI, statementName, false, count); }
private static ContextDetailCondition GetContextCondition(EsperEPL2GrammarParser.CreateContextRangePointContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap, IDictionary <ITree, EvalFactoryNode> astPatternNodeMap, PropertyEvalSpec propertyEvalSpec, bool immediate) { if (ctx.crontabLimitParameterSet() != null) { IList <ExprNode> crontab = ASTExprHelper.ExprCollectSubNodes(ctx.crontabLimitParameterSet(), 0, astExprNodeMap); return(new ContextDetailConditionCrontab(crontab, immediate)); } else if (ctx.patternInclusionExpression() != null) { EvalFactoryNode evalNode = ASTExprHelper.PatternGetRemoveTopNode(ctx.patternInclusionExpression(), astPatternNodeMap); bool inclusive = false; if (ctx.i != null) { String ident = ctx.i.Text; if (ident != null && ident.ToLower() != "inclusive") { throw ASTWalkException.From("Expected 'inclusive' keyword after '@', found '" + ident + "' instead"); } inclusive = true; } return(new ContextDetailConditionPattern(evalNode, inclusive, immediate)); } else if (ctx.createContextFilter() != null) { FilterSpecRaw filterSpecRaw = ASTFilterSpecHelper.WalkFilterSpec(ctx.createContextFilter().eventFilterExpression(), propertyEvalSpec, astExprNodeMap); String asName = ctx.createContextFilter().i != null?ctx.createContextFilter().i.Text : null; if (immediate) { throw ASTWalkException.From("Invalid use of 'now' with initiated-by stream, this combination is not supported"); } return(new ContextDetailConditionFilter(filterSpecRaw, asName)); } else if (ctx.AFTER() != null) { ExprTimePeriod timePeriod = (ExprTimePeriod)ASTExprHelper.ExprCollectSubNodes(ctx.timePeriod(), 0, astExprNodeMap)[0]; return(new ContextDetailConditionTimePeriod(timePeriod, immediate)); } else { throw new IllegalStateException("Unrecognized child type"); } }
private static void RecursiveCompile( EvalFactoryNode evalNode, StatementContext context, ExprEvaluatorContext evaluatorContext, ICollection <string> eventTypeReferences, bool isInsertInto, MatchEventSpec tags, Deque <int> subexpressionIdStack, Stack <EvalFactoryNode> parentNodeStack, ICollection <string> allTagNamesOrdered) { var counter = 0; parentNodeStack.Push(evalNode); foreach (var child in evalNode.ChildNodes) { subexpressionIdStack.AddLast(counter++); RecursiveCompile( child, context, evaluatorContext, eventTypeReferences, isInsertInto, tags, subexpressionIdStack, parentNodeStack, allTagNamesOrdered); subexpressionIdStack.RemoveLast(); } parentNodeStack.Pop(); LinkedHashMap <string, Pair <EventType, string> > newTaggedEventTypes = null; LinkedHashMap <string, Pair <EventType, string> > newArrayEventTypes = null; if (evalNode is EvalFilterFactoryNode) { var filterNode = (EvalFilterFactoryNode)evalNode; var eventName = filterNode.RawFilterSpec.EventTypeName; if (context.TableService.GetTableMetadata(eventName) != null) { throw new ExprValidationException("Tables cannot be used in pattern filter atoms"); } var resolvedEventType = FilterStreamSpecRaw.ResolveType( context.EngineURI, eventName, context.EventAdapterService, context.PlugInTypeResolutionURIs); var finalEventType = resolvedEventType; var optionalTag = filterNode.EventAsName; var isPropertyEvaluation = false; var isParentMatchUntil = IsParentMatchUntil(evalNode, parentNodeStack); // obtain property event type, if final event type is properties if (filterNode.RawFilterSpec.OptionalPropertyEvalSpec != null) { var optionalPropertyEvaluator = PropertyEvaluatorFactory.MakeEvaluator( context.Container, filterNode.RawFilterSpec.OptionalPropertyEvalSpec, resolvedEventType, filterNode.EventAsName, context.EventAdapterService, context.EngineImportService, context.SchedulingService, context.VariableService, context.ScriptingService, context.TableService, context.EngineURI, context.StatementId, context.StatementName, context.Annotations, subexpressionIdStack, context.ConfigSnapshot, context.NamedWindowMgmtService, context.StatementExtensionServicesContext); finalEventType = optionalPropertyEvaluator.FragmentEventType; isPropertyEvaluation = true; } if (finalEventType is EventTypeSPI) { eventTypeReferences.Add(((EventTypeSPI)finalEventType).Metadata.PrimaryName); } // If a tag was supplied for the type, the tags must stay with this type, i.e. a=BeanA -> b=BeanA -> a=BeanB is a no if (optionalTag != null) { var pair = tags.TaggedEventTypes.Get(optionalTag); EventType existingType = null; if (pair != null) { existingType = pair.First; } if (existingType == null) { pair = tags.ArrayEventTypes.Get(optionalTag); if (pair != null) { throw new ExprValidationException( "Tag '" + optionalTag + "' for event '" + eventName + "' used in the repeat-until operator cannot also appear in other filter expressions"); } } if ((existingType != null) && (existingType != finalEventType)) { throw new ExprValidationException( "Tag '" + optionalTag + "' for event '" + eventName + "' has already been declared for events of type " + existingType.UnderlyingType.FullName); } pair = new Pair <EventType, string>(finalEventType, eventName); // add tagged type if (isPropertyEvaluation || isParentMatchUntil) { newArrayEventTypes = new LinkedHashMap <string, Pair <EventType, string> >(); newArrayEventTypes.Put(optionalTag, pair); } else { newTaggedEventTypes = new LinkedHashMap <string, Pair <EventType, string> >(); newTaggedEventTypes.Put(optionalTag, pair); } } // For this filter, filter types are all known tags at this time, // and additionally stream 0 (self) is our event type. // Stream type service allows resolution by property name event if that name appears in other tags. // by defaulting to stream zero. // Stream zero is always the current event type, all others follow the order of the map (stream 1 to N). var selfStreamName = optionalTag; if (selfStreamName == null) { selfStreamName = "s_" + UuidGenerator.Generate(); } var filterTypes = new LinkedHashMap <string, Pair <EventType, string> >(); var typePair = new Pair <EventType, string>(finalEventType, eventName); filterTypes.Put(selfStreamName, typePair); filterTypes.PutAll(tags.TaggedEventTypes); // for the filter, specify all tags used var filterTaggedEventTypes = new LinkedHashMap <string, Pair <EventType, string> >(tags.TaggedEventTypes); filterTaggedEventTypes.Remove(optionalTag); // handle array tags (match-until clause) LinkedHashMap <string, Pair <EventType, string> > arrayCompositeEventTypes = null; if (tags.ArrayEventTypes != null && !tags.ArrayEventTypes.IsEmpty()) { arrayCompositeEventTypes = new LinkedHashMap <string, Pair <EventType, string> >(); var patternSubexEventType = GetPatternSubexEventType( context.StatementId, "pattern", subexpressionIdStack); foreach (var entry in tags.ArrayEventTypes) { var specificArrayType = new LinkedHashMap <string, Pair <EventType, string> >(); specificArrayType.Put(entry.Key, entry.Value); var arrayTagCompositeEventType = context.EventAdapterService.CreateSemiAnonymousMapType( patternSubexEventType, Collections.GetEmptyMap <string, Pair <EventType, string> >(), specificArrayType, isInsertInto); context.StatementSemiAnonymousTypeRegistry.Register(arrayTagCompositeEventType); var tag = entry.Key; if (!filterTypes.ContainsKey(tag)) { var pair = new Pair <EventType, string>(arrayTagCompositeEventType, tag); filterTypes.Put(tag, pair); arrayCompositeEventTypes.Put(tag, pair); } } } StreamTypeService streamTypeService = new StreamTypeServiceImpl( filterTypes, context.EngineURI, true, false); var exprNodes = filterNode.RawFilterSpec.FilterExpressions; var spec = FilterSpecCompiler.MakeFilterSpec( resolvedEventType, eventName, exprNodes, filterNode.RawFilterSpec.OptionalPropertyEvalSpec, filterTaggedEventTypes, arrayCompositeEventTypes, streamTypeService, null, context, subexpressionIdStack); filterNode.FilterSpec = spec; } else if (evalNode is EvalObserverFactoryNode) { var observerNode = (EvalObserverFactoryNode)evalNode; try { var observerFactory = context.PatternResolutionService.Create(observerNode.PatternObserverSpec); var streamTypeService = GetStreamTypeService( context.EngineURI, context.StatementId, context.EventAdapterService, tags.TaggedEventTypes, tags.ArrayEventTypes, subexpressionIdStack, "observer", context); var validationContext = new ExprValidationContext( context.Container, streamTypeService, context.EngineImportService, context.StatementExtensionServicesContext, null, context.SchedulingService, context.VariableService, context.TableService, evaluatorContext, context.EventAdapterService, context.StatementName, context.StatementId, context.Annotations, context.ContextDescriptor, context.ScriptingService, false, false, false, false, null, false); var validated = ValidateExpressions( ExprNodeOrigin.PATTERNOBSERVER, observerNode.PatternObserverSpec.ObjectParameters, validationContext); MatchedEventConvertor convertor = new MatchedEventConvertorImpl( tags.TaggedEventTypes, tags.ArrayEventTypes, allTagNamesOrdered, context.EventAdapterService); observerNode.ObserverFactory = observerFactory; observerFactory.SetObserverParameters(validated, convertor, validationContext); } catch (ObserverParameterException e) { throw new ExprValidationException( "Invalid parameter for pattern observer '" + observerNode.ToPrecedenceFreeEPL() + "': " + e.Message, e); } catch (PatternObjectException e) { throw new ExprValidationException( "Failed to resolve pattern observer '" + observerNode.ToPrecedenceFreeEPL() + "': " + e.Message, e); } } else if (evalNode is EvalGuardFactoryNode) { var guardNode = (EvalGuardFactoryNode)evalNode; try { var guardFactory = context.PatternResolutionService.Create(guardNode.PatternGuardSpec); var streamTypeService = GetStreamTypeService( context.EngineURI, context.StatementId, context.EventAdapterService, tags.TaggedEventTypes, tags.ArrayEventTypes, subexpressionIdStack, "guard", context); var validationContext = new ExprValidationContext( context.Container, streamTypeService, context.EngineImportService, context.StatementExtensionServicesContext, null, context.SchedulingService, context.VariableService, context.TableService, evaluatorContext, context.EventAdapterService, context.StatementName, context.StatementId, context.Annotations, context.ContextDescriptor, context.ScriptingService, false, false, false, false, null, false); var validated = ValidateExpressions( ExprNodeOrigin.PATTERNGUARD, guardNode.PatternGuardSpec.ObjectParameters, validationContext); MatchedEventConvertor convertor = new MatchedEventConvertorImpl( tags.TaggedEventTypes, tags.ArrayEventTypes, allTagNamesOrdered, context.EventAdapterService); guardNode.GuardFactory = guardFactory; guardFactory.SetGuardParameters(validated, convertor); } catch (GuardParameterException e) { throw new ExprValidationException( "Invalid parameter for pattern guard '" + guardNode.ToPrecedenceFreeEPL() + "': " + e.Message, e); } catch (PatternObjectException e) { throw new ExprValidationException( "Failed to resolve pattern guard '" + guardNode.ToPrecedenceFreeEPL() + "': " + e.Message, e); } } else if (evalNode is EvalEveryDistinctFactoryNode) { var distinctNode = (EvalEveryDistinctFactoryNode)evalNode; var matchEventFromChildNodes = AnalyzeMatchEvent(distinctNode); var streamTypeService = GetStreamTypeService( context.EngineURI, context.StatementId, context.EventAdapterService, matchEventFromChildNodes.TaggedEventTypes, matchEventFromChildNodes.ArrayEventTypes, subexpressionIdStack, "every-distinct", context); var validationContext = new ExprValidationContext( context.Container, streamTypeService, context.EngineImportService, context.StatementExtensionServicesContext, null, context.SchedulingService, context.VariableService, context.TableService, evaluatorContext, context.EventAdapterService, context.StatementName, context.StatementId, context.Annotations, context.ContextDescriptor, context.ScriptingService, false, false, false, false, null, false); IList <ExprNode> validated; try { validated = ValidateExpressions( ExprNodeOrigin.PATTERNEVERYDISTINCT, distinctNode.Expressions, validationContext); } catch (ExprValidationPropertyException ex) { throw new ExprValidationPropertyException( ex.Message + ", every-distinct requires that all properties resolve from sub-expressions to the every-distinct", ex.InnerException); } MatchedEventConvertor convertor = new MatchedEventConvertorImpl( matchEventFromChildNodes.TaggedEventTypes, matchEventFromChildNodes.ArrayEventTypes, allTagNamesOrdered, context.EventAdapterService); distinctNode.Convertor = convertor; // Determine whether some expressions are constants or time period IList <ExprNode> distinctExpressions = new List <ExprNode>(); ExprTimePeriodEvalDeltaConst timeDeltaComputation = null; ExprNode expiryTimeExp = null; var count = -1; var last = validated.Count - 1; foreach (var expr in validated) { count++; if (count == last && expr is ExprTimePeriod) { expiryTimeExp = expr; var timePeriodExpr = (ExprTimePeriod)expiryTimeExp; timeDeltaComputation = timePeriodExpr.ConstEvaluator(new ExprEvaluatorContextStatement(context, false)); } else if (expr.IsConstantResult) { if (count == last) { var evaluateParams = new EvaluateParams(null, true, evaluatorContext); var value = expr.ExprEvaluator.Evaluate(evaluateParams); if (!(value.IsNumber())) { throw new ExprValidationException( "Invalid parameter for every-distinct, expected number of seconds constant (constant not considered for distinct)"); } var secondsExpire = expr.ExprEvaluator.Evaluate(evaluateParams); long?timeExpire; if (secondsExpire == null) { timeExpire = null; } else { timeExpire = context.TimeAbacus.DeltaForSecondsNumber(secondsExpire); } if (timeExpire != null && timeExpire > 0) { timeDeltaComputation = new ExprTimePeriodEvalDeltaConstGivenDelta(timeExpire.Value); expiryTimeExp = expr; } else { Log.Warn("Invalid seconds-expire " + timeExpire + " for " + ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(expr)); } } else { Log.Warn( "Every-distinct node utilizes an expression returning a constant value, please check expression '{0}', not adding expression to distinct-value expression list", expr.ToExpressionStringMinPrecedenceSafe()); } } 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.SetDistinctExpressions(distinctExpressions, timeDeltaComputation, expiryTimeExp); } else if (evalNode is EvalMatchUntilFactoryNode) { var matchUntilNode = (EvalMatchUntilFactoryNode)evalNode; // compile bounds expressions, if any var untilMatchEventSpec = new MatchEventSpec(tags.TaggedEventTypes, tags.ArrayEventTypes); var streamTypeService = GetStreamTypeService( context.EngineURI, context.StatementId, context.EventAdapterService, untilMatchEventSpec.TaggedEventTypes, untilMatchEventSpec.ArrayEventTypes, subexpressionIdStack, "until", context); var validationContext = new ExprValidationContext( context.Container, streamTypeService, context.EngineImportService, context.StatementExtensionServicesContext, null, context.SchedulingService, context.VariableService, context.TableService, evaluatorContext, context.EventAdapterService, context.StatementName, context.StatementId, context.Annotations, context.ContextDescriptor, context.ScriptingService, false, false, false, false, null, false); var lower = ValidateBounds(matchUntilNode.LowerBounds, validationContext); matchUntilNode.LowerBounds = lower; var upper = ValidateBounds(matchUntilNode.UpperBounds, validationContext); matchUntilNode.UpperBounds = upper; var single = ValidateBounds(matchUntilNode.SingleBound, validationContext); matchUntilNode.SingleBound = single; var convertor = new MatchedEventConvertorImpl( untilMatchEventSpec.TaggedEventTypes, untilMatchEventSpec.ArrayEventTypes, allTagNamesOrdered, context.EventAdapterService); matchUntilNode.Convertor = convertor; // compile new tag lists ISet <string> arrayTags = null; var matchUntilAnalysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes(matchUntilNode.ChildNodes[0]); foreach (var filterNode in matchUntilAnalysisResult.FilterNodes) { var optionalTag = filterNode.EventAsName; if (optionalTag != null) { if (arrayTags == null) { arrayTags = new HashSet <string>(); } arrayTags.Add(optionalTag); } } if (arrayTags != null) { foreach (var arrayTag in arrayTags) { if (!tags.ArrayEventTypes.ContainsKey(arrayTag)) { tags.ArrayEventTypes.Put(arrayTag, tags.TaggedEventTypes.Get(arrayTag)); tags.TaggedEventTypes.Remove(arrayTag); } } } matchUntilNode.TagsArrayed = GetIndexesForTags(allTagNamesOrdered, arrayTags); } else if (evalNode is EvalFollowedByFactoryNode) { var followedByNode = (EvalFollowedByFactoryNode)evalNode; StreamTypeService streamTypeService = new StreamTypeServiceImpl(context.EngineURI, false); var validationContext = new ExprValidationContext( context.Container, streamTypeService, context.EngineImportService, context.StatementExtensionServicesContext, null, context.SchedulingService, context.VariableService, context.TableService, evaluatorContext, context.EventAdapterService, context.StatementName, context.StatementId, context.Annotations, context.ContextDescriptor, context.ScriptingService, false, false, false, false, null, false); if (followedByNode.OptionalMaxExpressions != null) { IList <ExprNode> validated = new List <ExprNode>(); foreach (var maxExpr in followedByNode.OptionalMaxExpressions) { if (maxExpr == null) { validated.Add(null); } else { var visitor = new ExprNodeSummaryVisitor(); maxExpr.Accept(visitor); if (!visitor.IsPlain) { var errorMessage = "Invalid maximum expression in followed-by, " + visitor.GetMessage() + " are not allowed within the expression"; Log.Error(errorMessage); throw new ExprValidationException(errorMessage); } var validatedExpr = ExprNodeUtility.GetValidatedSubtree( ExprNodeOrigin.FOLLOWEDBYMAX, maxExpr, validationContext); validated.Add(validatedExpr); if ((validatedExpr.ExprEvaluator.ReturnType == null) || (!validatedExpr.ExprEvaluator.ReturnType.IsNumeric())) { var message = "Invalid maximum expression in followed-by, the expression must return an integer value"; throw new ExprValidationException(message); } } } followedByNode.OptionalMaxExpressions = validated; } } if (newTaggedEventTypes != null) { tags.TaggedEventTypes.PutAll(newTaggedEventTypes); } if (newArrayEventTypes != null) { tags.ArrayEventTypes.PutAll(newArrayEventTypes); } }
/// <summary>Adds a child node. </summary> /// <param name="childNode">is the child evaluation tree node to add</param> public void AddChildNode(EvalFactoryNode childNode) { _childNodes.Add(childNode); }
public EvalRootFactoryNode(EvalFactoryNode childNode) { AddChildNode(childNode); _numTreeChildNodes = AssignFactoryNodeIds(); }
/// <summary>Add a node found. </summary> /// <param name="node">found</param> public void AddNode(EvalFactoryNode node) { _activeNodes.Add(node); }
public EvalRootFactoryNode MakeRootNode(EvalFactoryNode childNode) { return(new EvalRootFactoryNode(childNode)); }
private static void RecursiveGetChildNodes(ICollection <EvalFactoryNode> set, EvalFactoryNode currentNode, EvalNodeUtilFactoryFilter filter) { foreach (var node in currentNode.ChildNodes) { if (filter.Consider(node)) { set.Add(node); } RecursiveGetChildNodes(set, node, filter); } }
public void TestSPI() { EPAdministratorSPI spi = (EPAdministratorSPI)_epService.EPAdministrator; ExprDotNode funcnode = (ExprDotNode)spi.CompileExpression("func()"); Assert.IsFalse(funcnode.ChainSpec[0].IsProperty); ExprNode node = spi.CompileExpression("value=5 and /* comment */ True"); Assert.AreEqual("value=5 and true", node.ToExpressionStringMinPrecedenceSafe()); Expression expr = spi.CompileExpressionToSODA("value=5 and True"); StringWriter buf = new StringWriter(); expr.ToEPL(buf, ExpressionPrecedenceEnum.MINIMUM); Assert.AreEqual("value=5 and true", buf.ToString()); expr = spi.CompileExpressionToSODA("5 sec"); buf = new StringWriter(); expr.ToEPL(buf, ExpressionPrecedenceEnum.MINIMUM); Assert.AreEqual("5 seconds", buf.ToString()); EvalFactoryNode pattern = spi.CompilePatternToNode("every A -> B"); Assert.That(pattern, Is.InstanceOf <EvalFollowedByFactoryNode>()); PatternExpr patternExpr = spi.CompilePatternToSODA("every A -> B"); Assert.AreEqual(typeof(PatternFollowedByExpr), patternExpr.GetType()); EPStatementObjectModel modelPattern = spi.CompilePatternToSODAModel("@Name('test') every A -> B"); Assert.AreEqual("Name", modelPattern.Annotations[0].Name); Assert.AreEqual(typeof(PatternFollowedByExpr), ((PatternStream)modelPattern.FromClause.Streams[0]).Expression.GetType()); AnnotationPart part = spi.CompileAnnotationToSODA("@somevalue(a='test', b=5)"); Assert.AreEqual("somevalue", part.Name); Assert.AreEqual(2, part.Attributes.Count); Assert.AreEqual("a", part.Attributes[0].Name); Assert.AreEqual("test", part.Attributes[0].Value); Assert.AreEqual("b", part.Attributes[1].Name); Assert.AreEqual(5, part.Attributes[1].Value); MatchRecognizeRegEx regex = spi.CompileMatchRecognizePatternToSODA("a b* c+ d? e?"); Assert.AreEqual(5, regex.Children.Count); // test fail cases string expected = "Incorrect syntax near 'in' (a reserved keyword) at line 1 column 42 [goofy in in]"; String compiled = "goofy in in"; try { spi.CompileExpression(compiled); Assert.Fail(); } catch (EPException ex) { Assert.AreEqual(expected, ex.Message); } try { spi.CompileExpressionToSODA(compiled); Assert.Fail(); } catch (EPException ex) { Assert.AreEqual(expected, ex.Message); } expected = "Incorrect syntax near 'in' (a reserved keyword) at line 1 column 6 [goofy in in]"; try { spi.CompilePatternToNode(compiled); Assert.Fail(); } catch (EPException ex) { Assert.AreEqual(expected, ex.Message); } try { spi.CompilePatternToSODA(compiled); Assert.Fail(); } catch (EPException ex) { Assert.AreEqual(expected, ex.Message); } try { spi.CompileAnnotationToSODA("not an annotation"); Assert.Fail(); } catch (EPException ex) { Assert.AreEqual("Incorrect syntax near 'not' (a reserved keyword) [not an annotation]", ex.Message); } try { spi.CompileMatchRecognizePatternToSODA("a b???"); Assert.Fail(); } catch (EPException ex) { Assert.AreEqual("Incorrect syntax near '?' expecting a closing parenthesis ')' but found a questionmark '?' at line 1 column 76 [a b???]", ex.Message); } StatementSpecRaw raw = spi.CompileEPLToRaw("select * from System.Object"); Assert.NotNull(raw); EPStatementObjectModel model = spi.MapRawToSODA(raw); Assert.NotNull(model); // try control characters TryInvalidControlCharacters(); }
public ContextDetailConditionPattern(EvalFactoryNode patternRaw, bool inclusive, bool immediate) { _patternRaw = patternRaw; _inclusive = inclusive; _immediate = immediate; }
public void PatternInstance( bool increase, EvalFactoryNode factoryNode, AgentInstanceContext agentInstanceContext) { }
public PatternExpr CompilePatternToSODA(String expression) { EvalFactoryNode node = CompilePatternToNode(expression); return(StatementSpecMapper.Unmap(node)); }
public bool Consider(EvalFactoryNode node) { return(node is EvalFilterFactoryNode); }
private static void RecursiveAnalyzeChildNodes(EvalNodeAnalysisResult evalNodeAnalysisResult, EvalFactoryNode currentNode) { if ((currentNode is EvalFilterFactoryNode) || (currentNode is EvalGuardFactoryNode) || (currentNode is EvalObserverFactoryNode) || (currentNode is EvalMatchUntilFactoryNode) || (currentNode is EvalEveryDistinctFactoryNode)) { evalNodeAnalysisResult.AddNode(currentNode); } foreach (EvalFactoryNode node in currentNode.ChildNodes) { RecursiveAnalyzeChildNodes(evalNodeAnalysisResult, node); } }