Example #1
0
        private ExprAggMultiFunctionSortedMinMaxByNodeFactory HandleCreateTable(
            ExprValidationContext validationContext)
        {
            if (PositionalParams.Length == 0)
                throw new ExprValidationException("Missing the sort criteria expression");

            var message = "For tables columns, the aggregation function requires the 'sorted(*)' declaration";
            if (!_sortedwin && !_ever) throw new ExprValidationException(message);
            if (validationContext.StreamTypeService.StreamNames.Length == 0)
                throw new ExprValidationException("'Sorted' requires that the event type is provided");
            var containedType = validationContext.StreamTypeService.EventTypes[0];
            var componentType = containedType.UnderlyingType;
            var criteriaExpressions = CriteriaExpressions;
            var accessorResultType = componentType;
            AggregationAccessor accessor;
            if (!_sortedwin)
            {
                accessor = new AggregationAccessorMinMaxByNonTable(IsMax);
            }
            else
            {
                accessor = new AggregationAccessorSortedNonTable(IsMax, componentType);
                accessorResultType = TypeHelper.GetArrayType(accessorResultType);
            }

            var stateFactoryFactory = new
                SortedAggregationStateFactoryFactory(validationContext.EngineImportService,
                    validationContext.StatementExtensionSvcContext,
                    ExprNodeUtility.GetEvaluators(criteriaExpressions.First),
                    criteriaExpressions.Second, _ever, 0, this, null);
            return new ExprAggMultiFunctionSortedMinMaxByNodeFactory(this, accessor, accessorResultType, containedType,
                null, stateFactoryFactory, null);
        }
Example #2
0
        private ExprAggMultiFunctionSortedMinMaxByNodeFactory HandleIntoTable(ExprValidationContext validationContext)
        {
            int streamNum;
            var positionalParams = PositionalParams;

            if (positionalParams.Length == 0 ||
                (positionalParams.Length == 1 && positionalParams[0] is ExprWildcard))
            {
                ExprAggMultiFunctionUtil.ValidateWildcardStreamNumbers(
                    validationContext.StreamTypeService, AggregationFunctionName);
                streamNum = 0;
            }
            else if (positionalParams.Length == 1 && positionalParams[0] is ExprStreamUnderlyingNode)
            {
                streamNum = ExprAggMultiFunctionUtil.ValidateStreamWildcardGetStreamNum(positionalParams[0]);
            }
            else if (positionalParams.Length > 0)
            {
                throw new ExprValidationException("When specifying into-table a sort expression cannot be provided");
            }
            else
            {
                streamNum = 0;
            }

            var containedType      = validationContext.StreamTypeService.EventTypes[streamNum];
            var componentType      = containedType.UnderlyingType;
            var accessorResultType = componentType;
            AggregationAccessor accessor;

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

            AggregationAgent agent = AggregationAgentDefault.INSTANCE;

            if (streamNum != 0)
            {
                agent = new AggregationAgentRewriteStream(streamNum);
            }

            return(new ExprAggMultiFunctionSortedMinMaxByNodeFactory(
                       this, accessor, accessorResultType, containedType, null, null, agent));
        }
Example #3
0
        private AggregationForgeFactoryAccessSorted HandleCreateTable(ExprValidationContext validationContext)
        {
            if (positionalParams.Length == 0) {
                throw new ExprValidationException("Missing the sort criteria expression");
            }

            var message = "For tables columns, the aggregation function requires the 'sorted(*)' declaration";
            if (!sortedwin && !ever) {
                throw new ExprValidationException(message);
            }

            if (validationContext.StreamTypeService.StreamNames.Length == 0) {
                throw new ExprValidationException("'Sorted' requires that the event type is provided");
            }

            var containedType = validationContext.StreamTypeService.EventTypes[0];
            var componentType = containedType.UnderlyingType;
            var criteriaExpressions = CriteriaExpressions;
            var accessorResultType = componentType;
            AggregationAccessorForge accessor;
            if (!sortedwin) {
                accessor = new AggregationAccessorMinMaxByNonTable(IsMax);
            }
            else {
                accessor = new AggregationAccessorSortedNonTable(IsMax, componentType);
                accessorResultType = TypeHelper.GetArrayType(accessorResultType);
            }

            var criteriaTypes = ExprNodeUtilityQuery.GetExprResultTypes(criteriaExpressions.First);
            var stateDesc = new SortedAggregationStateDesc(
                IsMax,
                validationContext.ImportService,
                criteriaExpressions.First,
                criteriaTypes,
                criteriaExpressions.Second,
                ever,
                0,
                this,
                null,
                containedType);
            return new AggregationForgeFactoryAccessSorted(
                this,
                accessor,
                accessorResultType,
                containedType,
                null,
                stateDesc,
                null);
        }
