Пример #1
0
        private static CreateSchemaDesc GetSchemaDesc(EsperEPL2GrammarParser.CreateSchemaDefContext ctx, AssignedType assignedType)
        {
            var schemaName  = ctx.name.Text;
            var columnTypes = GetColTypeList(ctx.createColumnList());

            // get model-after types (could be multiple for variants)
            ISet <string> typeNames = new LinkedHashSet <string>();

            if (ctx.variantList() != null)
            {
                IList <EsperEPL2GrammarParser.VariantListElementContext> variantCtxs = ctx.variantList().variantListElement();
                foreach (var variantCtx in variantCtxs)
                {
                    typeNames.Add(variantCtx.GetText().UnmaskTypeName());
                }
            }

            // get inherited and start timestamp and end timestamps
            string        startTimestamp = null;
            string        endTimestamp   = null;
            ISet <string> inherited      = new LinkedHashSet <string>();
            ISet <string> copyFrom       = new LinkedHashSet <string>();

            if (ctx.createSchemaQual() != null)
            {
                IList <EsperEPL2GrammarParser.CreateSchemaQualContext> qualCtxs = ctx.createSchemaQual();
                foreach (var qualCtx in qualCtxs)
                {
                    var qualName      = qualCtx.i.Text.ToLower();
                    var cols          = ASTUtil.GetIdentList(qualCtx.columnList());
                    var qualNameLower = qualName.ToLower();
                    switch (qualNameLower)
                    {
                    case "inherits":
                        inherited.AddAll(cols);
                        continue;

                    case "starttimestamp":
                        startTimestamp = cols[0];
                        continue;

                    case "endtimestamp":
                        endTimestamp = cols[0];
                        continue;

                    case "copyfrom":
                        copyFrom.AddAll(cols);
                        continue;
                    }
                    throw new EPException("Expected 'inherits', 'starttimestamp', 'endtimestamp' or 'copyfrom' keyword after create-schema clause but encountered '" + qualName + "'");
                }
            }

            return(new CreateSchemaDesc(schemaName, typeNames, columnTypes, inherited, assignedType, startTimestamp, endTimestamp, copyFrom));
        }
Пример #2
0
        internal static IList <string> GetLambdaGoesParams(EsperEPL2GrammarParser.ExpressionLambdaDeclContext ctx)
        {
            IList <string> parameters;

            if (ctx.i != null)
            {
                parameters = new List <string>(1);
                parameters.Add(ctx.i.Text);
            }
            else
            {
                parameters = ASTUtil.GetIdentList(ctx.columnList());
            }
            return(parameters);
        }
Пример #3
0
        public static Pair <ExpressionDeclItem, ExpressionScriptProvided> WalkExpressionDecl(
            EsperEPL2GrammarParser.ExpressionDeclContext ctx,
            IList <String> scriptBodies,
            IDictionary <ITree, ExprNode> astExprNodeMap,
            CommonTokenStream tokenStream)
        {
            var name = ctx.name.Text;

            if (ctx.alias != null)
            {
                if (ctx.alias.Text.ToLower().Trim() != "alias")
                {
                    throw ASTWalkException.From("For expression alias '" + name + "' expecting 'alias' keyword but received '" + ctx.alias.Text + "'");
                }
                if (ctx.columnList() != null)
                {
                    throw ASTWalkException.From("For expression alias '" + name + "' expecting no parameters but received '" + tokenStream.GetText(ctx.columnList()) + "'");
                }
                if (ctx.expressionDef() != null && ctx.expressionDef().expressionLambdaDecl() != null)
                {
                    throw ASTWalkException.From("For expression alias '" + name + "' expecting an expression without parameters but received '" + tokenStream.GetText(ctx.expressionDef().expressionLambdaDecl()) + "'");
                }
                if (ctx.expressionDef().stringconstant() != null)
                {
                    throw ASTWalkException.From("For expression alias '" + name + "' expecting an expression but received a script");
                }
                var exprNode = ASTExprHelper.ExprCollectSubNodes(ctx, 0, astExprNodeMap)[0];
                var alias    = ctx.name.Text;
                var decl     = new ExpressionDeclItem(alias, Collections.GetEmptyList <String>(), exprNode, true);
                return(new Pair <ExpressionDeclItem, ExpressionScriptProvided>(decl, null));
            }

            if (ctx.expressionDef().stringconstant() != null)
            {
                var expressionText = scriptBodies[0];
                scriptBodies.RemoveAt(0);
                var parameters         = ASTUtil.GetIdentList(ctx.columnList());
                var optionalReturnType = ctx.classIdentifier() == null
                    ? null
                    : ASTUtil.UnescapeClassIdent(ctx.classIdentifier());
                var optionalReturnTypeArray = ctx.array != null;
                var optionalDialect         = ctx.expressionDialect() == null ? null : ctx.expressionDialect().d.Text;
                var script = new ExpressionScriptProvided(
                    name, expressionText, parameters,
                    optionalReturnType, optionalReturnTypeArray, optionalDialect);
                return(new Pair <ExpressionDeclItem, ExpressionScriptProvided>(null, script));
            }

            var ctxexpr = ctx.expressionDef();
            var inner   = ASTExprHelper.ExprCollectSubNodes(ctxexpr.expression(), 0, astExprNodeMap)[0];

            var parametersNames = Collections.GetEmptyList <string>();
            var lambdactx       = ctxexpr.expressionLambdaDecl();

            if (ctxexpr.expressionLambdaDecl() != null)
            {
                parametersNames = ASTLibFunctionHelper.GetLambdaGoesParams(lambdactx);
            }

            var expr = new ExpressionDeclItem(name, parametersNames, inner, false);

            return(new Pair <ExpressionDeclItem, ExpressionScriptProvided>(expr, null));
        }