Ejemplo n.º 1
0
        protected internal static ExprNode ValidateJoinNamedWindow(
            ExprNodeOrigin exprNodeOrigin,
            ExprNode deleteJoinExpr,
            EventType namedWindowType,
            string namedWindowStreamName,
            string namedWindowName,
            EventType filteredType,
            string filterStreamName,
            string filteredTypeName,
            string optionalTableName,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices compileTimeServices
        )
        {
            if (deleteJoinExpr == null) {
                return null;
            }

            var namesAndTypes = new LinkedHashMap<string, Pair<EventType, string>>();
            namesAndTypes.Put(namedWindowStreamName, new Pair<EventType, string>(namedWindowType, namedWindowName));
            namesAndTypes.Put(filterStreamName, new Pair<EventType, string>(filteredType, filteredTypeName));
            StreamTypeService typeService = new StreamTypeServiceImpl(namesAndTypes, false, false);

            var validationContext = new ExprValidationContextBuilder(typeService, statementRawInfo, compileTimeServices)
                .WithAllowBindingConsumption(true)
                .Build();
            return ExprNodeUtilityValidate.GetValidatedSubtree(exprNodeOrigin, deleteJoinExpr, validationContext);
        }
Ejemplo n.º 2
0
        public static IList<ExprNode> ValidateAllowSubquery(
            ExprNodeOrigin exprNodeOrigin,
            IList<ExprNode> exprNodes,
            StreamTypeService streamTypeService,
            IDictionary<string, Pair<EventType, string>> taggedEventTypes,
            IDictionary<string, Pair<EventType, string>> arrayEventTypes,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            IList<ExprNode> validatedNodes = new List<ExprNode>();

            ExprValidationContext validationContext =
                new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services)
                    .WithAllowBindingConsumption(true)
                    .WithIsFilterExpression(true)
                    .Build();
            foreach (var node in exprNodes) {
                // Determine subselects
                var visitor = new ExprNodeSubselectDeclaredDotVisitor();
                node.Accept(visitor);

                // Compile subselects
                if (!visitor.Subselects.IsEmpty()) {
                    // The outer event type is the filtered-type itself
                    foreach (var subselect in visitor.Subselects) {
                        try {
                            SubSelectHelperFilters.HandleSubselectSelectClauses(
                                subselect,
                                streamTypeService.EventTypes[0],
                                streamTypeService.StreamNames[0],
                                streamTypeService.StreamNames[0],
                                taggedEventTypes,
                                arrayEventTypes,
                                statementRawInfo,
                                services);
                        }
                        catch (ExprValidationException ex) {
                            throw new ExprValidationException(
                                "Failed to validate " +
                                ExprNodeUtilityMake.GetSubqueryInfoText(subselect) +
                                ": " +
                                ex.Message,
                                ex);
                        }
                    }
                }

                var validated = ExprNodeUtilityValidate.GetValidatedSubtree(exprNodeOrigin, node, validationContext);
                validatedNodes.Add(validated);

                if (validated.Forge.EvaluationType != typeof(bool?) && validated.Forge.EvaluationType != typeof(bool)) {
                    throw new ExprValidationException(
                        "Filter expression not returning a boolean value: '" +
                        ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(validated) +
                        "'");
                }
            }

            return validatedNodes;
        }
        internal static ExprNode ValidateExprNoAgg(
            ExprNodeOrigin exprNodeOrigin,
            ExprNode exprNode,
            StreamTypeService streamTypeService,
            StatementContext statementContext,
            ExprEvaluatorContext exprEvaluatorContext,
            String errorMsg,
            bool allowTableConsumption)
        {
            var validationContext = new ExprValidationContext(
                streamTypeService,
                statementContext.MethodResolutionService, null,
                statementContext.SchedulingService,
                statementContext.VariableService,
                statementContext.TableService,
                exprEvaluatorContext,
                statementContext.EventAdapterService,
                statementContext.StatementName,
                statementContext.StatementId,
                statementContext.Annotations,
                statementContext.ContextDescriptor,
                statementContext.ScriptingService,
                false, false,
                allowTableConsumption, false,
                null, false);
            var validated = ExprNodeUtility.GetValidatedSubtree(exprNodeOrigin, exprNode, validationContext);

            ValidateNoAggregations(validated, errorMsg);
            return(validated);
        }
