Пример #1
0
        public override AggregationForgeFactory ValidateAggregationChild(ExprValidationContext validationContext)
        {
            if (positionalParams.Length == 0 || positionalParams.Length > 2) {
                throw new ExprValidationException(MinMaxTypeEnum + " node must have either 1 or 2 parameters");
            }

            var child = positionalParams[0];
            bool hasDataWindows;
            if (IsEver) {
                hasDataWindows = false;
            }
            else {
                if (validationContext.StatementType == StatementType.CREATE_TABLE) {
                    hasDataWindows = true;
                }
                else {
                    hasDataWindows = ExprNodeUtilityAggregation.HasRemoveStreamForAggregations(
                        child,
                        validationContext.StreamTypeService,
                        validationContext.IsResettingAggregations);
                }
            }

            if (isFFunc) {
                if (positionalParams.Length < 2) {
                    throw new ExprValidationException(
                        MinMaxTypeEnum +
                        "-filtered aggregation function must have a filter expression as a second parameter");
                }

                ValidateFilter(positionalParams[1]);
            }

            HasFilter = positionalParams.Length == 2;
            if (HasFilter) {
                optionalFilter = positionalParams[1];
            }

            var evaluationType = child.Forge.EvaluationType;
            var serde = validationContext.SerdeResolver.SerdeForAggregation(evaluationType, validationContext.StatementRawInfo);
            var distinctSerde = isDistinct ? validationContext.SerdeResolver.SerdeForAggregationDistinct(evaluationType, validationContext.StatementRawInfo) : null;
            return new AggregationForgeFactoryMinMax(this, evaluationType, hasDataWindows, serde, distinctSerde);
        }
Пример #2
0
        public override AggregationForgeFactory ValidateAggregationChild(ExprValidationContext validationContext)
        {
            Type[] parameterTypes = new Type[positionalParams.Length];
            object[] constant = new object[positionalParams.Length];
            bool[] isConstant = new bool[positionalParams.Length];
            ExprNode[] expressions = new ExprNode[positionalParams.Length];

            int count = 0;
            bool hasDataWindows = true;
            foreach (ExprNode child in positionalParams) {
                if (child.Forge.ForgeConstantType == ExprForgeConstantType.COMPILETIMECONST) {
                    isConstant[count] = true;
                    constant[count] = child.Forge.ExprEvaluator.Evaluate(null, true, null);
                }

                parameterTypes[count] = child.Forge.EvaluationType;
                expressions[count] = child;

                if (!ExprNodeUtilityAggregation.HasRemoveStreamForAggregations(
                    child,
                    validationContext.StreamTypeService,
                    validationContext.IsResettingAggregations)) {
                    hasDataWindows = false;
                }

                if (child is ExprWildcard) {
                    ExprAggMultiFunctionUtil.CheckWildcardNotJoinOrSubquery(
                        validationContext.StreamTypeService,
                        functionName);
                    parameterTypes[count] = validationContext.StreamTypeService.EventTypes[0].UnderlyingType;
                    isConstant[count] = false;
                    constant[count] = null;
                }

                count++;
            }

            LinkedHashMap<string, IList<ExprNode>> namedParameters = null;
            if (optionalFilter != null) {
                namedParameters = new LinkedHashMap<string, IList<ExprNode>>();
                namedParameters.Put("filter", Collections.SingletonList(optionalFilter));
                positionalParams = ExprNodeUtilityMake.AddExpression(positionalParams, optionalFilter);
            }

            AggregationFunctionValidationContext context = new AggregationFunctionValidationContext(
                parameterTypes,
                isConstant,
                constant,
                base.IsDistinct,
                hasDataWindows,
                expressions,
                namedParameters);
            try {
                // the aggregation function factory is transient, obtain if not provided
                if (aggregationFunctionForge == null) {
                    aggregationFunctionForge =
                        validationContext.ImportService.ResolveAggregationFunction(functionName);
                }

                aggregationFunctionForge.Validate(context);
            }
            catch (Exception ex) {
                throw new ExprValidationException(
                    "Plug-in aggregation function '" + functionName + "' failed validation: " + ex.Message,
                    ex);
            }

            AggregationFunctionMode mode = aggregationFunctionForge.AggregationFunctionMode;
            if (mode == null) {
                throw new ExprValidationException("Aggregation function forge returned a null value for mode");
            }

            if (mode is AggregationFunctionModeManaged) {
                if (positionalParams.Length > 2) {
                    throw new ExprValidationException(
                        "Aggregation function forge single-value mode requires zero, one or two parameters");
                }
            }
            else if (mode is AggregationFunctionModeMultiParam || mode is AggregationFunctionModeCodeGenerated) {
            }
            else {
                throw new ExprValidationException("Aggregation function forge returned an unrecognized mode " + mode);
            }

            return new AggregationMethodFactoryPluginMethod(this, aggregationFunctionForge, mode);
        }
