Beispiel #1
0
#pragma warning disable RCS1168
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext context)
#pragma warning restore RCS1168
        {
            if (!context.OutputPorts.IsEmpty())
            {
                throw new ArgumentException("EventBusSink operator does not provide an output stream");
            }

            var eventTypes = new EventType[context.InputPorts.Count];

            for (int i = 0; i < eventTypes.Length; i++)
            {
                eventTypes[i] = context.InputPorts.Get(i).TypeDesc.EventType;
            }
            _runtimeEventSender  = context.RuntimeEventSender;
            _eventAdapterService = context.StatementContext.EventAdapterService;

            if (collector != null)
            {
                _eventBusCollector = new EventBusCollectorImpl(
                    _eventAdapterService,
                    _runtimeEventSender);
            }
            else
            {
                _adapterFactories = new EventBeanAdapterFactory[eventTypes.Length];
                for (int i = 0; i < eventTypes.Length; i++)
                {
                    _adapterFactories[i] = context.ServicesContext.EventAdapterService.GetAdapterFactoryForType(eventTypes[i]);
                }
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the specified prepare context.
        /// </summary>
        /// <param name="prepareContext">The prepare context.</param>
        /// <returns></returns>
        /// <exception cref="ExprValidationException">
        /// Filter requires single input port
        /// or
        /// Required parameter 'filter' providing the filter expression is not provided
        /// </exception>
        /// <exception cref="ArgumentException">Filter operator requires one or two output Stream(s) but produces " + prepareContext.OutputPorts.Count + " streams</exception>
#pragma warning disable RCS1168
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext prepareContext)
#pragma warning restore RCS1168
        {
            if (prepareContext.InputPorts.Count != 1)
            {
                throw new ExprValidationException("Filter requires single input port");
            }
            if (filter == null)
            {
                throw new ExprValidationException("Required parameter 'filter' providing the filter expression is not provided");
            }
            if (prepareContext.OutputPorts.IsEmpty() || prepareContext.OutputPorts.Count > 2)
            {
                throw new ArgumentException("Filter operator requires one or two output Stream(s) but produces " + prepareContext.OutputPorts.Count + " streams");
            }

            EventType eventType = prepareContext.InputPorts[0].TypeDesc.EventType;

            _singleOutputPort = prepareContext.OutputPorts.Count == 1;

            ExprNode validated = ExprNodeUtility.ValidateSimpleGetSubtree(ExprNodeOrigin.DATAFLOWFILTER, filter, prepareContext.StatementContext, eventType, false);

            _evaluator          = validated.ExprEvaluator;
            _theEvent           = prepareContext.ServicesContext.EventAdapterService.GetShellForType(eventType);
            _eventsPerStream[0] = _theEvent;

            var typesPerPort = new GraphTypeDesc[prepareContext.OutputPorts.Count];

            for (int i = 0; i < typesPerPort.Length; i++)
            {
                typesPerPort[i] = new GraphTypeDesc(false, true, eventType);
            }
            return(new DataFlowOpInitializeResult(typesPerPort));
        }
Beispiel #3
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext context)
        {
            if (context.OutputPorts.Count != 1)
            {
                throw new ArgumentException("EPStatementSource operator requires one output stream but produces " + context.OutputPorts.Count + " streams");
            }

            if (_statementName == null && _statementFilter == null)
            {
                throw new EPException("Failed to find required 'StatementName' or 'statementFilter' parameter");
            }
            if (_statementName != null && _statementFilter != null)
            {
                throw new EPException("Both 'StatementName' or 'statementFilter' parameters were provided, only either one is expected");
            }

            DataFlowOpOutputPort portZero = context.OutputPorts[0];

            if (portZero != null && portZero.OptionalDeclaredType != null && portZero.OptionalDeclaredType.IsWildcard)
            {
                _submitEventBean = true;
            }

            _statementLifecycleSvc = context.ServicesContext.StatementLifecycleSvc;
            return(null);
        }
Beispiel #4
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext initContext)
        {
            var httpContext = initContext.ServicesContext.EventAdapterService.GetEventTypeByName("HttpContext");

            if (initContext.OutputPorts.Count == 1)
            {
                Host = initContext.OutputPorts[0].StreamName;
            }

            return new DataFlowOpInitializeResult(new[] { new com.espertech.esper.dataflow.util.GraphTypeDesc(false, false, httpContext) });
        }
