public EventBean Process(EventBean[] eventsPerStream, bool isNewData, bool isSynthesize, ExprEvaluatorContext exprEvaluatorContext)
            {
                ObjectArrayBackedEventBean theEvent = (ObjectArrayBackedEventBean)eventsPerStream[_underlyingStreamNumber];

                Object[] props = new Object[_items.Length];
                foreach (Item item in _items)
                {
                    Object value;

                    if (item.OptionalFromIndex != -1)
                    {
                        value = theEvent.Properties[item.OptionalFromIndex];
                    }
                    else
                    {
                        value = item.Evaluator.Evaluate(new EvaluateParams(eventsPerStream, isNewData, exprEvaluatorContext));
                        if (item.OptionalWidener != null)
                        {
                            value = item.OptionalWidener.Invoke(value);
                        }
                    }

                    props[item.ToIndex] = value;
                }

                return(_manufacturer.Make(props));
            }
Exemplo n.º 2
0
        protected void ApplyEnterTableKey(
            EventBean[] eventsPerStream,
            Object tableKey,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            ObjectArrayBackedEventBean bean = tableInstance.GetCreateRowIntoTable(tableKey, exprEvaluatorContext);
            currentAggregationRow = (AggregationRow) bean.Properties[0];

            InstrumentationCommon instrumentationCommon = exprEvaluatorContext.InstrumentationProvider;
            instrumentationCommon.QAggregationGroupedApplyEnterLeave(true, methodPairs.Length, accessAgents.Length, tableKey);

            for (int i = 0; i < methodPairs.Length; i++) {
                TableColumnMethodPairEval methodPair = methodPairs[i];
                instrumentationCommon.QAggNoAccessEnterLeave(true, i, null, null);
                Object columnResult = methodPair.Evaluator.Evaluate(eventsPerStream, true, exprEvaluatorContext);
                currentAggregationRow.EnterAgg(methodPair.Column, columnResult);
                instrumentationCommon.AAggNoAccessEnterLeave(true, i, null);
            }

            for (int i = 0; i < accessAgents.Length; i++) {
                instrumentationCommon.QAggAccessEnterLeave(true, i, null);
                accessAgents[i].ApplyEnter(eventsPerStream, exprEvaluatorContext, currentAggregationRow, accessColumnsZeroOffset[i]);
                instrumentationCommon.AAggAccessEnterLeave(true, i);
            }

            tableInstance.HandleRowUpdated(bean);

            instrumentationCommon.AAggregationGroupedApplyEnterLeave(true);
        }
Exemplo n.º 3
0
        internal static object[] EvalTypable(ObjectArrayBackedEventBean @event,
                                             AggregationRowPair row,
                                             IDictionary <String, TableMetadataColumn> items,
                                             EventBean[] eventsPerStream,
                                             bool isNewData,
                                             ExprEvaluatorContext exprEvaluatorContext)
        {
            var values = new object[items.Count];
            var count  = 0;

            foreach (var entry in items)
            {
                if (entry.Value is TableMetadataColumnPlain)
                {
                    var plain = (TableMetadataColumnPlain)entry.Value;
                    values[count] = @event.Properties[plain.IndexPlain];
                }
                else
                {
                    var aggcol = (TableMetadataColumnAggregation)entry.Value;
                    if (!aggcol.Factory.IsAccessAggregation)
                    {
                        values[count] = row.Methods[aggcol.MethodOffset].Value;
                    }
                    else
                    {
                        var pair = aggcol.AccessAccessorSlotPair;
                        values[count] = pair.Accessor.GetValue(row.States[pair.Slot], eventsPerStream, isNewData, exprEvaluatorContext);
                    }
                }
                count++;
            }
            return(values);
        }
