コード例 #1
0
        private ExprAggMultiFunctionSortedMinMaxByNodeFactory HandleNonTable(ExprValidationContext validationContext)

        {
            if (PositionalParams.Length == 0)
            {
                throw new ExprValidationException("Missing the sort criteria expression");
            }

            // validate that the streams referenced in the criteria are a single stream's
            var streams = ExprNodeUtility.GetIdentStreamNumbers(PositionalParams[0]);

            if (streams.Count > 1 || streams.IsEmpty())
            {
                throw new ExprValidationException(ErrorPrefix + " requires that any parameter expressions evaluate properties of the same stream");
            }
            int streamNum = streams.First();

            // validate that there is a remove stream, use "ever" if not
            var forceEver = false;

            if (!_ever && ExprAggMultiFunctionLinearAccessNode.GetIstreamOnly(validationContext.StreamTypeService, streamNum))
            {
                if (_sortedwin)
                {
                    throw new ExprValidationException(ErrorPrefix + " requires that a data window is declared for the stream");
                }
                forceEver = true;
            }

            // determine typing and evaluation
            _containedType = validationContext.StreamTypeService.EventTypes[streamNum];

            var componentType      = _containedType.UnderlyingType;
            var accessorResultType = componentType;
            AggregationAccessor accessor;
            TableMetadata       tableMetadata = validationContext.TableService.GetTableMetadataFromEventType(_containedType);

            if (!_sortedwin)
            {
                if (tableMetadata != null)
                {
                    accessor = new AggregationAccessorMinMaxByTable(_max, tableMetadata);
                }
                else
                {
                    accessor = new AggregationAccessorMinMaxByNonTable(_max);
                }
            }
            else
            {
                if (tableMetadata != null)
                {
                    accessor = new AggregationAccessorSortedTable(_max, componentType, tableMetadata);
                }
                else
                {
                    accessor = new AggregationAccessorSortedNonTable(_max, componentType);
                }
                accessorResultType = TypeHelper.GetArrayType(accessorResultType);
            }

            Pair <ExprNode[], bool[]> criteriaExpressions = CriteriaExpressions;

            AggregationStateTypeWStream type;

            if (_ever)
            {
                type = _max ? AggregationStateTypeWStream.MAXEVER : AggregationStateTypeWStream.MINEVER;
            }
            else
            {
                type = AggregationStateTypeWStream.SORTED;
            }
            var stateKey = new AggregationStateKeyWStream(streamNum, _containedType, type, criteriaExpressions.First);

            var stateFactoryFactory = new
                                      SortedAggregationStateFactoryFactory(validationContext.MethodResolutionService,
                                                                           ExprNodeUtility.GetEvaluators(criteriaExpressions.First),
                                                                           criteriaExpressions.Second, _ever, streamNum, this);

            return(new ExprAggMultiFunctionSortedMinMaxByNodeFactory(this, accessor, accessorResultType, _containedType, stateKey, stateFactoryFactory, AggregationAgentDefault.INSTANCE));
        }
コード例 #2
0
        private ExprAggMultiFunctionSortedMinMaxByNodeFactory HandleNonTable(ExprValidationContext validationContext)
        {
            var positionalParams = PositionalParams;
            if (positionalParams.Length == 0)
                throw new ExprValidationException("Missing the sort criteria expression");

            // validate that the streams referenced in the criteria are a single stream's
            var streams = ExprNodeUtility.GetIdentStreamNumbers(positionalParams[0]);
            if (streams.Count > 1 || streams.IsEmpty())
                throw new ExprValidationException(
                    GetErrorPrefix() + " requires that any parameter expressions evaluate properties of the same stream");
            var streamNum = streams.First();

            // validate that there is a remove stream, use "ever" if not
            if (!_ever && ExprAggMultiFunctionLinearAccessNode.GetIstreamOnly(validationContext.StreamTypeService,
                    streamNum))
                if (_sortedwin)
                    throw new ExprValidationException(
                        GetErrorPrefix() + " requires that a data window is declared for the stream");

            // determine typing and evaluation
            _containedType = validationContext.StreamTypeService.EventTypes[streamNum];

            var componentType = _containedType.UnderlyingType;
            var accessorResultType = componentType;
            AggregationAccessor accessor;
            var tableMetadata = validationContext.TableService.GetTableMetadataFromEventType(_containedType);
            if (!_sortedwin)
            {
                if (tableMetadata != null)
                    accessor = new AggregationAccessorMinMaxByTable(IsMax, tableMetadata);
                else
                    accessor = new AggregationAccessorMinMaxByNonTable(IsMax);
            }
            else
            {
                if (tableMetadata != null)
                    accessor = new AggregationAccessorSortedTable(IsMax, componentType, tableMetadata);
                else
                    accessor = new AggregationAccessorSortedNonTable(IsMax, componentType);
                accessorResultType = TypeHelper.GetArrayType(accessorResultType);
            }

            var criteriaExpressions = CriteriaExpressions;

            AggregationStateTypeWStream type;
            if (_ever)
                type = IsMax ? AggregationStateTypeWStream.MAXEVER : AggregationStateTypeWStream.MINEVER;
            else
                type = AggregationStateTypeWStream.SORTED;

            var optionalFilter = OptionalFilter;
            var stateKey = new AggregationStateKeyWStream(
                streamNum, _containedType, type, criteriaExpressions.First, optionalFilter);

            var optionalFilterEval = optionalFilter?.ExprEvaluator;
            var stateFactoryFactory = new
                SortedAggregationStateFactoryFactory(validationContext.EngineImportService,
                    validationContext.StatementExtensionSvcContext,
                    ExprNodeUtility.GetEvaluators(criteriaExpressions.First),
                    criteriaExpressions.Second, _ever, streamNum, this, optionalFilterEval);

            return new ExprAggMultiFunctionSortedMinMaxByNodeFactory(this, accessor, accessorResultType, _containedType,
                stateKey, stateFactoryFactory, AggregationAgentDefault.INSTANCE);
        }