示例#1
0
 public AggregationMethodFactoryPluginMethod(
     ExprPlugInAggNode parent,
     AggregationFunctionForge aggregationFunctionForge,
     AggregationFunctionMode mode)
 {
     this.parent = parent;
     this.aggregationFunctionForge = aggregationFunctionForge;
     this.mode = mode;
 }
示例#2
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="distinct">flag indicating unique or non-unique value aggregation</param>
 /// <param name="aggregationFunctionForge">is the base class for plug-in aggregation functions</param>
 /// <param name="functionName">is the aggregation function name</param>
 public ExprPlugInAggNode(
     bool distinct,
     AggregationFunctionForge aggregationFunctionForge,
     string functionName)
     : base(distinct)
 {
     this.aggregationFunctionForge = aggregationFunctionForge;
     this.functionName = functionName;
     aggregationFunctionForge.FunctionName = functionName;
 }
示例#3
0
 public AggregationForgeFactoryPlugin(
     ExprPlugInAggNode parent,
     AggregationFunctionForge aggregationFunctionForge,
     AggregationFunctionMode mode,
     Type aggregatedValueType,
     DataInputOutputSerdeForge distinctSerde)
 {
     this.parent = parent;
     this.aggregationFunctionForge = aggregationFunctionForge;
     this.mode = mode;
     this.aggregatedValueType = aggregatedValueType;
     this.distinctSerde       = distinctSerde;
 }
示例#4
0
        public static ExprNode TryResolveAsAggregation(
            ImportServiceCompileTime importService,
            bool distinct,
            string functionName,
            LazyAllocatedMap<HashableMultiKey, AggregationMultiFunctionForge> plugInAggregations,
            ClassProvidedExtension classProvidedExtension)
        {
            try {
                AggregationFunctionForge aggregationFactory = importService.ResolveAggregationFunction(functionName, classProvidedExtension);
                return new ExprPlugInAggNode(distinct, aggregationFactory, functionName);
            }
            catch (ImportUndefinedException) {
                // Not an aggregation function
            }
            catch (ImportException e) {
                throw new ValidationException("Error resolving aggregation: " + e.Message, e);
            }

            // try plug-in aggregation multi-function
            Pair<ConfigurationCompilerPlugInAggregationMultiFunction, Type> configPair = importService
                .ResolveAggregationMultiFunction(functionName, classProvidedExtension);
            if (configPair != null) {
                HashableMultiKey multiKey = new HashableMultiKey(configPair.First.FunctionNames);
                AggregationMultiFunctionForge factory = plugInAggregations.Map.Get(multiKey);
                if (factory == null) {
                    if (configPair.Second != null) {
                        factory = (AggregationMultiFunctionForge) TypeHelper.Instantiate<AggregationMultiFunctionForge>(
                            configPair.Second);
                    } else {
                        factory = (AggregationMultiFunctionForge) TypeHelper.Instantiate<AggregationMultiFunctionForge>(
                            configPair.First.MultiFunctionForgeClassName, importService.ClassForNameProvider);
                    }
                    plugInAggregations.Map[multiKey] = factory;
                }
                factory.AddAggregationFunction(new AggregationMultiFunctionDeclarationContext(
                    functionName.ToLowerInvariant(),
                    distinct,
                    configPair.First));
                return new ExprPlugInMultiFunctionAggNode(distinct, configPair.First, factory, functionName);
            }

            // try built-in expanded set of aggregation functions
            return importService.ResolveAggExtendedBuiltin(functionName, distinct);
        }
示例#5
0
        public static ExprNode TryResolveAsAggregation(
            ImportServiceCompileTime importService,
            bool distinct,
            string functionName,
            LazyAllocatedMap<ConfigurationCompilerPlugInAggregationMultiFunction, AggregationMultiFunctionForge>
                plugInAggregations)
        {
            try {
                AggregationFunctionForge aggregationFactory = importService.ResolveAggregationFunction(functionName);
                return new ExprPlugInAggNode(distinct, aggregationFactory, functionName);
            }
            catch (ImportUndefinedException) {
                // Not an aggregation function
            }
            catch (ImportException e) {
                throw new ValidationException("Error resolving aggregation: " + e.Message, e);
            }

            // try plug-in aggregation multi-function
            ConfigurationCompilerPlugInAggregationMultiFunction config =
                importService.ResolveAggregationMultiFunction(functionName);
            if (config != null) {
                AggregationMultiFunctionForge factory = plugInAggregations.Map.Get(config);
                if (factory == null) {
                    factory = (AggregationMultiFunctionForge) TypeHelper.Instantiate<AggregationMultiFunctionForge>(
                        config.MultiFunctionForgeClassName,
                        importService.ClassForNameProvider);
                    plugInAggregations.Map.Put(config, factory);
                }

                factory.AddAggregationFunction(
                    new AggregationMultiFunctionDeclarationContext(functionName.ToLowerInvariant(), distinct, config));
                return new ExprPlugInMultiFunctionAggNode(distinct, config, factory, functionName);
            }

            // try built-in expanded set of aggregation functions
            return importService.ResolveAggExtendedBuiltin(functionName, distinct);
        }