Exemplo n.º 4
0
        internal static IDictionary <String, object> EvalMap(ObjectArrayBackedEventBean @event, AggregationRowPair row, IDictionary <String, TableMetadataColumn> items, EventBean[] eventsPerStream, bool isNewData, ExprEvaluatorContext exprEvaluatorContext)
        {
            var cols = new Dictionary <string, object>();

            foreach (var entry in items)
            {
                if (entry.Value is TableMetadataColumnPlain)
                {
                    var plain = (TableMetadataColumnPlain)entry.Value;
                    cols.Put(entry.Key, @event.Properties[plain.IndexPlain]);
                }
                else
                {
                    var aggcol = (TableMetadataColumnAggregation)entry.Value;
                    if (!aggcol.Factory.IsAccessAggregation)
                    {
                        cols.Put(entry.Key, row.Methods[aggcol.MethodOffset].Value);
                    }
                    else
                    {
                        var pair  = aggcol.AccessAccessorSlotPair;
                        var value = pair.Accessor.GetValue(row.States[pair.Slot], eventsPerStream, isNewData, exprEvaluatorContext);
                        cols.Put(entry.Key, value);
                    }
                }
            }
            return(cols);
        }
Exemplo n.º 5
0
        protected internal static object[] EvalTypable(
            ObjectArrayBackedEventBean @event,
            AggregationRow row,
            IDictionary<string, TableMetadataColumn> items,
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            object[] values = new object[items.Count];
            int count = 0;
            foreach (KeyValuePair<string, TableMetadataColumn> entry in items) {
                if (entry.Value is TableMetadataColumnPlain) {
                    TableMetadataColumnPlain plain = (TableMetadataColumnPlain) entry.Value;
                    values[count] = @event.Properties[plain.IndexPlain];
                }
                else {
                    TableMetadataColumnAggregation aggcol = (TableMetadataColumnAggregation) entry.Value;
                    values[count] = row.GetValue(aggcol.Column, eventsPerStream, isNewData, exprEvaluatorContext);
                }

                count++;
            }

            return values;
        }
Exemplo n.º 6
0
 public void HandleRowUpdated(ObjectArrayBackedEventBean row)
 {
     if (InstrumentationHelper.ENABLED)
     {
         InstrumentationHelper.Get().QaTableUpdatedEvent(row);
     }
 }
Exemplo n.º 7
0
        protected ObjectArrayBackedEventBean CreateRowIntoTable(object groupKeys)
        {
            EventType eventType = table.MetaData.InternalEventType;
            AggregationRow aggregationRow = table.AggregationRowFactory.Make();
            var data = new object[eventType.PropertyDescriptors.Count];
            data[0] = aggregationRow;

            int[] groupKeyColNums = table.MetaData.KeyColNums;
            if (groupKeyColNums.Length == 1) {
                if (groupKeys is MultiKeyArrayWrap multiKeyArrayWrap) {
                    data[groupKeyColNums[0]] = multiKeyArrayWrap.Array;
                } else {
                    data[groupKeyColNums[0]] = groupKeys;
                }
            }
            else {
                var mk = (MultiKey) groupKeys;
                for (var i = 0; i < groupKeyColNums.Length; i++) {
                    data[groupKeyColNums[i]] = mk.GetKey(i);
                }
            }

            ObjectArrayBackedEventBean row =
                agentInstanceContext.EventBeanTypedEventFactory.AdapterForTypedObjectArray(data, eventType);
            AddEvent(row);
            return row;
        }
Exemplo n.º 8
0
 public override void HandleRowUpdated(ObjectArrayBackedEventBean updatedEvent)
 {
     // no action
     if (agentInstanceContext.InstrumentationProvider.Activated()) {
         agentInstanceContext.InstrumentationProvider.QTableUpdatedEvent(updatedEvent);
         agentInstanceContext.InstrumentationProvider.ATableUpdatedEvent();
     }
 }
Exemplo n.º 9
0
 public virtual void HandleRowUpdateKeyAfterUpdate(ObjectArrayBackedEventBean updatedEvent)
 {
     if (InstrumentationHelper.ENABLED)
     {
         InstrumentationHelper.Get().QaTableUpdatedEventWKeyAfter(updatedEvent);
     }
     // no action
 }