Пример #3
0
        public override AggregationForgeFactory ValidateAggregationChild(ExprValidationContext validationContext)
        {
            if (this.positionalParams.Length == 0) {
                throw new ExprValidationException(
                    "The rate aggregation function minimally requires a numeric constant or expression as a parameter.");
            }

            // handle "ever"
            ExprNode first = this.positionalParams[0];
            if (first.Forge.ForgeConstantType.IsCompileTimeConstant) {
                string messageX =
                    "The rate aggregation function requires a numeric constant or time period as the first parameter in the constant-value notation";
                long intervalTime;
                if (first is ExprTimePeriod) {
                    double secInterval = ((ExprTimePeriod) first).EvaluateAsSeconds(null, true, null);
                    intervalTime =
                        validationContext.ImportService.TimeAbacus.DeltaForSecondsDouble(secInterval);
                }
                else if (ExprNodeUtilityQuery.IsConstant(first)) {
                    if (!first.Forge.EvaluationType.IsNumeric()) {
                        throw new ExprValidationException(messageX);
                    }

                    var num = first.Forge.ExprEvaluator.Evaluate(null, true, null);
                    intervalTime = validationContext.ImportService.TimeAbacus.DeltaForSecondsNumber(num);
                }
                else {
                    throw new ExprValidationException(messageX);
                }

                if (optionalFilter == null) {
                    this.positionalParams = ExprNodeUtilityQuery.EMPTY_EXPR_ARRAY;
                }
                else {
                    this.positionalParams = new ExprNode[] {optionalFilter};
                }

                return new AggregationForgeFactoryRate(this, true, intervalTime, validationContext.ImportService.TimeAbacus);
            }

            string message =
                "The rate aggregation function requires a property or expression returning a non-constant long-type value as the first parameter in the timestamp-property notation";
            Type boxedParamOne = first.Forge.EvaluationType.GetBoxedType();
            if (boxedParamOne != typeof(long?)) {
                throw new ExprValidationException(message);
            }

            if (first.Forge.ForgeConstantType.IsConstant) {
                throw new ExprValidationException(message);
            }

            if (first is ExprTimestampNode) {
                throw new ExprValidationException(
                    "The rate aggregation function does not allow the current runtime timestamp as a parameter");
            }

            if (this.positionalParams.Length > 1) {
                if (!this.positionalParams[1].Forge.EvaluationType.IsNumeric()) {
                    throw new ExprValidationException(
                        "The rate aggregation function accepts an expression returning a numeric value to accumulate as an optional second parameter");
                }
            }

            bool hasDataWindows = ExprNodeUtilityAggregation.HasRemoveStreamForAggregations(
                first,
                validationContext.StreamTypeService,
                validationContext.IsResettingAggregations);
            if (!hasDataWindows) {
                throw new ExprValidationException(
                    "The rate aggregation function in the timestamp-property notation requires data windows");
            }

            if (optionalFilter != null) {
                positionalParams = ExprNodeUtilityMake.AddExpression(positionalParams, optionalFilter);
            }

            return new AggregationForgeFactoryRate(this, false, -1, validationContext.ImportService.TimeAbacus);
        }