示例#6
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);
        }
示例#7
0
        // Since static method calls such as "Class.method('a')" and mapped properties "Stream.property('key')"
        // look the same, however as the validation could not resolve "Stream.property('key')" before calling this method,
        // this method tries to resolve the mapped property as a static method.
        // Assumes that this is an ExprIdentNode.
        private static ExprNode ResolveStaticMethodOrField(
            ExprIdentNode identNode,
            ExprValidationException propertyException,
            ExprValidationContext validationContext)
        {
            // Reconstruct the original string
            StringBuilder mappedProperty = new StringBuilder(identNode.UnresolvedPropertyName);
            if (identNode.StreamOrPropertyName != null) {
                mappedProperty.Insert(0, identNode.StreamOrPropertyName + '.');
            }

            // Parse the mapped property format into a class name, method and single string parameter
            MappedPropertyParseResult parse = ParseMappedProperty(mappedProperty.ToString());
            if (parse == null) {
                ExprConstantNode constNode = ResolveIdentAsEnumConst(
                    mappedProperty.ToString(),
                    validationContext.ImportService);
                if (constNode == null) {
                    throw propertyException;
                }
                else {
                    return constNode;
                }
            }

            // If there is a class name, assume a static method is possible.
            if (parse.ClassName != null) {
                IList<ExprNode> parameters =
                    Collections.SingletonList((ExprNode) new ExprConstantNodeImpl(parse.ArgString));
                IList<ExprChainedSpec> chain = new List<ExprChainedSpec>();
                chain.Add(new ExprChainedSpec(parse.ClassName, Collections.GetEmptyList<ExprNode>(), false));
                chain.Add(new ExprChainedSpec(parse.MethodName, parameters, false));
                ConfigurationCompilerExpression exprConfig =
                    validationContext.StatementCompileTimeService.Configuration.Compiler.Expression;
                ExprNode result = new ExprDotNodeImpl(chain, exprConfig.IsDuckTyping, exprConfig.IsUdfCache);

                // Validate
                try {
                    result.Validate(validationContext);
                }
                catch (ExprValidationException e) {
                    throw new ExprValidationException(
                        $"Failed to resolve enumeration method, date-time method or mapped property '{mappedProperty}': {e.Message}",
                        e);
                }

                return result;
            }

            // There is no class name, try a single-row function
            string functionName = parse.MethodName;
            try {
                Pair<Type, ImportSingleRowDesc> classMethodPair =
                    validationContext.ImportService.ResolveSingleRow(functionName);
                IList<ExprNode> parameters =
                    Collections.SingletonList((ExprNode) new ExprConstantNodeImpl(parse.ArgString));
                IList<ExprChainedSpec> chain = Collections.SingletonList(
                    new ExprChainedSpec(classMethodPair.Second.MethodName, parameters, false));
                ExprNode result = new ExprPlugInSingleRowNode(
                    functionName,
                    classMethodPair.First,
                    chain,
                    classMethodPair.Second);

                // Validate
                try {
                    result.Validate(validationContext);
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception ex) {
                    throw new ExprValidationException(
                        "Plug-in aggregation function '" + parse.MethodName + "' failed validation: " + ex.Message);
                }

                return result;
            }
            catch (ImportUndefinedException) {
                // Not an single-row function
            }
            catch (ImportException e) {
                throw new IllegalStateException("Error resolving single-row function: " + e.Message, e);
            }

            // Try an aggregation function factory
            try {
                AggregationFunctionForge aggregationForge =
                    validationContext.ImportService.ResolveAggregationFunction(parse.MethodName);
                ExprNode result = new ExprPlugInAggNode(false, aggregationForge, parse.MethodName);
                result.AddChildNode(new ExprConstantNodeImpl(parse.ArgString));

                // Validate
                try {
                    result.Validate(validationContext);
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception e) {
                    throw new ExprValidationException(
                        "Plug-in aggregation function '" + parse.MethodName + "' failed validation: " + e.Message);
                }

                return result;
            }
            catch (ImportUndefinedException) {
                // Not an aggregation function
            }
            catch (ImportException e) {
                throw new IllegalStateException("Error resolving aggregation: " + e.Message, e);
            }

            // absolutely cannot be resolved
            throw propertyException;
        }