Ejemplo n.º 4
0
 public static void ValidatePlainExpression(
     ExprNodeOrigin origin,
     ExprNode expression)
 {
     ExprNodeSummaryVisitor summaryVisitor = new ExprNodeSummaryVisitor();
     ValidatePlainExpression(origin, expression, summaryVisitor);
 }
Ejemplo n.º 5
0
        public static object InstantiatePopulateObject(
            IDictionary<string, object> objectProperties,
            Type topClass,
            ExprNodeOrigin exprNodeOrigin,
            ExprValidationContext exprValidationContext)
        {
            var applicableClass = topClass;
            if (topClass.IsInterface) {
                applicableClass = FindInterfaceImplementation(
                    objectProperties,
                    topClass,
                    exprValidationContext.ImportService);
            }

            object top;
            try {
                top = TypeHelper.Instantiate(applicableClass);
            }
            catch (EPException) {
                throw;
            }
            catch (Exception ex) {
                throw new ExprValidationException(
                    "Exception instantiating class " + applicableClass.Name + ": " + ex.Message,
                    ex);
            }

            PopulateObject(objectProperties, top, exprNodeOrigin, exprValidationContext);

            return top;
        }
Ejemplo n.º 6
0
        public static void PopulateSpecCheckParameters(
            PopulateFieldWValueDescriptor[] descriptors,
            IDictionary<string, object> jsonRaw,
            object spec,
            ExprNodeOrigin exprNodeOrigin,
            ExprValidationContext exprValidationContext)
        {
            // lowercase keys
            IDictionary<string, object> lowerCaseJsonRaw = new LinkedHashMap<string, object>();
            foreach (var entry in jsonRaw) {
                lowerCaseJsonRaw.Put(entry.Key.ToLowerInvariant(), entry.Value);
            }

            jsonRaw = lowerCaseJsonRaw;

            // apply values
            foreach (var desc in descriptors) {
                object value = jsonRaw.Delete(desc.PropertyName.ToLowerInvariant());
                var coerced = CoerceProperty(
                    desc.PropertyName,
                    desc.ContainerType,
                    value,
                    desc.FieldType,
                    exprNodeOrigin,
                    exprValidationContext,
                    desc.IsForceNumeric,
                    false);
                desc.Setter.Invoke(coerced);
            }

            // should not have remaining parameters
            if (!jsonRaw.IsEmpty()) {
                throw new ExprValidationException("Unrecognized parameter '" + jsonRaw.Keys.First() + "'");
            }
        }
Ejemplo n.º 7
0
 public override void Validate(
     ExprNodeOrigin origin,
     ExprValidationContext validationContext)
 {
     Expression = GetValidatedSubtree(origin, Expression, validationContext);
     EPStatementStartMethodHelperValidate.ValidateNoAggregations(Expression, ValidationAggMsg);
 }
Ejemplo n.º 8
0
        public static ExprForge[] CrontabScheduleValidate(
            ExprNodeOrigin origin,
            IList<ExprNode> scheduleSpecExpressionList,
            bool allowBindingConsumption,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            // Validate the expressions
            ExprForge[] expressions = new ExprForge[scheduleSpecExpressionList.Count];
            int count = 0;
            ExprValidationContext validationContext =
                new ExprValidationContextBuilder(new StreamTypeServiceImpl(false), statementRawInfo, services)
                    .WithAllowBindingConsumption(allowBindingConsumption)
                    .Build();
            foreach (ExprNode parameters in scheduleSpecExpressionList) {
                ExprNode node = ExprNodeUtilityValidate.GetValidatedSubtree(origin, parameters, validationContext);
                expressions[count++] = node.Forge;
            }

            if (expressions.Length <= 4 || expressions.Length >= 8) {
                throw new ExprValidationException(
                    "Invalid schedule specification: " +
                    ScheduleSpecUtil.GetExpressionCountException(expressions.Length));
            }

            return expressions;
        }
Ejemplo n.º 9
0
 public static ExprValidationException MakeValidationExWExpression(
     ExprNodeOrigin origin,
     String text,
     ExprValidationException ex)
 {
     return new ExprValidationException(
         $"Failed to validate {origin.GetClauseName()} expression {text}: {ex.Message}",
         ex);
 }