Exemplo n.º 10
0
        public void AddEventUnadorned(EventBean @event)
        {
            ObjectArrayBackedEventBean oa   = (ObjectArrayBackedEventBean)@event;
            AggregationRowPair         aggs = _tableMetadata.RowFactory.MakeAggs(_agentInstanceContext.AgentInstanceId, null, null, AggregationServicePassThru);

            oa.Properties[0] = aggs;
            AddEvent(oa);
        }
Exemplo n.º 11
0
        public object Evaluate(EventBean[] eventsPerStream, bool isNewData, ExprEvaluatorContext context)
        {
            ObjectArrayBackedEventBean @event = LockTableReadAndGet(context);

            if (@event == null)
            {
                return(null);
            }
            AggregationState aggregationState = GetAndLock(@event, context);

            return(_accessor.GetValue(aggregationState, eventsPerStream, isNewData, context));
        }
Exemplo n.º 12
0
        public ICollection <object> EvaluateGetROCollectionScalar(EventBean[] eventsPerStream, bool isNewData, ExprEvaluatorContext context)
        {
            ObjectArrayBackedEventBean @event = LockTableReadAndGet(context);

            if (@event == null)
            {
                return(null);
            }
            AggregationState aggregationState = GetAndLock(@event, context);

            return(_accessor.GetEnumerableScalar(aggregationState, eventsPerStream, isNewData, context));
        }
        public EventBean EvaluateGetEventBean(EventBean[] eventsPerStream, bool isNewData, ExprEvaluatorContext context)
        {
            ObjectArrayBackedEventBean @event = LockTableReadAndGet(context);

            if (@event == null)
            {
                return(null);
            }
            AggregationState aggregationState = GetAndLock(@event, context);

            return(_accessor.GetEnumerableEvent(aggregationState, new EvaluateParams(eventsPerStream, isNewData, context)));
        }
Exemplo n.º 14
0
        public AggregationRow GetAggregationRow(
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext context)
        {
            ObjectArrayBackedEventBean row = LockTableReadAndGet(context);
            if (row == null) {
                return null;
            }

            return ExprTableEvalStrategyUtil.GetRow(row);
        }
Exemplo n.º 15
0
        public override ICollection<EventBean> EvaluateGetROCollectionEvents(
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext context)
        {
            ObjectArrayBackedEventBean row = LockTableReadAndGet(context);
            if (row == null) {
                return null;
            }

            AggregationRow aggs = ExprTableEvalStrategyUtil.GetRow(row);
            return aggs.GetCollectionOfEvents(Factory.AggColumnNum, eventsPerStream, isNewData, context);
        }
Exemplo n.º 16
0
        public override object Evaluate(
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            ObjectArrayBackedEventBean row = LockTableReadAndGet(exprEvaluatorContext);
            if (row == null) {
                return null;
            }

            AggregationRow aggs = ExprTableEvalStrategyUtil.GetRow(row);
            return aggs.GetValue(Factory.AggColumnNum, eventsPerStream, isNewData, exprEvaluatorContext);
        }
        public override object[] EvaluateTypableSingle(
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext context)
        {
            ObjectArrayBackedEventBean @event = LockTableReadAndGet(context);
            if (@event == null) {
                return null;
            }

            AggregationRow row = ExprTableEvalStrategyUtil.GetRow(@event);
            IDictionary<string, TableMetadataColumn> items = Factory.Table.MetaData.Columns;
            return ExprTableEvalStrategyUtil.EvalTypable(@event, row, items, eventsPerStream, isNewData, context);
        }
        public override object Evaluate(
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext context)
        {
            ObjectArrayBackedEventBean @event = LockTableReadAndGet(context);
            if (@event == null) {
                return null;
            }

            AggregationRow row = ExprTableEvalStrategyUtil.GetRow(@event);
            return ExprTableEvalStrategyUtil.EvalMap(
                @event,
                row,
                Factory.Table.MetaData.Columns,
                eventsPerStream,
                isNewData,
                context);
        }