Beispiel #5
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext initContext)
        {
            var httpContext = initContext.ServicesContext.EventAdapterService.GetEventTypeByName("HttpContext");

            if (initContext.OutputPorts.Count == 1)
            {
                Host = initContext.OutputPorts[0].StreamName;
            }

            return(new DataFlowOpInitializeResult(new[] { new com.espertech.esper.dataflow.util.GraphTypeDesc(false, false, httpContext) }));
        }
Beispiel #6
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext initContext)
        {
            if (initContext.InputPorts.Count == 1 && initContext.InputPorts[0].StreamNames.Count == 1)
            {
                Service = initContext.InputPorts[0].StreamNames.First();
            }

            var dataflowContext = initContext.DataflowInstanceUserObject as DataflowContext;
            FinderFactory = dataflowContext.Resolve<Func<IServiceFinder>>();

            return null;
        }
Beispiel #7
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext initContext)
        {
            if (initContext.InputPorts.Count == 1 && initContext.InputPorts[0].StreamNames.Count == 1)
            {
                Service = initContext.InputPorts[0].StreamNames.First();
            }

            var dataflowContext = initContext.DataflowInstanceUserObject as DataflowContext;

            FinderFactory = dataflowContext.Resolve <Func <IServiceFinder> >();

            return(null);
        }
        private void RunAssertionFlowGraphSource(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            epService.EPAdministrator.Configuration.AddImport(typeof(SupportGraphSource));
            SupportGraphSource.GetAndResetLifecycle();

            epService.EPAdministrator.CreateEPL("create dataflow MyDataFlow @Name('Goodie') @Audit SupportGraphSource -> outstream<SupportBean> {propOne:'abc'}");
            Assert.AreEqual(0, SupportGraphSource.GetAndResetLifecycle().Count);

            // instantiate
            var options           = new EPDataFlowInstantiationOptions().DataFlowInstanceId("id1").DataFlowInstanceUserObject("myobject");
            EPDataFlowInstance df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlow", options);

            List <object> events = SupportGraphSource.GetAndResetLifecycle();

            Assert.AreEqual(3, events.Count);
            Assert.AreEqual("instantiated", events[0]);                // instantiated
            Assert.AreEqual("setPropOne=abc", events[1]);              // injected properties

            Assert.IsTrue(events[2] is DataFlowOpInitializateContext); // called initialize
            DataFlowOpInitializateContext initContext = (DataFlowOpInitializateContext)events[2];

            Assert.IsNotNull(initContext.AgentInstanceContext);
            Assert.IsNotNull(initContext.RuntimeEventSender);
            Assert.IsNotNull(initContext.ServicesContext);
            Assert.IsNotNull(initContext.StatementContext);
            Assert.AreEqual("id1", initContext.DataflowInstanceId);
            Assert.AreEqual("myobject", initContext.DataflowInstanceUserObject);
            Assert.AreEqual(0, initContext.InputPorts.Count);
            Assert.AreEqual(1, initContext.OutputPorts.Count);
            Assert.AreEqual("outstream", initContext.OutputPorts[0].StreamName);
            Assert.AreEqual("SupportBean", initContext.OutputPorts[0].OptionalDeclaredType.EventType.Name);
            Assert.AreEqual(2, initContext.OperatorAnnotations.Length);
            Assert.AreEqual("Goodie", ((NameAttribute)initContext.OperatorAnnotations[0]).Value);
            Assert.IsNotNull((AuditAttribute)initContext.OperatorAnnotations[1]);

            // run
            df.Run();

            events = SupportGraphSource.GetAndResetLifecycle();
            Assert.AreEqual(5, events.Count);
            Assert.IsTrue(events[0] is DataFlowOpOpenContext); // called open (GraphSource only)
            Assert.AreEqual("Next(numrows=0)", events[1]);
            Assert.AreEqual("Next(numrows=1)", events[2]);
            Assert.AreEqual("Next(numrows=2)", events[3]);
            Assert.IsTrue(events[4] is DataFlowOpCloseContext); // called close (GraphSource only)

            epService.EPAdministrator.DestroyAllStatements();
        }