Ejemplo n.º 10
0
 public static void ValidatePlainExpression(
     ExprNodeOrigin origin,
     ExprNode[] expressions)
 {
     ExprNodeSummaryVisitor summaryVisitor = new ExprNodeSummaryVisitor();
     foreach (ExprNode expression in expressions) {
         ValidatePlainExpression(origin, expression, summaryVisitor);
     }
 }
Ejemplo n.º 11
0
 public override void Validate(
     ExprNodeOrigin origin,
     ExprValidationContext validationContext)
 {
     var index = _indexExpressions[0];
     index = ExprNodeUtilityValidate.GetValidatedSubtree(origin, index, validationContext);
     _indexExpressions = Collections.SingletonList(index);
     ChainableArray.ValidateSingleIndexExpr(_indexExpressions, () => "expression '" + Ident + "'");
     EPStatementStartMethodHelperValidate.ValidateNoAggregations(index, ExprAssignment.ValidationAggMsg);
 }
Ejemplo n.º 12
0
 public static void Validate(
     ExprNodeOrigin origin,
     IList<Chainable> chainSpec,
     ExprValidationContext validationContext)
 {
     // validate all parameters
     foreach (var chainElement in chainSpec) {
         chainElement.Validate(origin, validationContext);
     }
 }
Ejemplo n.º 13
0
        public void Validate(
            ExprNodeOrigin origin,
            ExprValidationContext validationContext)
        {
            foreach (var node in GetParametersOrEmpty()) {
                if (node is ExprNamedParameterNode) {
                    throw new ExprValidationException("Named parameters are not allowed");
                }
            }

            ValidateExpressions(origin, validationContext);
        }
Ejemplo n.º 14
0
        public static void GetValidatedSubtree(
            ExprNodeOrigin origin,
            ExprNode[][] exprNode,
            ExprValidationContext validationContext)
        {
            if (exprNode == null) {
                return;
            }

            foreach (ExprNode[] anExprNode in exprNode) {
                GetValidatedSubtree(origin, anExprNode, validationContext);
            }
        }
Ejemplo n.º 15
0
        public static void GetValidatedSubtree(
            ExprNodeOrigin origin,
            ExprNode[] exprNode,
            ExprValidationContext validationContext)
        {
            if (exprNode == null) {
                return;
            }

            for (int i = 0; i < exprNode.Length; i++) {
                exprNode[i] = GetValidatedSubtree(origin, exprNode[i], validationContext);
            }
        }
Ejemplo n.º 16
0
 internal static void ValidateExpressions(
     IList<ExprNode> expressions,
     ExprNodeOrigin origin,
     ExprValidationContext validationContext)
 {
     for (var i = 0; i < expressions.Count; i++) {
         var node = expressions[i];
         var validated = GetValidatedSubtree(origin, node, validationContext);
         if (node != validated) {
             expressions[i] = validated;
         }
     }
 }
Ejemplo n.º 17
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;
            }
        }
Ejemplo n.º 18
0
        private static IList<ExprNode> ValidateExpressions(
            ExprNodeOrigin exprNodeOrigin,
            IList<ExprNode> objectParameters,
            ExprValidationContext validationContext)
        {
            if (objectParameters == null) {
                return objectParameters;
            }

            IList<ExprNode> validated = new List<ExprNode>();
            foreach (var node in objectParameters) {
                validated.Add(ExprNodeUtilityValidate.GetValidatedSubtree(exprNodeOrigin, node, validationContext));
            }

            return validated;
        }
Ejemplo n.º 19
0
        public static void ValidateAssignment(
            bool allowLHSVariables,
            ExprNodeOrigin origin,
            OnTriggerSetAssignment spec,
            ExprValidationContext validationContext)
        {
            // equals-assignments are "a=1" and "a[1]=2" and such
            // they are not "a.reset()"
            var assignment = CheckGetStraightAssignment(spec.Expression, allowLHSVariables);
            if (assignment == null) {
                assignment = new ExprAssignmentCurly(spec.Expression);
            }

            assignment.Validate(origin, validationContext);
            spec.Validated = assignment;
        }