Example #4
0
        private AggregationForgeFactoryAccessSorted HandleIntoTable(ExprValidationContext validationContext)
        {
            int streamNum;
            if (positionalParams.Length == 0 ||
                positionalParams.Length == 1 && positionalParams[0] is ExprWildcard) {
                ExprAggMultiFunctionUtil.ValidateWildcardStreamNumbers(
                    validationContext.StreamTypeService,
                    AggregationFunctionName);
                streamNum = 0;
            }
            else if (positionalParams.Length == 1 && positionalParams[0] is ExprStreamUnderlyingNode) {
                streamNum = ExprAggMultiFunctionUtil.ValidateStreamWildcardGetStreamNum(positionalParams[0]);
            }
            else if (positionalParams.Length > 0) {
                throw new ExprValidationException("When specifying into-table a sort expression cannot be provided");
            }
            else {
                streamNum = 0;
            }

            var containedType = validationContext.StreamTypeService.EventTypes[streamNum];
            var componentType = containedType.UnderlyingType;
            var accessorResultType = componentType;
            AggregationAccessorForge accessor;
            if (!sortedwin) {
                accessor = new AggregationAccessorMinMaxByNonTable(IsMax);
            }
            else {
                accessor = new AggregationAccessorSortedNonTable(IsMax, componentType);
                accessorResultType = TypeHelper.GetArrayType(accessorResultType);
            }

            AggregationAgentForge agent = AggregationAgentForgeFactory.Make(
                streamNum,
                optionalFilter,
                validationContext.ImportService,
                validationContext.StreamTypeService.IsOnDemandStreams,
                validationContext.StatementName);
            return new AggregationForgeFactoryAccessSorted(
                this,
                accessor,
                accessorResultType,
                containedType,
                null,
                null,
                agent);
        }
        private ExprAggMultiFunctionSortedMinMaxByNodeFactory HandleTableAccess(TableMetadataColumnAggregation tableAccess)
        {
            var factory = (ExprAggMultiFunctionSortedMinMaxByNodeFactory)tableAccess.Factory;
            AggregationAccessor accessor;
            var componentType      = factory.ContainedEventType.UnderlyingType;
            var accessorResultType = componentType;

            if (!_sortedwin)
            {
                accessor = new AggregationAccessorMinMaxByNonTable(_max);
            }
            else
            {
                accessor           = new AggregationAccessorSortedNonTable(_max, componentType);
                accessorResultType = TypeHelper.GetArrayType(accessorResultType);
            }
            return(new ExprAggMultiFunctionSortedMinMaxByNodeFactory(this, accessor, accessorResultType, factory.ContainedEventType, null, null, null));
        }
        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));
        }