Exemplo n.º 19
0
        protected internal static IDictionary<string, object> EvalMap(
            ObjectArrayBackedEventBean @event,
            AggregationRow row,
            IDictionary<string, TableMetadataColumn> items,
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            Dictionary<string, object> cols = new Dictionary<string, object>();
            foreach (KeyValuePair<string, TableMetadataColumn> entry in items) {
                if (entry.Value is TableMetadataColumnPlain) {
                    TableMetadataColumnPlain plain = (TableMetadataColumnPlain) entry.Value;
                    cols.Put(entry.Key, @event.Properties[plain.IndexPlain]);
                }
                else {
                    TableMetadataColumnAggregation aggcol = (TableMetadataColumnAggregation) entry.Value;
                    cols.Put(entry.Key, row.GetValue(aggcol.Column, eventsPerStream, isNewData, exprEvaluatorContext));
                }
            }

            return cols;
        }
Exemplo n.º 20
0
        public void UpdateTable(
            ICollection<EventBean> eventsUnsafeIter,
            TableInstance instance,
            EventBean[] eventsPerStream,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            // update (no-copy unless original values required)
            foreach (EventBean @event in eventsUnsafeIter) {
                eventsPerStream[0] = @event;
                ObjectArrayBackedEventBean updatedEvent = (ObjectArrayBackedEventBean) @event;

                // if "initial.property" is part of the assignment expressions, provide initial value event
                if (updateHelper.IsRequiresStream2InitialValueEvent) {
                    object[] prev = new object[updatedEvent.Properties.Length];
                    Array.Copy(updatedEvent.Properties, 0, prev, 0, prev.Length);
                    eventsPerStream[2] = new ObjectArrayEventBean(prev, updatedEvent.EventType);
                }

                // apply in-place updates
                updateHelper.UpdateNoCopy(updatedEvent, eventsPerStream, exprEvaluatorContext);
                instance.HandleRowUpdated(updatedEvent);
            }
        }
Exemplo n.º 21
0
 public abstract void HandleRowUpdateKeyAfterUpdate(ObjectArrayBackedEventBean updatedEvent);
Exemplo n.º 22
0
 public static AggregationRow GetRow(ObjectArrayBackedEventBean eventBean)
 {
     return GetRow(eventBean.Properties);
 }
Exemplo n.º 23
0
 public static AggregationRowPair GetRow(ObjectArrayBackedEventBean eventBean)
 {
     return((AggregationRowPair)eventBean.Properties[0]);
 }
Exemplo n.º 24
0
        private AggregationState GetAndLock(ObjectArrayBackedEventBean @event, ExprEvaluatorContext exprEvaluatorContext)
        {
            AggregationRowPair row = ExprTableEvalStrategyUtil.GetRow(@event);

            return(row.States[_slot]);
        }
Exemplo n.º 25
0
 public override void HandleRowUpdateKeyAfterUpdate(ObjectArrayBackedEventBean updatedEvent)
 {
 }
Exemplo n.º 26
0
 public override void HandleRowUpdateKeyAfterUpdate(ObjectArrayBackedEventBean updatedEvent)
 {
     agentInstanceContext.InstrumentationProvider.QaTableUpdatedEventWKeyAfter(updatedEvent);
 }