Ejemplo n.º 20
0
        public static Object ParsePopulate(String json, Type topClass, ExprNodeOrigin exprNodeOrigin, ExprValidationContext exprValidationContext)
        {
            var startRuleSelector = new ParseRuleSelector(parser => parser.startJsonValueRule());
            var parseResult       = ParseHelper.Parse(json, json, true, startRuleSelector, false);
            var tree   = (EsperEPL2GrammarParser.StartJsonValueRuleContext)parseResult.Tree;
            var parsed = ASTJsonHelper.Walk(parseResult.TokenStream, tree.jsonvalue());

            if (!(parsed is IDictionary <String, Object>))
            {
                throw new ExprValidationException(
                          "Failed to map value to object of type " + topClass.FullName +
                          ", expected Json Map/Object format, received " + (parsed != null ? parsed.GetType().Name : "null"));
            }
            var objectProperties = (IDictionary <String, Object>)parsed;

            return(PopulateUtil.InstantiatePopulateObject(objectProperties, topClass, exprNodeOrigin, exprValidationContext));
        }
Ejemplo n.º 21
0
 public static ExprNode ValidateExprNoAgg(
     ExprNodeOrigin exprNodeOrigin,
     ExprNode exprNode,
     StreamTypeService streamTypeService,
     string errorMsg,
     bool allowTableConsumption,
     bool allowTableAggReset,
     StatementRawInfo raw,
     StatementCompileTimeServices compileTimeServices)
 {
     var validationContext = new ExprValidationContextBuilder(streamTypeService, raw, compileTimeServices)
             .WithAllowBindingConsumption(allowTableConsumption)
             .WithAllowTableAggReset(allowTableAggReset)
             .Build();
     var validated = ExprNodeUtilityValidate.GetValidatedSubtree(exprNodeOrigin, exprNode, validationContext);
     ValidateNoAggregations(validated, errorMsg);
     return validated;
 }
Ejemplo n.º 22
0
        public static void Validate(
            ExprNodeOrigin origin,
            IList<ExprChainedSpec> chainSpec,
            ExprValidationContext validationContext)
        {
            // validate all parameters
            foreach (ExprChainedSpec chainElement in chainSpec) {
                IList<ExprNode> validated = new List<ExprNode>();
                foreach (ExprNode expr in chainElement.Parameters) {
                    validated.Add(GetValidatedSubtree(origin, expr, validationContext));
                    if (expr is ExprNamedParameterNode) {
                        throw new ExprValidationException("Named parameters are not allowed");
                    }
                }

                chainElement.Parameters = validated;
            }
        }
Ejemplo n.º 23
0
 private static void ValidatePlainExpression(
     ExprNodeOrigin origin,
     ExprNode expression,
     ExprNodeSummaryVisitor summaryVisitor)
 {
     expression.Accept(summaryVisitor);
     if (summaryVisitor.HasAggregation ||
         summaryVisitor.HasSubselect ||
         summaryVisitor.HasStreamSelect ||
         summaryVisitor.HasPreviousPrior) {
         string text = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(expression);
         throw new ExprValidationException(
             "Invalid " +
             origin.GetClauseName() +
             " expression '" +
             text +
             "': Aggregation, sub-select, previous or prior functions are not supported in this context");
     }
 }
Ejemplo n.º 24
0
        public static ExprNode ValidateSimpleGetSubtree(
            ExprNodeOrigin origin,
            ExprNode expression,
            EventType optionalEventType,
            bool allowBindingConsumption,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            ExprNodeUtilityValidate.ValidatePlainExpression(origin, expression);

            StreamTypeServiceImpl streamTypes;
            if (optionalEventType != null) {
                streamTypes = new StreamTypeServiceImpl(optionalEventType, null, true);
            }
            else {
                streamTypes = new StreamTypeServiceImpl(false);
            }

            var validationContext = new ExprValidationContextBuilder(streamTypes, statementRawInfo, services)
                .WithAllowBindingConsumption(allowBindingConsumption)
                .Build();
            return ExprNodeUtilityValidate.GetValidatedSubtree(origin, expression, validationContext);
        }
 public override void Validate(
     ExprNodeOrigin origin,
     ExprValidationContext validationContext)
 {
     // specific validation by assignor
 }