Example #7
0
        private AggregationForgeFactoryAccessSorted 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 = ExprNodeUtilityQuery.GetIdentStreamNumbers(positionalParams[0]);
            if (streams.Count > 1 || streams.IsEmpty()) {
                throw new ExprValidationException(
                    ErrorPrefix + " 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(
                        ErrorPrefix + " 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;
            AggregationAccessorForge accessor;
            var tableMetadata = validationContext.TableCompileTimeResolver.ResolveTableFromEventType(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 stateKey = new AggregationStateKeyWStream(
                streamNum,
                containedType,
                type,
                criteriaExpressions.First,
                optionalFilter);

            var optionalFilterForge = optionalFilter == null ? null : optionalFilter.Forge;
            var streamEventType = validationContext.StreamTypeService.EventTypes[streamNum];
            var criteriaTypes = ExprNodeUtilityQuery.GetExprResultTypes(criteriaExpressions.First);
            var sortedDesc = new
                SortedAggregationStateDesc(
                    IsMax,
                    validationContext.ImportService,
                    criteriaExpressions.First,
                    criteriaTypes,
                    criteriaExpressions.Second,
                    ever,
                    streamNum,
                    this,
                    optionalFilterForge,
                    streamEventType);

            return new AggregationForgeFactoryAccessSorted(
                this,
                accessor,
                accessorResultType,
                containedType,
                stateKey,
                sortedDesc,
                AggregationAgentDefault.INSTANCE);
        }
Example #8
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);
        }
        private AggregationForgeFactoryAccessSorted 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
            ISet <int> streams = ExprNodeUtilityQuery.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
            if (!_ever && ExprAggMultiFunctionLinearAccessNode.GetIstreamOnly(validationContext.StreamTypeService, streamNum))
            {
                if (_sortedwin)
                {
                    throw new ExprValidationException(ErrorPrefix + " requires that a data window is declared for the stream");
                }
            }

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

            Type componentType      = _containedType.UnderlyingType;
            Type accessorResultType = componentType;
            AggregationAccessorForge accessor;
            TableMetaData            tableMetadata = validationContext.TableCompileTimeResolver.ResolveTableFromEventType(_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;
            }

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

            ExprForge optionalFilterForge = optionalFilter == null ? null : optionalFilter.Forge;
            EventType streamEventType     = validationContext.StreamTypeService.EventTypes[streamNum];

            Type[] criteriaTypes = ExprNodeUtilityQuery.GetExprResultTypes(criteriaExpressions.First);
            DataInputOutputSerdeForge[] criteriaSerdes = new DataInputOutputSerdeForge[criteriaTypes.Length];
            for (int i = 0; i < criteriaTypes.Length; i++)
            {
                criteriaSerdes[i] = validationContext.SerdeResolver.SerdeForAggregation(criteriaTypes[i], validationContext.StatementRawInfo);
            }

            SortedAggregationStateDesc sortedDesc = new
                                                    SortedAggregationStateDesc(
                _max,
                validationContext.ImportService,
                criteriaExpressions.First,
                criteriaTypes,
                criteriaSerdes,
                criteriaExpressions.Second,
                _ever,
                streamNum,
                this,
                optionalFilterForge,
                streamEventType);

            IList <StmtClassForgeableFactory> serdeForgables = SerdeEventTypeUtility.Plan(
                _containedType,
                validationContext.StatementRawInfo,
                validationContext.SerdeEventTypeRegistry,
                validationContext.SerdeResolver);

            validationContext.AdditionalForgeables.AddAll(serdeForgables);

            return(new AggregationForgeFactoryAccessSorted(
                       this,
                       accessor,
                       accessorResultType,
                       _containedType,
                       stateKey,
                       sortedDesc,
                       AggregationAgentDefault.INSTANCE));
        }
        private AggregationForgeFactoryAccessSorted HandleCreateTable(ExprValidationContext validationContext)
        {
            if (positionalParams.Length == 0)
            {
                throw new ExprValidationException("Missing the sort criteria expression");
            }

            string message = "For tables columns, the aggregation function requires the 'sorted(*)' declaration";

            if (!_sortedwin && !_ever)
            {
                throw new ExprValidationException(message);
            }

            if (validationContext.StreamTypeService.StreamNames.Length == 0)
            {
                throw new ExprValidationException("'Sorted' requires that the event type is provided");
            }

            EventType containedType = validationContext.StreamTypeService.EventTypes[0];
            Type      componentType = containedType.UnderlyingType;
            Pair <ExprNode[], bool[]> criteriaExpressions = CriteriaExpressions;
            Type accessorResultType = componentType;
            AggregationAccessorForge accessor;

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

            Type[] criteriaTypes = ExprNodeUtilityQuery.GetExprResultTypes(criteriaExpressions.First);
            DataInputOutputSerdeForge[] criteriaSerdes = new DataInputOutputSerdeForge[criteriaTypes.Length];
            for (int i = 0; i < criteriaTypes.Length; i++)
            {
                criteriaSerdes[i] = validationContext.SerdeResolver.SerdeForAggregation(criteriaTypes[i], validationContext.StatementRawInfo);
            }

            SortedAggregationStateDesc stateDesc = new SortedAggregationStateDesc(
                _max,
                validationContext.ImportService,
                criteriaExpressions.First,
                criteriaTypes,
                criteriaSerdes,
                criteriaExpressions.Second,
                _ever,
                0,
                this,
                null,
                containedType);

            IList <StmtClassForgeableFactory> serdeForgables = SerdeEventTypeUtility.Plan(
                containedType,
                validationContext.StatementRawInfo,
                validationContext.SerdeEventTypeRegistry,
                validationContext.SerdeResolver);

            validationContext.AdditionalForgeables.AddAll(serdeForgables);

            return(new AggregationForgeFactoryAccessSorted(this, accessor, accessorResultType, containedType, null, stateDesc, null));
        }