Exemplo n.º 27
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="viewChain">views</param>
        /// <param name="matchRecognizeSpec">specification</param>
        /// <param name="agentInstanceContext">The agent instance context.</param>
        /// <param name="isUnbound">true for unbound stream</param>
        /// <param name="annotations">annotations</param>
        /// <exception cref="ExprValidationException">
        /// Variable ' + defineItem.Identifier + ' has already been defined
        /// or
        /// An aggregate function may not appear in a DEFINE clause
        /// or
        /// Failed to validate condition expression for variable ' + defineItem.Identifier + ':  + ex.Message
        /// or
        /// Aggregation functions in the measure-clause must only refer to properties of exactly one group variable returning multiple events
        /// or
        /// Aggregation functions in the measure-clause must refer to one or more properties of exactly one group variable returning multiple events
        /// or
        /// The measures clause requires that each expression utilizes the AS keyword to assign a column name
        /// </exception>
        /// <throws>ExprValidationException if validation fails</throws>
        public EventRowRegexNFAViewFactory(
            ViewFactoryChain viewChain,
            MatchRecognizeSpec matchRecognizeSpec,
            AgentInstanceContext agentInstanceContext,
            bool isUnbound,
            Attribute[] annotations,
            ConfigurationEngineDefaults.MatchRecognizeConfig matchRecognizeConfig)
        {
            var parentViewType = viewChain.EventType;

            _matchRecognizeSpec   = matchRecognizeSpec;
            _isUnbound            = isUnbound;
            _isIterateOnly        = HintEnum.ITERATE_ONLY.GetHint(annotations) != null;
            _matchRecognizeConfig = matchRecognizeConfig;

            var statementContext = agentInstanceContext.StatementContext;

            // Expand repeats and permutations
            _expandedPatternNode = RegexPatternExpandUtil.Expand(matchRecognizeSpec.Pattern);

            // Determine single-row and multiple-row variables
            _variablesSingle = new LinkedHashSet <string>();
            ISet <string> variablesMultiple = new LinkedHashSet <string>();

            EventRowRegexHelper.RecursiveInspectVariables(_expandedPatternNode, false, _variablesSingle, variablesMultiple);

            // each variable gets associated with a stream number (multiple-row variables as well to hold the current event for the expression).
            var streamNum = 0;

            _variableStreams = new LinkedHashMap <string, Pair <int, bool> >();
            foreach (var variableSingle in _variablesSingle)
            {
                _variableStreams.Put(variableSingle, new Pair <int, bool>(streamNum, false));
                streamNum++;
            }
            foreach (var variableMultiple in variablesMultiple)
            {
                _variableStreams.Put(variableMultiple, new Pair <int, bool>(streamNum, true));
                streamNum++;
            }

            // mapping of stream to variable
            _streamVariables = new SortedDictionary <int, string>();
            foreach (var entry in _variableStreams)
            {
                _streamVariables.Put(entry.Value.First, entry.Key);
            }

            // determine visibility rules
            var visibility = EventRowRegexHelper.DetermineVisibility(_expandedPatternNode);

            // assemble all single-row variables for expression validation
            var allStreamNames = new string[_variableStreams.Count];
            var allTypes       = new EventType[_variableStreams.Count];

            streamNum = 0;
            foreach (var variableSingle in _variablesSingle)
            {
                allStreamNames[streamNum] = variableSingle;
                allTypes[streamNum]       = parentViewType;
                streamNum++;
            }
            foreach (var variableMultiple in variablesMultiple)
            {
                allStreamNames[streamNum] = variableMultiple;
                allTypes[streamNum]       = parentViewType;
                streamNum++;
            }

            // determine type service for use with DEFINE
            // validate each DEFINE clause expression
            ISet <string>             definedVariables = new HashSet <string>();
            IList <ExprAggregateNode> aggregateNodes   = new List <ExprAggregateNode>();
            var exprEvaluatorContext = new ExprEvaluatorContextStatement(statementContext, false);

            _isExprRequiresMultimatchState = new bool[_variableStreams.Count];

            for (var defineIndex = 0; defineIndex < matchRecognizeSpec.Defines.Count; defineIndex++)
            {
                var defineItem = matchRecognizeSpec.Defines[defineIndex];
                if (definedVariables.Contains(defineItem.Identifier))
                {
                    throw new ExprValidationException("Variable '" + defineItem.Identifier + "' has already been defined");
                }
                definedVariables.Add(defineItem.Identifier);

                // stream-type visibilities handled here
                var typeServiceDefines = EventRowRegexNFAViewFactoryHelper.BuildDefineStreamTypeServiceDefine(statementContext, _variableStreams, defineItem, visibility, parentViewType);

                var exprNodeResult    = HandlePreviousFunctions(defineItem.Expression);
                var validationContext = new ExprValidationContext(
                    typeServiceDefines,
                    statementContext.EngineImportService,
                    statementContext.StatementExtensionServicesContext, null,
                    statementContext.SchedulingService,
                    statementContext.VariableService,
                    statementContext.TableService, exprEvaluatorContext,
                    statementContext.EventAdapterService,
                    statementContext.StatementName,
                    statementContext.StatementId,
                    statementContext.Annotations,
                    statementContext.ContextDescriptor,
                    statementContext.ScriptingService,
                    true, false, true, false, null, false);

                ExprNode validated;
                try {
                    // validate
                    validated = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.MATCHRECOGDEFINE, exprNodeResult, validationContext);

                    // check aggregates
                    defineItem.Expression = validated;
                    ExprAggregateNodeUtil.GetAggregatesBottomUp(validated, aggregateNodes);
                    if (!aggregateNodes.IsEmpty())
                    {
                        throw new ExprValidationException("An aggregate function may not appear in a DEFINE clause");
                    }
                }
                catch (ExprValidationException ex) {
                    throw new ExprValidationException("Failed to validate condition expression for variable '" + defineItem.Identifier + "': " + ex.Message, ex);
                }

                // determine access to event properties from multi-matches
                var visitor = new ExprNodeStreamRequiredVisitor();
                validated.Accept(visitor);
                var streamsRequired = visitor.StreamsRequired;
                foreach (var streamRequired in streamsRequired)
                {
                    if (streamRequired >= _variableStreams.Count)
                    {
                        var streamNumIdent = _variableStreams.Get(defineItem.Identifier).First;
                        _isExprRequiresMultimatchState[streamNumIdent] = true;
                        break;
                    }
                }
            }
            _isDefineAsksMultimatches  = CollectionUtil.IsAnySet(_isExprRequiresMultimatchState);
            _defineMultimatchEventBean = _isDefineAsksMultimatches ? EventRowRegexNFAViewFactoryHelper.GetDefineMultimatchBean(statementContext, _variableStreams, parentViewType) : null;

            // assign "prev" node indexes
            // Since an expression such as "prior(2, price), prior(8, price)" translates into {2, 8} the relative index is {0, 1}.
            // Map the expression-supplied index to a relative index
            var countPrev = 0;

            foreach (var entry in _callbacksPerIndex)
            {
                foreach (var callback in entry.Value)
                {
                    callback.AssignedIndex = countPrev;
                }
                countPrev++;
            }

            // determine type service for use with MEASURE
            IDictionary <string, object> measureTypeDef = new LinkedHashMap <string, object>();

            foreach (var variableSingle in _variablesSingle)
            {
                measureTypeDef.Put(variableSingle, parentViewType);
            }
            foreach (var variableMultiple in variablesMultiple)
            {
                measureTypeDef.Put(variableMultiple, new EventType[] { parentViewType });
            }
            var outputEventTypeName = statementContext.StatementId + "_rowrecog";

            _compositeEventType = (ObjectArrayEventType)statementContext.EventAdapterService.CreateAnonymousObjectArrayType(outputEventTypeName, measureTypeDef);
            StreamTypeService typeServiceMeasure = new StreamTypeServiceImpl(_compositeEventType, "MATCH_RECOGNIZE", true, statementContext.EngineURI);

            // find MEASURE clause aggregations
            var measureReferencesMultivar = false;
            IList <ExprAggregateNode> measureAggregateExprNodes = new List <ExprAggregateNode>();

            foreach (var measureItem in matchRecognizeSpec.Measures)
            {
                ExprAggregateNodeUtil.GetAggregatesBottomUp(measureItem.Expr, measureAggregateExprNodes);
            }
            if (!measureAggregateExprNodes.IsEmpty())
            {
                var isIStreamOnly = new bool[allStreamNames.Length];
                CompatExtensions.Fill(isIStreamOnly, true);
                var typeServiceAggregateMeasure  = new StreamTypeServiceImpl(allTypes, allStreamNames, isIStreamOnly, statementContext.EngineURI, false);
                var measureExprAggNodesPerStream = new Dictionary <int, IList <ExprAggregateNode> >();

                foreach (var aggregateNode in measureAggregateExprNodes)
                {
                    // validate absence of group-by
                    aggregateNode.ValidatePositionals();
                    if (aggregateNode.OptionalLocalGroupBy != null)
                    {
                        throw new ExprValidationException("Match-recognize does not allow aggregation functions to specify a group-by");
                    }

                    // validate node and params
                    var count   = 0;
                    var visitor = new ExprNodeIdentifierVisitor(true);

                    var validationContext = new ExprValidationContext(
                        typeServiceAggregateMeasure,
                        statementContext.EngineImportService,
                        statementContext.StatementExtensionServicesContext, null,
                        statementContext.SchedulingService,
                        statementContext.VariableService,
                        statementContext.TableService,
                        exprEvaluatorContext,
                        statementContext.EventAdapterService,
                        statementContext.StatementName,
                        statementContext.StatementId,
                        statementContext.Annotations,
                        statementContext.ContextDescriptor,
                        statementContext.ScriptingService,
                        false, false, true, false, null, false);
                    for (int ii = 0; ii < aggregateNode.ChildNodes.Count; ii++)
                    {
                        var child     = aggregateNode.ChildNodes[ii];
                        var validated = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.MATCHRECOGMEASURE, child, validationContext);
                        validated.Accept(visitor);
                        aggregateNode.SetChildNode(count++, new ExprNodeValidated(validated));
                    }
                    validationContext = new ExprValidationContext(
                        typeServiceMeasure,
                        statementContext.EngineImportService,
                        statementContext.StatementExtensionServicesContext, null,
                        statementContext.SchedulingService,
                        statementContext.VariableService,
                        statementContext.TableService,
                        exprEvaluatorContext,
                        statementContext.EventAdapterService,
                        statementContext.StatementName,
                        statementContext.StatementId,
                        statementContext.Annotations,
                        statementContext.ContextDescriptor,
                        statementContext.ScriptingService,
                        false, false, true, false, null, false);
                    aggregateNode.Validate(validationContext);

                    // verify properties used within the aggregation
                    var aggregatedStreams = new HashSet <int>();
                    foreach (var pair in visitor.ExprProperties)
                    {
                        aggregatedStreams.Add(pair.First);
                    }

                    int?multipleVarStream = null;
                    foreach (int streamNumAggregated in aggregatedStreams)
                    {
                        var variable = _streamVariables.Get(streamNumAggregated);
                        if (variablesMultiple.Contains(variable))
                        {
                            measureReferencesMultivar = true;
                            if (multipleVarStream == null)
                            {
                                multipleVarStream = streamNumAggregated;
                                continue;
                            }
                            throw new ExprValidationException("Aggregation functions in the measure-clause must only refer to properties of exactly one group variable returning multiple events");
                        }
                    }

                    if (multipleVarStream == null)
                    {
                        throw new ExprValidationException("Aggregation functions in the measure-clause must refer to one or more properties of exactly one group variable returning multiple events");
                    }

                    var aggNodesForStream = measureExprAggNodesPerStream.Get(multipleVarStream.Value);
                    if (aggNodesForStream == null)
                    {
                        aggNodesForStream = new List <ExprAggregateNode>();
                        measureExprAggNodesPerStream.Put(multipleVarStream.Value, aggNodesForStream);
                    }
                    aggNodesForStream.Add(aggregateNode);
                }

                var factoryDesc = AggregationServiceFactoryFactory.GetServiceMatchRecognize(_streamVariables.Count, measureExprAggNodesPerStream, typeServiceAggregateMeasure.EventTypes);
                _aggregationService     = factoryDesc.AggregationServiceFactory.MakeService(agentInstanceContext);
                _aggregationExpressions = factoryDesc.Expressions;
            }
            else
            {
                _aggregationService     = null;
                _aggregationExpressions = Collections.GetEmptyList <AggregationServiceAggExpressionDesc>();
            }

            // validate each MEASURE clause expression
            IDictionary <string, object> rowTypeDef = new LinkedHashMap <string, object>();
            var streamRefVisitor = new ExprNodeStreamUseCollectVisitor();

            foreach (var measureItem in matchRecognizeSpec.Measures)
            {
                if (measureItem.Name == null)
                {
                    throw new ExprValidationException("The measures clause requires that each expression utilizes the AS keyword to assign a column name");
                }
                var validated = ValidateMeasureClause(measureItem.Expr, typeServiceMeasure, variablesMultiple, _variablesSingle, statementContext);
                measureItem.Expr = validated;
                rowTypeDef.Put(measureItem.Name, validated.ExprEvaluator.ReturnType);
                validated.Accept(streamRefVisitor);
            }

            // Determine if any of the multi-var streams are referenced in the measures (non-aggregated only)
            foreach (var @ref in streamRefVisitor.Referenced)
            {
                var rootPropName = @ref.RootPropertyNameIfAny;
                if (rootPropName != null)
                {
                    if (variablesMultiple.Contains(rootPropName))
                    {
                        measureReferencesMultivar = true;
                        break;
                    }
                }

                var streamRequired = @ref.StreamReferencedIfAny;
                if (streamRequired != null)
                {
                    var streamVariable = _streamVariables.Get(streamRequired.Value);
                    if (streamVariable != null)
                    {
                        var def = _variableStreams.Get(streamVariable);
                        if (def != null && def.Second)
                        {
                            measureReferencesMultivar = true;
                            break;
                        }
                    }
                }
            }
            _isCollectMultimatches = measureReferencesMultivar || _isDefineAsksMultimatches;

            // create rowevent type
            var rowEventTypeName = statementContext.StatementId + "_rowrecogrow";

            _rowEventType = statementContext.EventAdapterService.CreateAnonymousMapType(rowEventTypeName, rowTypeDef, true);

            // validate partition-by expressions, if any
            if (!matchRecognizeSpec.PartitionByExpressions.IsEmpty())
            {
                var typeServicePartition = new StreamTypeServiceImpl(parentViewType, "MATCH_RECOGNIZE_PARTITION", true, statementContext.EngineURI);
                var validated            = new List <ExprNode>();
                var validationContext    = new ExprValidationContext(
                    typeServicePartition,
                    statementContext.EngineImportService,
                    statementContext.StatementExtensionServicesContext, null,
                    statementContext.SchedulingService, statementContext.VariableService, statementContext.TableService,
                    exprEvaluatorContext, statementContext.EventAdapterService, statementContext.StatementName,
                    statementContext.StatementId, statementContext.Annotations, statementContext.ContextDescriptor,
                    statementContext.ScriptingService,
                    false, false, true, false, null, false);
                foreach (var partitionExpr in matchRecognizeSpec.PartitionByExpressions)
                {
                    validated.Add(ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.MATCHRECOGPARTITION, partitionExpr, validationContext));
                }
                matchRecognizeSpec.PartitionByExpressions = validated;
            }

            // validate interval if present
            if (matchRecognizeSpec.Interval != null)
            {
                var validationContext =
                    new ExprValidationContext(
                        new StreamTypeServiceImpl(statementContext.EngineURI, false),
                        statementContext.EngineImportService,
                        statementContext.StatementExtensionServicesContext, null,
                        statementContext.SchedulingService,
                        statementContext.VariableService, statementContext.TableService, exprEvaluatorContext,
                        statementContext.EventAdapterService, statementContext.StatementName, statementContext.StatementId,
                        statementContext.Annotations, statementContext.ContextDescriptor, statementContext.ScriptingService,
                        false, false, true, false, null, false);
                matchRecognizeSpec.Interval.Validate(validationContext);
            }
        }
            public EventBean Process(EventBean[] eventsPerStream, bool isNewData, bool isSynthesize, ExprEvaluatorContext exprEvaluatorContext)
            {
                ObjectArrayBackedEventBean theEvent = (ObjectArrayBackedEventBean)eventsPerStream[_underlyingStreamNumber];

                return(_selectExprContext.EventAdapterService.AdapterForTypedObjectArray(theEvent.Properties, _resultType));
            }