Esempio n. 1
0
 public object Evaluate(
     EventBean[] eventsPerStream,
     bool isNewData,
     ExprEvaluatorContext exprEvaluatorContext)
 {
     throw ExprNodeUtilityMake.MakeUnsupportedCompileTime();
 }
Esempio n. 2
0
        /// <summary>
        /// Validates the expression node subtree that has this
        /// node as root. Some of the nodes of the tree, including the
        /// root, might be replaced in the process.
        /// </summary>
        /// <param name="origin">validate origin</param>
        /// <param name="exprNode">node</param>
        /// <param name="validationContext">context</param>
        /// <returns>the root node of the validated subtree, possibly different than the root node of the unvalidated subtree
        /// </returns>
        /// <throws>ExprValidationException when the validation fails</throws>
        public static ExprNode GetValidatedSubtree(
            ExprNodeOrigin origin,
            ExprNode exprNode,
            ExprValidationContext validationContext)
        {
            if (exprNode is ExprLambdaGoesNode) {
                return exprNode;
            }

            try {
                return GetValidatedSubtreeInternal(exprNode, validationContext, true);
            }
            catch (ExprValidationException ex) {
                try {
                    string text;
                    if (exprNode is ExprSubselectNode subselect) {
                        text = ExprNodeUtilityMake.GetSubqueryInfoText(subselect);
                    }
                    else {
                        text = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(exprNode);
                        if (text.Length > 40) {
                            string shortened = text.Substring(0, 35);
                            text = shortened + "...(" + text.Length + " chars)";
                        }

                        text = "'" + text + "'";
                    }

                    var errorText = string.Format(
                        "Failed to validate {0} expression {1}: {2}",
                        origin.GetClauseName(),
                        text,
                        ex.Message);

                    throw new ExprValidationException(errorText, ex);
                }
                catch (ExprValidationException) {
                    throw;
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception rtex) {
                    Log.Debug("Failed to render nice validation message text: " + rtex.Message, rtex);
                    // fall through
                }

                throw;
            }
        }