Ejemplo n.º 26
0
        public static void PopulateObject(
            IDictionary<string, object> objectProperties,
            object top,
            ExprNodeOrigin exprNodeOrigin,
            ExprValidationContext exprValidationContext)
        {
            var applicableClass = top.GetType();
            var writables = PropertyHelper.GetWritableProperties(applicableClass);
            var annotatedFields = TypeHelper.FindAnnotatedFields(top.GetType(), typeof(DataFlowOpParameterAttribute));
            var annotatedMethods = TypeHelper.FindAnnotatedMethods(top.GetType(), typeof(DataFlowOpParameterAttribute));

            // find catch-all methods
            ISet<MethodInfo> catchAllMethods = new LinkedHashSet<MethodInfo>();
            if (annotatedMethods != null) {
                foreach (var method in annotatedMethods) {
                    var anno = (DataFlowOpParameterAttribute) TypeHelper
                        .GetAnnotations<DataFlowOpParameterAttribute>(method.UnwrapAttributes())[0];
                    if (anno.IsAll) {
                        var parameters = method.GetParameters();
                        if (parameters.Length == 2 &&
                            (parameters[0].ParameterType == typeof(string)) &&
                            (parameters[1].ParameterType == typeof(object))) {
                            catchAllMethods.Add(method);
                            continue;
                        }

                        throw new ExprValidationException("Invalid annotation for catch-call");
                    }
                }
            }

            // map provided values
            foreach (var property in objectProperties) {
                var found = false;
                var propertyName = property.Key;

                // invoke catch-all setters
                foreach (var method in catchAllMethods) {
                    try {
                        method.Invoke(top, new[] {propertyName, property.Value});
                    }
                    catch (MemberAccessException e) {
                        throw new ExprValidationException(
                            "Illegal access invoking method for property '" +
                            propertyName +
                            "' for class " +
                            applicableClass.Name +
                            " method " +
                            method.Name,
                            e);
                    }
                    catch (TargetException e) {
                        throw new ExprValidationException(
                            "Exception invoking method for property '" +
                            propertyName +
                            "' for class " +
                            applicableClass.Name +
                            " method " +
                            method.Name +
                            ": " +
                            e.InnerException.Message,
                            e);
                    }

                    found = true;
                }

                if (propertyName.ToLowerInvariant().Equals(CLASS_PROPERTY_NAME)) {
                    continue;
                }

                // use the writeable property descriptor (appropriate setter method) from writing the property
                var descriptor = FindDescriptor(applicableClass, propertyName, writables);
                if (descriptor != null) {
                    var coerceProperty = CoerceProperty(
                        propertyName,
                        applicableClass,
                        property.Value,
                        descriptor.PropertyType,
                        exprNodeOrigin,
                        exprValidationContext,
                        false,
                        true);

                    try {
                        var writeMember = descriptor.WriteMember;
                        if (writeMember is MethodInfo writeMethod) {
                            writeMethod.Invoke(top, new[] {coerceProperty});
                        }
                        else if (writeMember is PropertyInfo writeProperty) {
                            writeProperty.SetValue(top, coerceProperty);
                        }
                        else {
                            throw new IllegalStateException("writeMember of invalid type");
                        }
                    }
                    catch (ArgumentException e) {
                        throw new ExprValidationException(
                            "Illegal argument invoking setter method for property '" +
                            propertyName +
                            "' for class " +
                            applicableClass.Name +
                            " method " +
                            descriptor.WriteMember.Name +
                            " provided value " +
                            coerceProperty,
                            e);
                    }
                    catch (MemberAccessException e) {
                        throw new ExprValidationException(
                            "Illegal access invoking setter method for property '" +
                            propertyName +
                            "' for class " +
                            applicableClass.Name +
                            " method " +
                            descriptor.WriteMember.Name,
                            e);
                    }
                    catch (TargetException e) {
                        throw new ExprValidationException(
                            "Exception invoking setter method for property '" +
                            propertyName +
                            "' for class " +
                            applicableClass.Name +
                            " method " +
                            descriptor.WriteMember.Name +
                            ": " +
                            e.InnerException.Message,
                            e);
                    }

                    continue;
                }

                // find the field annotated with {@link @GraphOpProperty}
                foreach (var annotatedField in annotatedFields) {
                    var anno = (DataFlowOpParameterAttribute) TypeHelper.GetAnnotations(
                        typeof(DataFlowOpParameterAttribute),
                        annotatedField.UnwrapAttributes())[0];
                    if (anno.Name.Equals(propertyName) || annotatedField.Name.Equals(propertyName)) {
                        var coerceProperty = CoerceProperty(
                            propertyName,
                            applicableClass,
                            property.Value,
                            annotatedField.FieldType,
                            exprNodeOrigin,
                            exprValidationContext,
                            true,
                            true);
                        try {
                            annotatedField.SetValue(top, coerceProperty);
                        }
                        catch (Exception e) {
                            throw new ExprValidationException(
                                "Failed to set field '" + annotatedField.Name + "': " + e.Message,
                                e);
                        }

                        found = true;
                        break;
                    }
                }

                if (found) {
                    continue;
                }

                throw new ExprValidationException(
                    "Failed to find writable property '" + propertyName + "' for class " + applicableClass.Name);
            }
        }