Beispiel #9
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext initContext)
        {
            var dataflowContext = initContext.DataflowInstanceUserObject as DataflowContext;
            var log             = dataflowContext.Resolve <ILogger>();

            var port = ChoosePort(Port, new[] { 80, 8080 });

            if (port.HasValue == false)
            {
                log.Error("Unable to bind to port {Port}", Port);
            }

            var tcpListener = new TcpListener(IPAddress.Any, port.Value);

            tcpListener.Start(100);

            log.Information("Port open {Endpoint}", tcpListener.LocalEndpoint.ToString());

            Task.Factory.StartNew(async() =>
            {
                while (true)
                {
                    var tcpClient = await tcpListener.AcceptTcpClientAsync();
                    var stream    = tcpClient.GetStream();

                    var context = new HttpContext()
                    {
                        Connection = tcpClient,
                        Request    = new HttpRequest(stream),
                        Response   = new HttpResponse(stream)
                    };
                    await context.Request.ReadHeadersAsync();

                    log = log.ForContext(new[] {
                        new CorrelationEnricher(context.Correlation.ToString())
                    });
                    context.Properties.Add("Log", log);

                    log.Information("Request Accepted {Correlation}", context.Correlation);
                    log.Verbose("{@Block} {@Request}", this, context.Request);

                    Emitter.Submit(context);
                }
            });

            var httpContext = initContext.ServicesContext.EventAdapterService.GetEventTypeByName("HttpContext");

            return(new DataFlowOpInitializeResult(new[] { new com.espertech.esper.dataflow.util.GraphTypeDesc(false, false, httpContext) }));
        }
Beispiel #10
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext initContext)
        {
            var dataflowContext = initContext.DataflowInstanceUserObject as DataflowContext;
            var log = dataflowContext.Resolve<ILogger>();

            var port = ChoosePort(Port, new[] { 80, 8080 });

            if(port.HasValue == false)
            {
                log.Error("Unable to bind to port {Port}", Port);
            }

            var tcpListener = new TcpListener(IPAddress.Any, port.Value);
            tcpListener.Start(100);

            log.Information("Port open {Endpoint}", tcpListener.LocalEndpoint.ToString());

            Task.Factory.StartNew(async () =>
            {
                while (true)
                {
                    var tcpClient = await tcpListener.AcceptTcpClientAsync();
                    var stream = tcpClient.GetStream();

                    var context = new HttpContext()
                    {
                        Connection = tcpClient,
                        Request = new HttpRequest(stream),
                        Response = new HttpResponse(stream)
                    };
                    await context.Request.ReadHeadersAsync();

                    log = log.ForContext(new[] {
                        new CorrelationEnricher(context.Correlation.ToString())
                        });
                    context.Properties.Add("Log", log);

                    log.Information("Request Accepted {Correlation}", context.Correlation);
                    log.Verbose("{@Block} {@Request}", this, context.Request);

                    Emitter.Submit(context);
                }
            });

            var httpContext = initContext.ServicesContext.EventAdapterService.GetEventTypeByName("HttpContext");
            return new DataFlowOpInitializeResult(new[] { new com.espertech.esper.dataflow.util.GraphTypeDesc(false, false, httpContext) });
        }
        private void RunAssertionFlowGraphOperator(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            epService.EPAdministrator.Configuration.AddImport(typeof(MyLineFeedSource));
            epService.EPAdministrator.Configuration.AddImport(typeof(SupportOperator));
            SupportGraphSource.GetAndResetLifecycle();

            epService.EPAdministrator.CreateEPL("create dataflow MyDataFlow MyLineFeedSource -> outstream {} SupportOperator(outstream) {propOne:'abc'}");
            Assert.AreEqual(0, SupportOperator.GetAndResetLifecycle().Count);

            // instantiate
            var src               = new MyLineFeedSource(Collections.List("abc", "def").GetEnumerator());
            var options           = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(src));
            EPDataFlowInstance df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlow", options);

            IList <object> events = SupportOperator.GetAndResetLifecycle();

            Assert.AreEqual(3, events.Count);
            Assert.AreEqual("instantiated", events[0]);                // instantiated
            Assert.AreEqual("setPropOne=abc", events[1]);              // injected properties

            Assert.IsTrue(events[2] is DataFlowOpInitializateContext); // called initialize
            DataFlowOpInitializateContext initContext = (DataFlowOpInitializateContext)events[2];

            Assert.IsNotNull(initContext.AgentInstanceContext);
            Assert.IsNotNull(initContext.RuntimeEventSender);
            Assert.IsNotNull(initContext.ServicesContext);
            Assert.IsNotNull(initContext.StatementContext);
            Assert.IsNull(initContext.DataflowInstanceId);
            Assert.IsNull(initContext.DataflowInstanceUserObject);
            Assert.AreEqual(1, initContext.InputPorts.Count);
            Assert.AreEqual("[line]", CompatExtensions.Render(initContext.InputPorts[0].TypeDesc.EventType.PropertyNames));
            Assert.AreEqual("[outstream]", CompatExtensions.Render(initContext.InputPorts[0].StreamNames.ToArray()));
            Assert.AreEqual(0, initContext.OutputPorts.Count);

            // run
            df.Run();

            events = SupportOperator.GetAndResetLifecycle();
            Assert.AreEqual(4, events.Count);
            Assert.IsTrue(events[0] is DataFlowOpOpenContext); // called open (GraphSource only)
            Assert.AreEqual("abc", ((object[])events[1])[0]);
            Assert.AreEqual("def", ((object[])events[2])[0]);
            Assert.IsTrue(events[3] is DataFlowOpCloseContext); // called close (GraphSource only)

            epService.EPAdministrator.DestroyAllStatements();
        }