Esempio n. 3
0
        public static ExprNodeUtilMethodDesc ResolveMethodAllowWildcardAndStream(
            string className,
            Type optionalClass,
            string methodName,
            IList<ExprNode> parameters,
            bool allowWildcard,
            EventType wildcardType,
            ExprNodeUtilResolveExceptionHandler exceptionHandler,
            string functionName,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            var paramTypes = new Type[parameters.Count];
            var childForges = new ExprForge[parameters.Count];
            var count = 0;
            var allowEventBeanType = new bool[parameters.Count];
            var allowEventBeanCollType = new bool[parameters.Count];
            var childEvalsEventBeanReturnTypesForges = new ExprForge[parameters.Count];
            var allConstants = true;
            
            foreach (var childNode in parameters) {
                if (!EnumMethodResolver.IsEnumerationMethod(methodName, services.ImportServiceCompileTime) && childNode is ExprLambdaGoesNode) {
                    throw new ExprValidationException(
                        "Unrecognized lambda-expression encountered as parameter to UDF or static method '" +
                        methodName +
                        "'");
                }

                if (childNode is ExprWildcard) {
                    if (wildcardType == null || !allowWildcard) {
                        throw new ExprValidationException("Failed to resolve wildcard parameter to a given event type");
                    }

                    childForges[count] = new ExprEvalStreamNumUnd(0, wildcardType.UnderlyingType);
                    childEvalsEventBeanReturnTypesForges[count] = new ExprEvalStreamNumEvent(0);
                    paramTypes[count] = wildcardType.UnderlyingType;
                    allowEventBeanType[count] = true;
                    allConstants = false;
                    count++;
                    continue;
                }

                if (childNode is ExprStreamUnderlyingNode) {
                    var und = (ExprStreamUnderlyingNode) childNode;
                    var tableMetadata = services.TableCompileTimeResolver.ResolveTableFromEventType(und.EventType);
                    if (tableMetadata == null) {
                        childForges[count] = childNode.Forge;
                        childEvalsEventBeanReturnTypesForges[count] = new ExprEvalStreamNumEvent(und.StreamId);
                    }
                    else {
                        childForges[count] = new ExprEvalStreamTable(
                            und.StreamId,
                            und.EventType.UnderlyingType,
                            tableMetadata);
                        childEvalsEventBeanReturnTypesForges[count] =
                            new ExprEvalStreamNumEventTable(und.StreamId, tableMetadata);
                    }

                    paramTypes[count] = childForges[count].EvaluationType;
                    allowEventBeanType[count] = true;
                    allConstants = false;
                    count++;
                    continue;
                }

                if (childNode.Forge is ExprEnumerationForge) {
                    var enumeration = (ExprEnumerationForge) childNode.Forge;
                    var eventType = enumeration.GetEventTypeSingle(statementRawInfo, services);
                    childForges[count] = childNode.Forge;
                    paramTypes[count] = childForges[count].EvaluationType;
                    allConstants = false;
                    if (eventType != null) {
                        childEvalsEventBeanReturnTypesForges[count] = new ExprEvalStreamNumEnumSingleForge(enumeration);
                        allowEventBeanType[count] = true;
                        count++;
                        continue;
                    }

                    var eventTypeColl = enumeration.GetEventTypeCollection(statementRawInfo, services);
                    if (eventTypeColl != null) {
                        childEvalsEventBeanReturnTypesForges[count] = new ExprEvalStreamNumEnumCollForge(enumeration);
                        allowEventBeanCollType[count] = true;
                        count++;
                        continue;
                    }
                }

                paramTypes[count] = childNode.Forge.EvaluationType;
                childForges[count] = childNode.Forge;
                count++;
                if (!childNode.Forge.ForgeConstantType.IsCompileTimeConstant) {
                    allConstants = false;
                }
            }

            // Try to resolve the method
            MethodInfo method;
            try {
                if (optionalClass != null) {
                    method = services.ImportServiceCompileTime.ResolveMethod(
                        optionalClass,
                        methodName,
                        paramTypes,
                        allowEventBeanType);
                }
                else {
                    method = services.ImportServiceCompileTime.ResolveMethodOverloadChecked(
                        className,
                        methodName,
                        paramTypes,
                        allowEventBeanType,
                        allowEventBeanCollType,
                        services.ClassProvidedExtension);
                }
            }
            catch (Exception e) {
                throw exceptionHandler.Handle(e);
            }

            var parameterTypes = method.GetParameterTypes();
            
            // rewrite those evaluator that should return the event itself
            if (CollectionUtil.IsAnySet(allowEventBeanType)) {
                for (var i = 0; i < parameters.Count; i++) {
                    if (allowEventBeanType[i] && parameterTypes[i] == typeof(EventBean)) {
                        childForges[i] = childEvalsEventBeanReturnTypesForges[i];
                    }
                }
            }

            // rewrite those evaluators that should return the event collection
            if (CollectionUtil.IsAnySet(allowEventBeanCollType)) {
                for (var i = 0; i < parameters.Count; i++) {
                    if (allowEventBeanCollType[i] && (parameterTypes[i] == typeof(ICollection<EventBean>))) {
                        childForges[i] = childEvalsEventBeanReturnTypesForges[i];
                    }
                }
            }

            // add an evaluator if the method expects a context object
            if (!method.IsVarArgs() &&
                parameterTypes.Length > 0 &&
                parameterTypes[parameterTypes.Length - 1] == typeof(EPLMethodInvocationContext)) {
                var node = new ExprEvalMethodContext(functionName);
                childForges = (ExprForge[]) CollectionUtil.ArrayExpandAddSingle(childForges, node);
            }

            // handle varargs
            if (method.IsVarArgs()) {
                // handle context parameter
                var numMethodParams = parameterTypes.Length;
                if (numMethodParams > 1 && parameterTypes[numMethodParams - 2] == typeof(EPLMethodInvocationContext)) {
                    var rewrittenForges = new ExprForge[childForges.Length + 1];
                    Array.Copy(childForges, 0, rewrittenForges, 0, numMethodParams - 2);
                    rewrittenForges[numMethodParams - 2] = new ExprEvalMethodContext(functionName);
                    Array.Copy(
                        childForges,
                        numMethodParams - 2,
                        rewrittenForges,
                        numMethodParams - 1,
                        childForges.Length - (numMethodParams - 2));
                    childForges = rewrittenForges;
                }

                childForges = ExprNodeUtilityMake.MakeVarargArrayForges(method, childForges);
            }

            var localInlinedClass = services.ClassProvidedExtension.IsLocalInlinedClass(method.DeclaringType);
            return new ExprNodeUtilMethodDesc(allConstants, childForges, method, localInlinedClass);
        }