/// <summary> /// Resolve a string value by first looking at the parameter value provider and by using the evaluator if one was provided /// or returning null if no value was found. /// </summary> /// <param name="name">parameter name</param> /// <param name="optionalEvaluator">evaluator</param> /// <param name="context">initialization context</param> /// <returns>value</returns> /// <throws>EPException if no value was found</throws> public static string ResolveStringOptional( string name, ExprEvaluator optionalEvaluator, DataFlowOpInitializeContext context) { string resolvedFromProvider = TryParameterProvider<string>(name, context); if (resolvedFromProvider != null) { return resolvedFromProvider; } if (optionalEvaluator == null) { return null; } return (string) optionalEvaluator.Evaluate(null, true, context.AgentInstanceContext); }
public static IEnumerator<EventBean> For( IEnumerator<EventBean> sourceIterator, ExprEvaluator filter, ExprEvaluatorContext exprEvaluatorContext) { EventBean[] evalEventArr = new EventBean[1]; while (sourceIterator.MoveNext()) { EventBean candidate = sourceIterator.Current; evalEventArr[0] = candidate; var pass = filter.Evaluate(evalEventArr, true, exprEvaluatorContext); if ((pass != null) && true.Equals(pass)) { yield return candidate; } } }
public override ExprNode Validate(ExprValidationContext validationContext) { // Must have a single child node if (ChildNodes.Length != 1) { throw new ExprValidationException("The NOT node requires exactly 1 child node"); } ExprForge forge = ChildNodes[0].Forge; Type childType = forge.EvaluationType; if (!TypeHelper.IsBoolean(childType)) { throw new ExprValidationException("Incorrect use of NOT clause, sub-expressions do not return boolean"); } _evaluator = forge.ExprEvaluator; return null; }
public static ExprEvaluator[] GetEvaluatorsNoCompile(IList<ExprForge> forges) { if (forges == null) { return null; } var eval = new ExprEvaluator[forges.Count]; for (var i = 0; i < forges.Count; i++) { var forge = forges[i]; if (forge != null) { eval[i] = forge.ExprEvaluator; } } return eval; }
/// <summary> /// Constructor. /// </summary> /// <param name="factory">for copying this view in a group-by</param> /// <param name="timestampExpression">is the field name containing a long timestamp valuethat should be in ascending order for the natural order of events and is intended to reflect /// System.currentTimeInMillis but does not necessarily have to. /// out of the window as oldData in the update method. The view compares /// each events timestamp against the newest event timestamp and those with a delta /// greater then secondsBeforeExpiry are pushed out of the window.</param> /// <param name="timestampExpressionEval">The timestamp expression eval.</param> /// <param name="timeDeltaComputation">The time delta computation.</param> /// <param name="optionalReferencePoint">The optional reference point.</param> /// <param name="viewUpdatedCollection">is a collection that the view must update when receiving events</param> /// <param name="agentInstanceViewFactoryContext">context for expression evalauation</param> public ExternallyTimedBatchView(ExternallyTimedBatchViewFactory factory, ExprNode timestampExpression, ExprEvaluator timestampExpressionEval, ExprTimePeriodEvalDeltaConst timeDeltaComputation, long?optionalReferencePoint, ViewUpdatedCollection viewUpdatedCollection, AgentInstanceViewFactoryChainContext agentInstanceViewFactoryContext) { _factory = factory; _timestampExpression = timestampExpression; _timestampExpressionEval = timestampExpressionEval; _timeDeltaComputation = timeDeltaComputation; ViewUpdatedCollection = viewUpdatedCollection; AgentInstanceViewFactoryContext = agentInstanceViewFactoryContext; ReferenceTimestamp = optionalReferencePoint; }
/// <summary> /// Constructor. /// </summary> /// <param name="externallyTimedWindowViewFactory">for copying this view in a group-by</param> /// <param name="timestampExpression">is the field name containing a long timestamp valuethat should be in ascending order for the natural order of /// events and is intended to reflect /// System.currentTimeInMillis but does not necessarily have to. /// out of the window as oldData in the update method. The view compares /// each events timestamp against the newest event timestamp and those with a delta /// greater then secondsBeforeExpiry are pushed out of the window.</param> /// <param name="timestampExpressionEval">The timestamp expression eval.</param> /// <param name="timeDeltaComputation">The time delta computation.</param> /// <param name="viewUpdatedCollection">is a collection that the view must update when receiving events</param> /// <param name="agentInstanceViewFactoryContext">context for expression evalauation</param> public ExternallyTimedWindowView( ExternallyTimedWindowViewFactory externallyTimedWindowViewFactory, ExprNode timestampExpression, ExprEvaluator timestampExpressionEval, ExprTimePeriodEvalDeltaConst timeDeltaComputation, ViewUpdatedCollection viewUpdatedCollection, AgentInstanceViewFactoryChainContext agentInstanceViewFactoryContext) { _externallyTimedWindowViewFactory = externallyTimedWindowViewFactory; _timestampExpression = timestampExpression; _timestampExpressionEval = timestampExpressionEval; _timeDeltaComputation = timeDeltaComputation; _viewUpdatedCollection = viewUpdatedCollection; _timeWindow = new TimeWindow(agentInstanceViewFactoryContext.IsRemoveStream); AgentInstanceViewFactoryContext = agentInstanceViewFactoryContext; }
private static IEnumerator<EventBean> ForImpl( ExprEvaluator filter, IEnumerator<EventBean> parent, ExprEvaluatorContext exprEvaluatorContext) { var eventsPerStream = new EventBean[1]; while (parent.MoveNext()) { var eventBean = parent.Current; eventsPerStream[0] = eventBean; var result = filter.Evaluate(eventsPerStream, true, exprEvaluatorContext); if (result != null && true.Equals(result)) { yield return eventBean; } } }
public override ExprNode Validate(ExprValidationContext validationContext) { if (ChildNodes.Count == 0) { return(null); } _evaluator = ChildNodes[0].ExprEvaluator; Type type = _evaluator.ReturnType; if (!(type.IsNumericNonFP())) { throw new ExprValidationException("Frequency operator requires an integer-type parameter"); } return(null); }
public static object EvaluateValidationTimeNoStreams( ExprEvaluator evaluator, ExprEvaluatorContext context, string expressionName) { try { return evaluator.Evaluate(null, true, context); } catch (EPException ex) { throw new ExprValidationException("Invalid " + expressionName + " expression: " + ex.Message, ex); } catch (Exception ex) { Log.Warn("Invalid " + expressionName + " expression evaluation: {}", ex.Message, ex); throw new ExprValidationException("Invalid " + expressionName + " expression"); } }
/// <summary> /// Constructor requires the name of the two fields to use in the parent view to compute the statistics. /// </summary> /// <param name="expressionXEval">is the expression to get the X values from</param> /// <param name="expressionYEval">is the expression to get the Y values from</param> /// <param name="agentInstanceContext">contains required view services</param> /// <param name="eventType">type of event</param> /// <param name="additionalProps">additional props</param> /// <param name="viewFactory">view factory</param> public BaseBivariateStatisticsView( ViewFactory viewFactory, AgentInstanceContext agentInstanceContext, ExprEvaluator expressionXEval, ExprEvaluator expressionYEval, EventType eventType, StatViewAdditionalPropsEval additionalProps ) { this.viewFactory = viewFactory; this.agentInstanceContext = agentInstanceContext; ExpressionXEval = expressionXEval; ExpressionYEval = expressionYEval; this.eventType = eventType; this.additionalProps = additionalProps; }
public static object EvaluateChecked( string objectName, ExprEvaluator evaluator, EventBean[] eventsPerStream, ExprEvaluatorContext exprEvaluatorContext) { try { return evaluator.Evaluate(eventsPerStream, true, exprEvaluatorContext); } catch (EPException) { throw; } catch (Exception ex) { throw HandleRuntimeEx(ex, objectName); } }
protected SortedAccessStrategyRelOpBase( bool isNWOnTrigger, int lookupStream, int numStreams, ExprEvaluator keyEval) { this._lookupStream = lookupStream; this._keyEval = keyEval; this._isNwOnTrigger = isNWOnTrigger; if (lookupStream != -1) { _events = new EventBean[lookupStream + 1]; } else { _events = new EventBean[numStreams + 1]; } }
/// <summary> /// Ctor. /// </summary> /// <param name="namedWindowName">the named window name</param> /// <param name="consumerObject"> /// an object that identifies the consumer, the same instance or the add and for the remove /// event /// </param> /// <param name="statementName">statement name</param> /// <param name="agentInstanceId">agent instance id</param> /// <param name="filter">filter expressions</param> /// <param name="exprEvaluatorContext">for expression evaluation</param> public VirtualDataWindowEventConsumerAdd( string namedWindowName, object consumerObject, string statementName, int agentInstanceId, ExprEvaluator filter, ExprEvaluatorContext exprEvaluatorContext) : base( namedWindowName, consumerObject, statementName, agentInstanceId) { Filter = filter; ExprEvaluatorContext = exprEvaluatorContext; }
protected CompositeAccessStrategyRelOpBase(bool isNWOnTrigger, int lookupStream, int numStreams, ExprEvaluator key, Type coercionType) { Key = key; CoercionType = coercionType; if (lookupStream != -1) { _events = new EventBean[lookupStream + 1]; } else { _events = new EventBean[numStreams + 1]; } _lookupStream = lookupStream; _isNwOnTrigger = isNWOnTrigger; }
protected internal static TimerScheduleSpec Compute( ExprEvaluator parameter, EventBean[] events, ExprEvaluatorContext exprEvaluatorContext) { object param = PatternExpressionUtil.EvaluateChecked( NAME_OBSERVER, parameter, events, exprEvaluatorContext); string iso = (string) param; if (iso == null) { throw new ScheduleParameterException("Received null parameter value"); } return TimerScheduleISO8601Parser.Parse(iso); }
public CompositeIndexQueryKeyed( bool isNWOnTrigger, int lookupStream, int numStreams, ExprEvaluator hashGetter) { this._hashGetter = hashGetter; this._isNwOnTrigger = isNWOnTrigger; this._lookupStream = lookupStream; if (lookupStream != -1) { _events = new EventBean[lookupStream + 1]; } else { _events = new EventBean[numStreams + 1]; } }
/// <summary> /// Ctor. /// </summary> /// <param name="selectExprProcessor">for processing the select expression and generting the readonly output rows</param> /// <param name="optionalHavingNode">having clause expression node</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> /// <param name="outputLimitSpec">The output limit spec.</param> /// <param name="enableOutputLimitOpt">if set to <c>true</c> [enable output limit opt].</param> /// <param name="resultSetProcessorHelperFactory">The result set processor helper factory.</param> /// <param name="numStreams">The number streams.</param> public ResultSetProcessorSimpleFactory( SelectExprProcessor selectExprProcessor, ExprEvaluator optionalHavingNode, bool isSelectRStream, OutputLimitSpec outputLimitSpec, bool enableOutputLimitOpt, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory, int numStreams) { _selectExprProcessor = selectExprProcessor; _optionalHavingExpr = optionalHavingNode; _isSelectRStream = isSelectRStream; _outputLimitSpec = outputLimitSpec; IsEnableOutputLimitOpt = enableOutputLimitOpt; ResultSetProcessorHelperFactory = resultSetProcessorHelperFactory; NumStreams = numStreams; }
/// <summary> /// Ctor. /// </summary> /// <param name="whenExpressionNode">the expression to evaluate, returning true when to output</param> /// <param name="assignments">is the optional then-clause variable assignments, or null or empty if none</param> /// <param name="statementContext">The statement context.</param> /// <throws>ExprValidationException when validation fails</throws> public OutputConditionPolledExpressionFactory( ExprNode whenExpressionNode, IList <OnTriggerSetAssignment> assignments, StatementContext statementContext) { _whenExpressionNode = whenExpressionNode.ExprEvaluator; // determine if using properties var containsBuiltinProperties = false; if (ContainsBuiltinProperties(whenExpressionNode)) { containsBuiltinProperties = true; } else { if (assignments != null) { foreach (var assignment in assignments) { if (ContainsBuiltinProperties(assignment.Expression)) { containsBuiltinProperties = true; } } } } if (containsBuiltinProperties) { _oatypeBuiltinProperties = statementContext.EventAdapterService.CreateAnonymousObjectArrayType(typeof(OutputConditionPolledExpressionFactory).Name, OutputConditionExpressionTypeUtil.TYPEINFO); } else { _oatypeBuiltinProperties = null; } if (assignments != null) { _variableReadWritePackage = new VariableReadWritePackage(assignments, statementContext.VariableService, statementContext.EventAdapterService); } else { _variableReadWritePackage = null; } }
public override Object Evaluate(EvaluateParams evaluateParams) { var eventInQuestion = evaluateParams.EventsPerStream[StreamNum]; if (eventInQuestion == null) { return(null); } var index = ExprEvaluator.Evaluate(evaluateParams); if (index == null || !index.IsInt()) { Log.Warn(GetWarningText("integer", index)); return(null); } return(_indexedGetter.Get(eventInQuestion, index.AsInt())); }
public override Object Evaluate(EvaluateParams evaluateParams) { var eventInQuestion = evaluateParams.EventsPerStream[StreamNum]; if (eventInQuestion == null) { return(null); } var result = ExprEvaluator.Evaluate(evaluateParams); if (result != null && (!(result is String))) { Log.Warn(GetWarningText("string", result)); return(null); } return(_mappedGetter.Get(eventInQuestion, (String)result)); }
/// <summary> /// Ctor. /// </summary> /// <param name="selectExprProcessor">for processing the select expression and generting the readonly output rows</param> /// <param name="optionalHavingNode">having clause expression node</param> /// <param name="isSelectRStream">true if remove stream events should be generated</param> /// <param name="isUnidirectional">true if unidirectional join</param> /// <param name="isHistoricalOnly">if set to <c>true</c> [is historical only].</param> /// <param name="outputLimitSpec">The output limit spec.</param> /// <param name="resultSetProcessorHelperFactory">The result set processor helper factory.</param> public ResultSetProcessorRowForAllFactory( SelectExprProcessor selectExprProcessor, ExprEvaluator optionalHavingNode, bool isSelectRStream, bool isUnidirectional, bool isHistoricalOnly, OutputLimitSpec outputLimitSpec, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory) { _selectExprProcessor = selectExprProcessor; OutputLimitSpec = outputLimitSpec; OptionalHavingNode = optionalHavingNode; IsSelectRStream = isSelectRStream; IsUnidirectional = isUnidirectional; IsHistoricalOnly = isHistoricalOnly; ResultSetProcessorHelperFactory = resultSetProcessorHelperFactory; }
/// <summary> /// Constructor requires the name of the two fields to use in the parent view to compute the statistics. /// </summary> /// <param name="viewFactory">The view factory.</param> /// <param name="agentInstanceContext">contains required view services</param> /// <param name="expressionX">is the expression to get the X values from</param> /// <param name="expressionY">is the expression to get the Y values from</param> /// <param name="eventType">type of event</param> /// <param name="additionalProps">additional props</param> protected BaseBivariateStatisticsView( ViewFactory viewFactory, AgentInstanceContext agentInstanceContext, ExprNode expressionX, ExprNode expressionY, EventType eventType, StatViewAdditionalProps additionalProps) { _viewFactory = viewFactory; AgentInstanceContext = agentInstanceContext; _expressionX = expressionX; _expressionXEval = expressionX.ExprEvaluator; _expressionY = expressionY; _expressionYEval = expressionY.ExprEvaluator; _eventType = eventType; _additionalProps = additionalProps; }
public override EnumEval GetEnumEval( MethodResolutionService methodResolutionService, EventAdapterService eventAdapterService, StreamTypeService streamTypeService, String statementId, String enumMethodUsedName, IList <ExprDotEvalParam> bodiesAndParameters, EventType inputEventType, Type collectionComponentType, int numStreamsIncoming, bool disablePropertyExpressionEventCollCache) { base.TypeInfo = EPTypeHelper.SingleValue(typeof(Boolean)); ExprEvaluator body = bodiesAndParameters[0].BodyEvaluator; return(new EnumEvalSequenceEqual(body, numStreamsIncoming)); }
/// <summary>Constructor. </summary> /// <param name="agentInstanceContext">is the view context for time scheduling</param> /// <param name="scheduleSpecExpressionList">list of schedule parameters</param> /// <throws><seealso cref="ExprValidationException" /> if the crontab expression failed to validate</throws> public OutputConditionPolledCrontab( IList <ExprNode> scheduleSpecExpressionList, AgentInstanceContext agentInstanceContext) { if (agentInstanceContext == null) { const string message = "OutputConditionTime requires a non-null view context"; throw new ArgumentNullException("agentInstanceContext", message); } _agentInstanceContext = agentInstanceContext; // Validate the expression var expressions = new ExprEvaluator[scheduleSpecExpressionList.Count]; var count = 0; var validationContext = new ExprValidationContext( new StreamTypeServiceImpl(agentInstanceContext.StatementContext.EngineURI, false), agentInstanceContext.StatementContext.MethodResolutionService, null, agentInstanceContext.StatementContext.SchedulingService, agentInstanceContext.StatementContext.VariableService, agentInstanceContext.StatementContext.TableService, agentInstanceContext, agentInstanceContext.StatementContext.EventAdapterService, agentInstanceContext.StatementContext.StatementName, agentInstanceContext.StatementContext.StatementId, agentInstanceContext.StatementContext.Annotations, agentInstanceContext.StatementContext.ContextDescriptor, agentInstanceContext.StatementContext.ScriptingService, false, false, false, false, null, false); foreach (var parameters in scheduleSpecExpressionList) { var node = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.OUTPUTLIMIT, parameters, validationContext); expressions[count++] = node.ExprEvaluator; } try { var scheduleSpecParameterList = Evaluate(expressions, agentInstanceContext); _scheduleSpec = ScheduleSpecUtil.ComputeValues(scheduleSpecParameterList); } catch (ScheduleParameterException e) { throw new ArgumentException("Invalid schedule specification : " + e.Message, e); } }
/// <summary> /// Filter event by applying the filter nodes evaluation method. /// </summary> /// <param name="filterExprNode">top node of the filter expression tree.</param> /// <param name="events">set of tuples of events</param> /// <param name="isNewData">true to indicate filter new data (istream) and not old data (rstream)</param> /// <param name="exprEvaluatorContext">expression evaluation context</param> public static void Filter(ExprEvaluator filterExprNode, ICollection <MultiKey <EventBean> > events, bool isNewData, ExprEvaluatorContext exprEvaluatorContext) { var keyList = new List <MultiKey <EventBean> >(); foreach (MultiKey <EventBean> key in events) { var eventArr = key.Array; var evaluateParams = new EvaluateParams(eventArr, isNewData, exprEvaluatorContext); var matched = filterExprNode.Evaluate(evaluateParams); if ((matched == null) || (false.Equals(matched))) { keyList.Add(key); } } keyList.ForEach(ev => events.Remove(ev)); }
public TableOnMergeActionIns( ExprEvaluator optionalFilter, SelectExprProcessor insertHelper, InternalEventRouter internalEventRouter, EPStatementHandle statementHandle, InternalEventRouteDest internalEventRouteDest, bool audit, TableStateRowFactory tableStateRowFactory) : base(optionalFilter) { _insertHelper = insertHelper; _internalEventRouter = internalEventRouter; _statementHandle = statementHandle; _internalEventRouteDest = internalEventRouteDest; _audit = audit; _tableStateRowFactory = tableStateRowFactory; }
/// <summary> /// Ctor. /// </summary> /// <param name="exprNode">is the bool expression</param> /// <param name="prototype">is the row of events the we are matching on</param> /// <param name="variableService">for setting variable version for evaluating variables, if required</param> public ExprNodeAdapter(ExprNode exprNode, EventBean[] prototype, VariableService variableService) { _exprNode = exprNode; _exprNodeEval = exprNode.ExprEvaluator; _variableService = variableService; _arrayPerThread = ThreadLocalManager.Create <EventBean[]>(CreateLocalData); if (prototype == null) { _prototype = new EventBean[1]; } else { _prototype = prototype; } }
private ICollection<EventBean> SnapshotAndApplyFilter( QueryGraph queryGraph, Attribute[] annotations, ExprEvaluator filterExpr, AgentInstanceContext agentInstanceContext) { var indexedResult = SnapshotNullWhenNoIndex(queryGraph, annotations, null, null); if (indexedResult != null) { if (indexedResult.IsEmpty() || filterExpr == null) { return indexedResult; } var dequeX = new ArrayDeque<EventBean>(Math.Min(indexedResult.Count, 16)); ExprNodeUtilityEvaluate.ApplyFilterExpressionIterable( indexedResult.GetEnumerator(), filterExpr, agentInstanceContext, dequeX); return dequeX; } // fall back to window operator if snapshot doesn't resolve successfully var sourceCollection = instance.EventCollection; using (IEnumerator<EventBean> enumerator = sourceCollection.GetEnumerator()) { if (!enumerator.MoveNext()) { return new EmptyList<EventBean>(); } var deque = new ArrayDeque<EventBean>(sourceCollection.Count); if (filterExpr != null) { ExprNodeUtilityEvaluate.ApplyFilterExpressionIterable( sourceCollection.GetEnumerator(), filterExpr, agentInstanceContext, deque); } else { do { deque.Add(enumerator.Current); } while (enumerator.MoveNext()); } return deque; } }
public override ExprNode Validate(ExprValidationContext validationContext) { // Must have a single child node if (ChildNodes.Length != 1) { throw new ExprValidationException("The NOT node requires exactly 1 child node"); } _evaluator = ChildNodes[0].ExprEvaluator; Type childType = _evaluator.ReturnType; if (!childType.IsBoolean()) { throw new ExprValidationException("Incorrect use of NOT clause, sub-expressions do not return bool"); } return(null); }
public ExprPreviousEvalStrategyPrev(int streamNumber, ExprEvaluator indexNode, ExprEvaluator evalNode, RandomAccessByIndexGetter randomAccessGetter, RelativeAccessByEventNIndexMap relativeAccessGetter, bool constantIndex, int?constantIndexNumber, bool tail) { _streamNumber = streamNumber; _indexNode = indexNode; _evalNode = evalNode; _randomAccessGetter = randomAccessGetter; _relativeAccessGetter = relativeAccessGetter; _isConstantIndex = constantIndex; _constantIndexNumber = constantIndexNumber; _isTail = tail; }