Ejemplo n.º 27
0
        public static object CoerceProperty(
            string propertyName,
            Type containingType,
            object value,
            Type type,
            ExprNodeOrigin exprNodeOrigin,
            ExprValidationContext exprValidationContext,
            bool forceNumeric,
            bool includeClassNameInEx)
        {
            // handle system-property exception
            if (value is ExprNode) {
                if (value is ExprIdentNode) {
                    var identNode = (ExprIdentNode) value;
                    Property prop;
                    try {
                        prop = PropertyParser.ParseAndWalkLaxToSimple(identNode.FullUnresolvedName);
                    }
                    catch (Exception) {
                        throw new ExprValidationException(
                            "Failed to parse property '" + identNode.FullUnresolvedName + "'");
                    }

                    if (!(prop is MappedProperty)) {
                        throw new ExprValidationException(
                            "Unrecognized property '" + identNode.FullUnresolvedName + "'");
                    }

                    var mappedProperty = (MappedProperty) prop;
                    if (string.Equals(
                        mappedProperty.PropertyNameAtomic,
                        ExprEvalSystemProperty.SYSTEM_PROPETIES_NAME,
                        StringComparison.InvariantCultureIgnoreCase)) {
                        if (type == typeof(ExprNode)) {
                            return new ExprEvalSystemProperty(mappedProperty.Key);
                        }

                        return Environment.GetEnvironmentVariable(mappedProperty.Key);
                    }
                }
                else {
                    var exprNode = (ExprNode) value;
                    if (type == typeof(ExprNode)) {
                        return exprNode;
                    }

                    if (!exprNode.Forge.ForgeConstantType.IsCompileTimeConstant) {
                        throw new ExprValidationException(
                            "Failed to determine parameter for property '" +
                            propertyName +
                            "' as the parameter is not a compile-time constant expression");
                    }

                    value = exprNode.Forge.ExprEvaluator.Evaluate(null, true, null);
                }
            }

            if (value == null) {
                return null;
            }

            var valueType = value.GetType();
            if (valueType == type) {
                return value;
            }

            
            var typeUnboxed = type.GetUnboxedType();
            if (valueType.GetUnboxedType().IsAssignmentCompatible(typeUnboxed)) {
                if (forceNumeric &&
                    value.GetType().GetBoxedType() != type.GetBoxedType() &&
                    type.IsNumeric() &&
                    value.GetType().IsNumeric()) {
                    value = TypeHelper.CoerceBoxed(value, type.GetBoxedType());
                }

                return value;
            }

            if (TypeHelper.IsSubclassOrImplementsInterface(value.GetType(), type)) {
                return value;
            }

            if (type.IsArray) {
                if (!value.GetType().IsGenericCollection()) {
                    var detail = "expects an array but receives a value of type " + value.GetType().Name;
                    throw new ExprValidationException(
                        GetExceptionText(propertyName, containingType, includeClassNameInEx, detail));
                }

                var items = value.UnwrapIntoArray<object>();
                var coercedArray = Arrays.CreateInstanceChecked(type.GetElementType(), items.Length);
                for (var i = 0; i < items.Length; i++) {
                    var coercedValue = CoerceProperty(
                        propertyName + " (array element)",
                        type,
                        items[i],
                        type.GetElementType(),
                        exprNodeOrigin,
                        exprValidationContext,
                        false,
                        includeClassNameInEx);
                    coercedArray.SetValue(coercedValue, i);
                }

                return coercedArray;
            }

            if (!(value is IDictionary<string, object>)) {
                var detail = "expects an " +
                             type.CleanName() +
                             " but receives a value of type " +
                             value.GetType().CleanName();
                throw new ExprValidationException(
                    GetExceptionText(propertyName, containingType, includeClassNameInEx, detail));
            }

            var props = (IDictionary<string, object>) value;
            return InstantiatePopulateObject(props, type, exprNodeOrigin, exprValidationContext);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Validates expression nodes and returns a list of validated nodes.
        /// </summary>
        /// <param name="exprNodeOrigin">The expr node origin.</param>
        /// <param name="exprNodes">is the nodes to validate</param>
        /// <param name="streamTypeService">is provding type information for each stream</param>
        /// <param name="statementContext">context</param>
        /// <param name="taggedEventTypes">pattern tagged types</param>
        /// <param name="arrayEventTypes">@return list of validated expression nodes</param>
        /// <returns>
        /// expr nodes
        /// </returns>
        /// <exception cref="ExprValidationException">
        /// Failed to validate  + EPStatementStartMethodHelperSubselect.GetSubqueryInfoText(count, subselect) + :  + ex.Message
        /// or
        /// Filter expression not returning a boolean value: ' + ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(validated) + '
        /// </exception>
        /// <throws>ExprValidationException for validation errors</throws>
        public static IList <ExprNode> ValidateAllowSubquery(
            ExprNodeOrigin exprNodeOrigin,
            IList <ExprNode> exprNodes,
            StreamTypeService streamTypeService,
            StatementContext statementContext,
            IDictionary <string, Pair <EventType, string> > taggedEventTypes,
            IDictionary <string, Pair <EventType, string> > arrayEventTypes)
        {
            IList <ExprNode> validatedNodes = new List <ExprNode>();

            var evaluatorContextStmt = new ExprEvaluatorContextStatement(statementContext, false);
            var validationContext    = new ExprValidationContext(
                streamTypeService, statementContext.MethodResolutionService, null, statementContext.TimeProvider,
                statementContext.VariableService,
                statementContext.TableService,
                evaluatorContextStmt,
                statementContext.EventAdapterService,
                statementContext.StatementName,
                statementContext.StatementId,
                statementContext.Annotations,
                statementContext.ContextDescriptor,
                statementContext.ScriptingService,
                false, false, true, false, null, true);

            foreach (var node in exprNodes)
            {
                // Determine subselects
                var visitor = new ExprNodeSubselectDeclaredDotVisitor();
                node.Accept(visitor);

                // Compile subselects
                if (!visitor.Subselects.IsEmpty())
                {
                    // The outer event type is the filtered-type itself
                    var subselectStreamNumber = 2048;
                    var count = -1;
                    foreach (var subselect in visitor.Subselects)
                    {
                        count++;
                        subselectStreamNumber++;
                        try {
                            HandleSubselectSelectClauses(subselectStreamNumber, statementContext, subselect,
                                                         streamTypeService.EventTypes[0], streamTypeService.StreamNames[0], streamTypeService.StreamNames[0],
                                                         taggedEventTypes, arrayEventTypes);
                        }
                        catch (ExprValidationException ex) {
                            throw new ExprValidationException("Failed to validate " + EPStatementStartMethodHelperSubselect.GetSubqueryInfoText(count, subselect) + ": " + ex.Message, ex);
                        }
                    }
                }

                var validated = ExprNodeUtility.GetValidatedSubtree(exprNodeOrigin, node, validationContext);
                validatedNodes.Add(validated);

                if ((validated.ExprEvaluator.ReturnType != typeof(bool?)) && ((validated.ExprEvaluator.ReturnType != typeof(bool))))
                {
                    throw new ExprValidationException("Filter expression not returning a boolean value: '" + ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(validated) + "'");
                }
            }

            return(validatedNodes);
        }
Ejemplo n.º 29
0
        public static string GetClauseName(this ExprNodeOrigin enumValue)
        {
            switch (enumValue)
            {
            case ExprNodeOrigin.SELECT:
                return("select-clause");

            case ExprNodeOrigin.WHERE:
                return("where-clause");

            case ExprNodeOrigin.GROUPBY:
                return("group-by-clause");

            case ExprNodeOrigin.HAVING:
                return("having-clause");

            case ExprNodeOrigin.METHODINVJOIN:
                return("from-clause method-invocation");

            case ExprNodeOrigin.DATABASEPOLL:
                return("from-clause database-access parameter");

            case ExprNodeOrigin.CONTEXT:
                return("context declaration");

            case ExprNodeOrigin.CONTEXTDISTINCT:
                return("context distinct-clause");

            case ExprNodeOrigin.CONTEXTCONDITION:
                return("context condition");

            case ExprNodeOrigin.VARIABLEASSIGN:
                return("variable-assignment");

            case ExprNodeOrigin.DATAFLOW:
                return("dataflow operator");

            case ExprNodeOrigin.DATAFLOWBEACON:
                return("beacon dataflow operator");

            case ExprNodeOrigin.DATAFLOWFILTER:
                return("filter dataflow operator");

            case ExprNodeOrigin.UPDATEASSIGN:
                return("update assignment");

            case ExprNodeOrigin.PLUGINSINGLEROWPARAM:
                return("single-row function parameter");

            case ExprNodeOrigin.AGGPARAM:
                return("aggregation function parameter");

            case ExprNodeOrigin.OUTPUTLIMIT:
                return("output limit");

            case ExprNodeOrigin.DECLAREDEXPRPARAM:
                return("declared expression parameter");

            case ExprNodeOrigin.DECLAREDEXPRBODY:
                return("declared expression body");

            case ExprNodeOrigin.ALIASEXPRBODY:
                return("alias expression body");

            case ExprNodeOrigin.ORDERBY:
                return("order-by-clause");

            case ExprNodeOrigin.SCRIPTPARAMS:
                return("script parameter");

            case ExprNodeOrigin.FOLLOWEDBYMAX:
                return("pattern followed-by max");

            case ExprNodeOrigin.PATTERNMATCHUNTILBOUNDS:
                return("pattern match-until bounds");

            case ExprNodeOrigin.PATTERNGUARD:
                return("pattern guard");

            case ExprNodeOrigin.PATTERNEVERYDISTINCT:
                return("pattern every-distinct");

            case ExprNodeOrigin.PATTERNOBSERVER:
                return("pattern observer");

            case ExprNodeOrigin.DOTNODEPARAMETER:
                return("method-chain parameter");

            case ExprNodeOrigin.DOTNODE:
                return("method-chain");

            case ExprNodeOrigin.CONTAINEDEVENT:
                return("contained-event");

            case ExprNodeOrigin.CREATEWINDOWFILTER:
                return("create-window filter");

            case ExprNodeOrigin.CREATETABLECOLUMN:
                return("table-column");

            case ExprNodeOrigin.CREATEINDEXCOLUMN:
                return("create-index index-column");

            case ExprNodeOrigin.CREATEINDEXPARAMETER:
                return("create-index index-parameter");

            case ExprNodeOrigin.SUBQUERYSELECT:
                return("subquery select-clause");

            case ExprNodeOrigin.FILTER:
                return("filter");

            case ExprNodeOrigin.FORCLAUSE:
                return("for-clause");

            case ExprNodeOrigin.VIEWPARAMETER:
                return("view parameter");

            case ExprNodeOrigin.MATCHRECOGDEFINE:
                return("match-recognize define");

            case ExprNodeOrigin.MATCHRECOGMEASURE:
                return("match-recognize measure");

            case ExprNodeOrigin.MATCHRECOGPARTITION:
                return("match-recognize partition");

            case ExprNodeOrigin.MATCHRECOGINTERVAL:
                return("match-recognize interval");

            case ExprNodeOrigin.MATCHRECOGPATTERN:
                return("match-recognize pattern");

            case ExprNodeOrigin.JOINON:
                return("on-clause join");

            case ExprNodeOrigin.MERGEMATCHCOND:
                return("match condition");

            case ExprNodeOrigin.MERGEMATCHWHERE:
                return("match where-clause");

            case ExprNodeOrigin.HINT:
                return("hint");
            }

            throw new ArgumentException("invalid value for enumValue", "enumValue");
        }
Ejemplo n.º 30
0
 public override void ValidateExpressions(
     ExprNodeOrigin origin,
     ExprValidationContext validationContext)
 {
     ValidateExpressions(Parameters, origin, validationContext);
 }