Example #1
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);
        }
        public override AggregationMethodFactory ValidateAggregationChild(ExprValidationContext validationContext)
        {
            var positionalParams = PositionalParams;
            var parameterTypes   = new Type[positionalParams.Length];
            var constant         = new Object[positionalParams.Length];
            var isConstant       = new bool[positionalParams.Length];
            var expressions      = new ExprNode[positionalParams.Length];

            var count          = 0;
            var hasDataWindows = true;
            var evaluateParams = new EvaluateParams(null, true, validationContext.ExprEvaluatorContext);

            foreach (var child in positionalParams)
            {
                if (child.IsConstantResult)
                {
                    isConstant[count] = true;
                    constant[count]   = child.ExprEvaluator.Evaluate(evaluateParams);
                }
                parameterTypes[count] = child.ExprEvaluator.ReturnType;
                expressions[count]    = child;

                if (!ExprNodeUtility.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++;
            }

            var context = new AggregationValidationContext(parameterTypes, isConstant, constant, base.IsDistinct, hasDataWindows, expressions);

            try
            {
                // the aggregation function factory is transient, obtain if not provided
                if (_aggregationFunctionFactory == null)
                {
                    _aggregationFunctionFactory = validationContext.MethodResolutionService.EngineImportService.ResolveAggregationFactory(_functionName);
                }

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

            Type childType = null;

            if (positionalParams.Length > 0)
            {
                childType = positionalParams[0].ExprEvaluator.ReturnType;
            }

            return(new ExprPlugInAggFunctionFactory(this, _aggregationFunctionFactory, childType));
        }
Example #3
0
 private static String GetErrorPrefix(AggregationAccessorLinearType stateType)
 {
     return ExprAggMultiFunctionUtil.GetErrorPrefix(stateType.ToString().ToLowerInvariant());
 }