示例#1
0
        private compat.collections.Pair<ExprAggregateNode, IList<StmtClassForgeableFactory>> ValidateAggregationExpr(
            ExprNode columnExpressionType,
            EventType optionalProvidedType,
            StatementCompileTimeServices services)
        {
            var classpathImportService = services.ImportServiceCompileTime;

            // determine validation context types and istream/irstream
            EventType[] types;
            string[] streamNames;
            bool[] istreamOnly;
            if (optionalProvidedType != null) {
                types = new[] {optionalProvidedType};
                streamNames = new[] {types[0].Name};
                istreamOnly = new[] {
                    false
                }; // always false (expected to be bound by data window), use "ever"-aggregation functions otherwise
            }
            else {
                types = new EventType[0];
                streamNames = new string[0];
                istreamOnly = new bool[0];
            }

            var streamTypeService = new StreamTypeServiceImpl(types, streamNames, istreamOnly, false, false);
            var validationContext =
                new ExprValidationContextBuilder(streamTypeService, @base.StatementRawInfo, services).Build();

            // substitute parameter nodes
            foreach (var childNode in columnExpressionType.ChildNodes) {
                if (childNode is ExprIdentNode) {
                    var identNode = (ExprIdentNode) childNode;
                    var propname = identNode.FullUnresolvedName.Trim();
                    var clazz = TypeHelper.GetTypeForSimpleName(
                        propname,
                        classpathImportService.ClassForNameProvider);
                    if (propname.ToLowerInvariant().Trim().Equals("@object")) {
                        clazz = typeof(object);
                    }

                    ImportException ex = null;
                    if (clazz == null) {
                        try {
                            clazz = classpathImportService.ResolveClass(propname, false, services.ClassProvidedExtension);
                        }
                        catch (ImportException e) {
                            ex = e;
                        }
                    }

                    if (clazz != null) {
                        var typeNode = new ExprTypedNoEvalNode(propname, clazz);
                        ExprNodeUtilityModify.ReplaceChildNode(columnExpressionType, identNode, typeNode);
                    }
                    else {
                        if (optionalProvidedType == null) {
                            if (ex != null) {
                                throw new ExprValidationException(
                                    "Failed to resolve type '" + propname + "': " + ex.Message,
                                    ex);
                            }

                            throw new ExprValidationException("Failed to resolve type '" + propname + "'");
                        }
                    }
                }
            }

            // validate
            var validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                ExprNodeOrigin.CREATETABLECOLUMN,
                columnExpressionType,
                validationContext);
            if (!(validated is ExprAggregateNode)) {
                throw new ExprValidationException(
                    "Expression '" +
                    ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(validated) +
                    "' is not an aggregation");
            }

            return new compat.collections.Pair<ExprAggregateNode, IList<StmtClassForgeableFactory>>(
                (ExprAggregateNode) validated,
                validationContext.AdditionalForgeables);
        }
示例#2
0
        private ExprAggregateNode ValidateAggregationExpr(
            ExprNode columnExpressionType,
            EventType optionalProvidedType,
            EPServicesContext services,
            StatementContext statementContext)
        {
            // determine validation context types and istream/irstream
            EventType[] types;
            string[]    streamNames;
            bool[]      istreamOnly;
            if (optionalProvidedType != null)
            {
                types       = new EventType[] { optionalProvidedType };
                streamNames = new string[] { types[0].Name };
                istreamOnly = new bool[] { false }; // always false (expected to be bound by data window), use "ever"-aggregation functions otherwise
            }
            else
            {
                types       = new EventType[0];
                streamNames = new string[0];
                istreamOnly = new bool[0];
            }

            var streamTypeService = new StreamTypeServiceImpl(types, streamNames, istreamOnly, services.EngineURI, false);
            var validationContext = new ExprValidationContext(
                streamTypeService,
                statementContext.EngineImportService,
                statementContext.StatementExtensionServicesContext, null,
                statementContext.SchedulingService,
                statementContext.VariableService, statementContext.TableService,
                new ExprEvaluatorContextStatement(statementContext, false), statementContext.EventAdapterService,
                statementContext.StatementName, statementContext.StatementId, statementContext.Annotations,
                statementContext.ContextDescriptor, statementContext.ScriptingService, false, false, false, false, null, false);

            // substitute parameter nodes
            foreach (var childNode in columnExpressionType.ChildNodes.ToArray())
            {
                if (childNode is ExprIdentNode)
                {
                    var identNode = (ExprIdentNode)childNode;
                    var propname  = identNode.FullUnresolvedName.Trim();
                    var clazz     = TypeHelper.GetTypeForSimpleName(propname);
                    if (propname.ToLower().Trim() == "object")
                    {
                        clazz = typeof(object);
                    }
                    EngineImportException ex = null;
                    if (clazz == null)
                    {
                        try
                        {
                            clazz = services.EngineImportService.ResolveType(propname, false);
                        }
                        catch (EngineImportException e)
                        {
                            ex = e;
                        }
                    }
                    if (clazz != null)
                    {
                        var typeNode = new ExprTypedNoEvalNode(propname, clazz);
                        ExprNodeUtility.ReplaceChildNode(columnExpressionType, identNode, typeNode);
                    }
                    else
                    {
                        if (optionalProvidedType == null)
                        {
                            if (ex != null)
                            {
                                throw new ExprValidationException("Failed to resolve type '" + propname + "': " + ex.Message, ex);
                            }
                            throw new ExprValidationException("Failed to resolve type '" + propname + "'");
                        }
                    }
                }
            }

            // validate
            var validated = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.CREATETABLECOLUMN, columnExpressionType, validationContext);

            if (!(validated is ExprAggregateNode))
            {
                throw new ExprValidationException("Expression '" + validated.ToExpressionStringMinPrecedenceSafe() + "' is not an aggregation");
            }

            return((ExprAggregateNode)validated);
        }