Beispiel #12
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext context)
        {
            if (!context.OutputPorts.IsEmpty())
            {
                throw new ArgumentException("LogSink operator does not provide an output stream");
            }

            _dataflowName       = context.DataflowName;
            _dataFlowInstanceId = context.DataflowInstanceId;

            _shellPerStream = new EventBeanSPI[context.InputPorts.Count];
            foreach (KeyValuePair <int, DataFlowOpInputPort> entry in context.InputPorts)
            {
                EventType eventType = entry.Value.TypeDesc.EventType;
                if (eventType != null)
                {
                    _shellPerStream[entry.Key] = context.StatementContext.EventAdapterService.GetShellForType(eventType);
                }
            }

            if (format == null)
            {
                _renderer = new ConsoleOpRendererSummary();
            }
            else
            {
                try
                {
                    var formatEnum = EnumHelper.Parse <LogSinkOutputFormat>(format.Trim());
                    if (formatEnum == LogSinkOutputFormat.summary)
                    {
                        _renderer = new ConsoleOpRendererSummary();
                    }
                    else
                    {
                        _renderer = new ConsoleOpRendererXmlJSon(formatEnum, context.Engine.EPRuntime);
                    }
                }
                catch (Exception ex)
                {
                    throw new ExprValidationException("Format '" + format + "' is not supported, expecting any of " + EnumHelper.GetValues <LogSinkOutputFormat>().Render());
                }
            }

            return(null);
        }
Beispiel #13
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext context)
        {
            if (context.OutputPorts.Count != 1)
            {
                throw new ArgumentException("EventBusSource operator requires one output stream but produces " + context.OutputPorts.Count + " streams");
            }

            DataFlowOpOutputPort portZero = context.OutputPorts[0];

            if (portZero.OptionalDeclaredType == null || portZero.OptionalDeclaredType.EventType == null)
            {
                throw new ArgumentException("EventBusSource operator requires an event type declated for the output stream");
            }

            if (!portZero.OptionalDeclaredType.IsUnderlying)
            {
                submitEventBean = true;
            }
            eventType            = portZero.OptionalDeclaredType.EventType;
            agentInstanceContext = context.AgentInstanceContext;

            return(new DataFlowOpInitializeResult());
        }
Beispiel #14
0
 public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext context)
 {
     return(null);
 }
Beispiel #15
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext initContext)
        {
            var httpContext = initContext.ServicesContext.EventAdapterService.GetEventTypeByName("HttpContext");

            return(new DataFlowOpInitializeResult(new[] { new com.espertech.esper.dataflow.util.GraphTypeDesc(false, false, httpContext) }));
        }
