Exemplo n.º 1
0
        private bool EvaluateExpression(EventBean arriving, int windowSize)
        {
            ExpressionViewOAFieldEnumExtensions.Populate(BuiltinEventProps.Properties, windowSize, OldestEventTimestamp, NewestEventTimestamp, this, 0, OldestEvent, NewestEvent);
            EventsPerStream[0] = arriving;

            foreach (AggregationServiceAggExpressionDesc aggregateNode in AggregateNodes)
            {
                aggregateNode.AssignFuture(AggregationService);
            }

            var result = ExpiryExpression.Evaluate(new EvaluateParams(EventsPerStream, true, AgentInstanceContext));

            if (result == null)
            {
                return(false);
            }

            return(result.AsBoolean());
        }
Exemplo n.º 2
0
        private bool CheckEvent(ExpressionWindowTimestampEventPair first, ExpressionWindowTimestampEventPair newest, int numExpired)
        {
            ExpressionViewOAFieldEnumExtensions.Populate(BuiltinEventProps.Properties, _window.Count, first.Timestamp, newest.Timestamp,
                                                         this, numExpired, first.TheEvent, newest.TheEvent);
            EventsPerStream[0] = first.TheEvent;

            foreach (AggregationServiceAggExpressionDesc aggregateNode in AggregateNodes)
            {
                aggregateNode.AssignFuture(AggregationService);
            }

            var result = ExpiryExpression.Evaluate(new EvaluateParams(EventsPerStream, true, AgentInstanceContext));

            if (result == null)
            {
                return(false);
            }
            return(true.Equals(result));
        }
Exemplo n.º 3
0
        public void Attach(EventType parentEventType, StatementContext statementContext, ViewFactory optionalParentFactory, IList <ViewFactory> parentViewFactories)
        {
            _eventType = parentEventType;

            // define built-in fields
            var builtinTypeDef = ExpressionViewOAFieldEnumExtensions.AsMapOfTypes(_eventType);

            _builtinMapType = statementContext.EventAdapterService.CreateAnonymousObjectArrayType(
                statementContext.StatementId + "_exprview", builtinTypeDef);

            StreamTypeService streamTypeService = new StreamTypeServiceImpl(new EventType[] { _eventType, _builtinMapType }, new String[2], new bool[2], statementContext.EngineURI, false);

            // validate expression
            ExpiryExpression = ViewFactorySupport.ValidateExpr(ViewName, statementContext, ExpiryExpression, streamTypeService, 0);

            var summaryVisitor = new ExprNodeSummaryVisitor();

            ExpiryExpression.Accept(summaryVisitor);
            if (summaryVisitor.HasSubselect || summaryVisitor.HasStreamSelect || summaryVisitor.HasPreviousPrior)
            {
                throw new ViewParameterException("Invalid expiry expression: Sub-select, previous or prior functions are not supported in this context");
            }

            var returnType = ExpiryExpression.ExprEvaluator.ReturnType;

            if (returnType.GetBoxedType() != typeof(bool?))
            {
                throw new ViewParameterException("Invalid return value for expiry expression, expected a bool return value but received " + returnType.GetParameterAsString());
            }

            // determine variables used, if any
            var visitor = new ExprNodeVariableVisitor();

            ExpiryExpression.Accept(visitor);
            VariableNames = visitor.VariableNames;

            // determine aggregation nodes, if any
            var aggregateNodes = new List <ExprAggregateNode>();

            ExprAggregateNodeUtil.GetAggregatesBottomUp(ExpiryExpression, aggregateNodes);
            if (aggregateNodes.IsNotEmpty())
            {
                try {
                    AggregationServiceFactoryDesc = AggregationServiceFactoryFactory.GetService(
                        Collections.GetEmptyList <ExprAggregateNode>(),
                        Collections.GetEmptyMap <ExprNode, String>(),
                        Collections.GetEmptyList <ExprDeclaredNode>(),
                        null, aggregateNodes,
                        Collections.GetEmptyList <ExprAggregateNode>(),
                        Collections.GetEmptyList <ExprAggregateNodeGroupKey>(), false,
                        statementContext.Annotations,
                        statementContext.VariableService, false, false, null, null,
                        AggregationServiceFactoryServiceImpl.DEFAULT_FACTORY,
                        streamTypeService.EventTypes,
                        statementContext.MethodResolutionService, null,
                        statementContext.ContextName,
                        null, null);
                }
                catch (ExprValidationException ex) {
                    throw new ViewParameterException(ex.Message, ex);
                }
            }
        }