Beispiel #16
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext context)
        {
            _initialDelayMSec = (long)(initialDelay * 1000);
            _periodDelayMSec  = (long)(interval * 1000);

            if (context.OutputPorts.Count != 1)
            {
                throw new ArgumentException(
                          "BeaconSource operator requires one output stream but produces " + context.OutputPorts.Count +
                          " streams");
            }

            // Check if a type is declared
            var port = context.OutputPorts[0];
            ICollection <string> props;

            if (port.OptionalDeclaredType != null && port.OptionalDeclaredType.EventType != null)
            {
                var outputEventType = port.OptionalDeclaredType.EventType;
                _produceEventBean = port.OptionalDeclaredType != null && !port.OptionalDeclaredType.IsUnderlying;

                // compile properties to populate
                props = _allProperties.Keys;
                props.RemoveAll(PARAMETER_PROPERTIES);
                var writables = SetupProperties(props.ToArray(), outputEventType, context.StatementContext);
                _manufacturer = context.ServicesContext.EventAdapterService.GetManufacturer(
                    outputEventType, writables, context.ServicesContext.EngineImportService, false);

                var index = 0;
                _evaluators = new ExprEvaluator[writables.Length];
                TypeWidenerCustomizer typeWidenerCustomizer =
                    context.ServicesContext.EventAdapterService.GetTypeWidenerCustomizer(outputEventType);
                foreach (var writeable in writables)
                {
                    var providedProperty = _allProperties.Get(writeable.PropertyName);
                    if (providedProperty is ExprNode)
                    {
                        var exprNode  = (ExprNode)providedProperty;
                        var validated = ExprNodeUtility.ValidateSimpleGetSubtree(
                            ExprNodeOrigin.DATAFLOWBEACON, exprNode, context.StatementContext, null, false);
                        var exprEvaluator = validated.ExprEvaluator;
                        var widener       = TypeWidenerFactory.GetCheckPropertyAssignType(
                            ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(validated), exprEvaluator.ReturnType,
                            writeable.PropertyType, writeable.PropertyName, false, typeWidenerCustomizer,
                            context.StatementContext.StatementName, context.Engine.URI);
                        if (widener != null)
                        {
                            _evaluators[index] = new ProxyExprEvaluator
                            {
                                ProcEvaluate = evaluateParams =>
                                {
                                    var value = exprEvaluator.Evaluate(evaluateParams);
                                    return(widener.Invoke(value));
                                },
                                ProcReturnType = () => null
                            };
                        }
                        else
                        {
                            _evaluators[index] = exprEvaluator;
                        }
                    }
                    else if (providedProperty == null)
                    {
                        _evaluators[index] = new ProxyExprEvaluator
                        {
                            ProcEvaluate   = evaluateParams => null,
                            ProcReturnType = () => null
                        };
                    }
                    else
                    {
                        _evaluators[index] = new ProxyExprEvaluator
                        {
                            ProcEvaluate   = evaluateParams => providedProperty,
                            ProcReturnType = () => providedProperty.GetType()
                        };
                    }
                    index++;
                }

                return(null); // no changing types
            }

            // No type has been declared, we can create one
            var anonymousTypeName = context.DataflowName + "-beacon";
            var types             = new LinkedHashMap <string, Object>();

            props = _allProperties.Keys;
            props.RemoveAll(PARAMETER_PROPERTIES);

            var count = 0;

            _evaluators = new ExprEvaluator[props.Count];
            foreach (var propertyName in props)
            {
                var exprNode        = (ExprNode)_allProperties.Get(propertyName);
                var validated       = ExprNodeUtility.ValidateSimpleGetSubtree(ExprNodeOrigin.DATAFLOWBEACON, exprNode, context.StatementContext, null, false);
                var evaluateParamsX = new EvaluateParams(null, true, context.AgentInstanceContext);
                var value           = validated.ExprEvaluator.Evaluate(evaluateParamsX);
                if (value == null)
                {
                    types.Put(propertyName, null);
                }
                else
                {
                    types.Put(propertyName, value.GetType());
                }
                _evaluators[count] = new ProxyExprEvaluator()
                {
                    ProcEvaluate   = (evaluateParams) => value,
                    ProcReturnType = () => null
                };
                count++;
            }

            EventType type =
                context.ServicesContext.EventAdapterService.CreateAnonymousObjectArrayType(anonymousTypeName, types);

            return(new DataFlowOpInitializeResult(
                       new GraphTypeDesc[]
            {
                new GraphTypeDesc(false, true, type)
            }));
        }
Beispiel #17
0
        public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext context)
        {
            if (context.InputPorts.IsEmpty())
            {
                throw new ArgumentException("Select operator requires at least one input stream");
            }
            if (context.OutputPorts.Count != 1)
            {
                throw new ArgumentException("Select operator requires one output stream but produces " + context.OutputPorts.Count + " streams");
            }

            DataFlowOpOutputPort portZero = context.OutputPorts[0];

            if (portZero.OptionalDeclaredType != null && !portZero.OptionalDeclaredType.IsUnderlying)
            {
                _submitEventBean = true;
            }

            // determine adapter factories for each type
            int numStreams = context.InputPorts.Count;

            _adapterFactories = new EventBeanAdapterFactory[numStreams];
            for (int i = 0; i < numStreams; i++)
            {
                EventType eventType = context.InputPorts.Get(i).TypeDesc.EventType;
                _adapterFactories[i] = context.StatementContext.EventAdapterService.GetAdapterFactoryForType(eventType);
            }

            // Compile and prepare execution
            //
            StatementContext     statementContext     = context.StatementContext;
            EPServicesContext    servicesContext      = context.ServicesContext;
            AgentInstanceContext agentInstanceContext = context.AgentInstanceContext;

            // validate
            if (select.InsertIntoDesc != null)
            {
                throw new ExprValidationException("Insert-into clause is not supported");
            }
            if (select.SelectStreamSelectorEnum != SelectClauseStreamSelectorEnum.ISTREAM_ONLY)
            {
                throw new ExprValidationException("Selecting remove-stream is not supported");
            }
            ExprNodeSubselectDeclaredDotVisitor visitor            = StatementSpecRawAnalyzer.WalkSubselectAndDeclaredDotExpr(select);
            GroupByClauseExpressions            groupByExpressions = GroupByExpressionHelper.GetGroupByRollupExpressions(
                servicesContext.Container,
                select.GroupByExpressions,
                select.SelectClauseSpec,
                select.HavingExprRootNode,
                select.OrderByList,
                visitor);

            if (!visitor.Subselects.IsEmpty())
            {
                throw new ExprValidationException("Subselects are not supported");
            }

            IDictionary <int, FilterStreamSpecRaw> streams = new Dictionary <int, FilterStreamSpecRaw>();

            for (int streamNum = 0; streamNum < select.StreamSpecs.Count; streamNum++)
            {
                var rawStreamSpec = select.StreamSpecs[streamNum];
                if (!(rawStreamSpec is FilterStreamSpecRaw))
                {
                    throw new ExprValidationException("From-clause must contain only streams and cannot contain patterns or other constructs");
                }
                streams.Put(streamNum, (FilterStreamSpecRaw)rawStreamSpec);
            }

            // compile offered streams
            IList <StreamSpecCompiled> streamSpecCompileds = new List <StreamSpecCompiled>();

            for (int streamNum = 0; streamNum < select.StreamSpecs.Count; streamNum++)
            {
                var filter    = streams.Get(streamNum);
                var inputPort = FindInputPort(filter.RawFilterSpec.EventTypeName, context.InputPorts);
                if (inputPort == null)
                {
                    throw new ExprValidationException(
                              string.Format("Failed to find stream '{0}' among input ports, input ports are {1}", filter.RawFilterSpec.EventTypeName, GetInputPortNames(context.InputPorts).Render(", ", "[]")));
                }
                var eventType                = inputPort.Value.Value.TypeDesc.EventType;
                var streamAlias              = filter.OptionalStreamName;
                var filterSpecCompiled       = new FilterSpecCompiled(eventType, streamAlias, new IList <FilterSpecParam>[] { Collections.GetEmptyList <FilterSpecParam>() }, null);
                var filterStreamSpecCompiled = new FilterStreamSpecCompiled(filterSpecCompiled, select.StreamSpecs[0].ViewSpecs, streamAlias, StreamSpecOptions.DEFAULT);
                streamSpecCompileds.Add(filterStreamSpecCompiled);
            }

            // create compiled statement spec
            SelectClauseSpecCompiled selectClauseCompiled = StatementLifecycleSvcUtil.CompileSelectClause(select.SelectClauseSpec);

            // determine if snapshot output is needed
            OutputLimitSpec outputLimitSpec = select.OutputLimitSpec;

            _isOutputLimited = outputLimitSpec != null;
            if (iterate)
            {
                if (outputLimitSpec != null)
                {
                    throw new ExprValidationException("Output rate limiting is not supported with 'iterate'");
                }
                outputLimitSpec = new OutputLimitSpec(OutputLimitLimitType.SNAPSHOT, OutputLimitRateType.TERM);
            }

            var mergedAnnotations = AnnotationUtil.MergeAnnotations(statementContext.Annotations, context.OperatorAnnotations);
            var orderByArray      = OrderByItem.ToArray(select.OrderByList);
            var outerJoinArray    = OuterJoinDesc.ToArray(select.OuterJoinDescList);
            var streamSpecArray   = streamSpecCompileds.ToArray();
            var compiled          = new StatementSpecCompiled(null, null, null, null, null, null, null, SelectClauseStreamSelectorEnum.ISTREAM_ONLY,
                                                              selectClauseCompiled, streamSpecArray, outerJoinArray, select.FilterExprRootNode, select.HavingExprRootNode, outputLimitSpec,
                                                              orderByArray, ExprSubselectNode.EMPTY_SUBSELECT_ARRAY, ExprNodeUtility.EMPTY_DECLARED_ARR, ExprNodeUtility.EMPTY_SCRIPTS, select.ReferencedVariables,
                                                              select.RowLimitSpec, CollectionUtil.EMPTY_STRING_ARRAY, mergedAnnotations, null, null, null, null, null, null, null, null, null, groupByExpressions, null, null);

            // create viewable per port
            var viewables = new EPLSelectViewable[context.InputPorts.Count];

            _viewablesPerPort = viewables;
            foreach (var entry in context.InputPorts)
            {
                EPLSelectViewable viewable = new EPLSelectViewable(entry.Value.TypeDesc.EventType);
                viewables[entry.Key] = viewable;
            }

            var activatorFactory = new ProxyViewableActivatorFactory
            {
                ProcCreateActivatorSimple = filterStreamSpec =>
                {
                    EPLSelectViewable found = null;
                    foreach (EPLSelectViewable sviewable in viewables)
                    {
                        if (sviewable.EventType == filterStreamSpec.FilterSpec.FilterForEventType)
                        {
                            found = sviewable;
                        }
                    }
                    if (found == null)
                    {
                        throw new IllegalStateException("Failed to find viewable for filter");
                    }
                    EPLSelectViewable viewable = found;
                    return(new ProxyViewableActivator(
                               (agentInstanceContext2, isSubselect, isRecoveringResilient) =>
                               new ViewableActivationResult(
                                   viewable,
                                   new ProxyStopCallback(() => { }),
                                   null,
                                   null,
                                   null,
                                   false,
                                   false,
                                   null)));
                }
            };

            // for per-row deliver, register select expression result callback
            OutputProcessViewCallback optionalOutputProcessViewCallback = null;

            if (!iterate && !_isOutputLimited)
            {
                _deliveryCallback = new EPLSelectDeliveryCallback();
                optionalOutputProcessViewCallback = this;
            }

            // prepare
            EPStatementStartMethodSelectDesc selectDesc = EPStatementStartMethodSelectUtil.Prepare(compiled, servicesContext, statementContext, false, agentInstanceContext, false, activatorFactory, optionalOutputProcessViewCallback, _deliveryCallback);

            // start
            _selectResult = (StatementAgentInstanceFactorySelectResult)selectDesc.StatementAgentInstanceFactorySelect.NewContext(agentInstanceContext, false);

            // for output-rate-limited, register a dispatch view
            if (_isOutputLimited)
            {
                _selectResult.FinalView.AddView(new EPLSelectUpdateDispatchView(this));
            }

            // assign strategies to expression nodes
            EPStatementStartMethodHelperAssignExpr.AssignExpressionStrategies(
                selectDesc,
                _selectResult.OptionalAggegationService,
                _selectResult.SubselectStrategies,
                _selectResult.PriorNodeStrategies,
                _selectResult.PreviousNodeStrategies,
                null,
                null,
                _selectResult.TableAccessEvalStrategies);

            EventType outputEventType = selectDesc.ResultSetProcessorPrototypeDesc.ResultSetProcessorFactory.ResultEventType;

            _agentInstanceContext = agentInstanceContext;
            return(new DataFlowOpInitializeResult(new GraphTypeDesc[] { new GraphTypeDesc(false, true, outputEventType) }));
        }
Beispiel #18
0
 public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext initContext)
 {
     return null;
 }
Beispiel #19
0
 public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext context)
 {
     Port = context.OutputPorts[0];
     return(null);
 }
Beispiel #20
0
 public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext context)
 {
     _lifecycle.Add(context);
     return(null);
 }
Beispiel #21
0
 public DataFlowOpInitializeResult Initialize(DataFlowOpInitializateContext initContext)
 {
     var httpContext = initContext.ServicesContext.EventAdapterService.GetEventTypeByName("HttpContext");
     return new DataFlowOpInitializeResult(new[] { new com.espertech.esper.dataflow.util.GraphTypeDesc(false, false, httpContext) });
 }