Пример #1
0
        private static GraphOperatorSpec ParseOp(
            EsperEPL2GrammarParser.GopContext ctx,
            IDictionary<ITree, object> astGraphNodeMap,
            ImportServiceCompileTime importService)
        {
            var operatorName = ctx.opName != null ? ctx.opName.Text : ctx.s.Text;

            var input = new GraphOperatorInput();
            if (ctx.gopParams() != null)
            {
                ParseParams(ctx.gopParams(), input);
            }

            var output = new GraphOperatorOutput();
            if (ctx.gopOut() != null)
            {
                ParseOutput(ctx.gopOut(), output);
            }

            GraphOperatorDetail detail = null;
            if (ctx.gopDetail() != null)
            {
                IDictionary<string, object> configs = new LinkedHashMap<string, object>();
                IList<EsperEPL2GrammarParser.GopConfigContext> cfgctxs = ctx.gopDetail().gopConfig();
                foreach (var cfgctx in cfgctxs)
                {
                    string name;
                    object value = astGraphNodeMap.Delete(cfgctx);
                    if (cfgctx.n != null)
                    {
                        name = cfgctx.n.Text;
                    }
                    else
                    {
                        name = "select";
                    }

                    configs.Put(name, value);
                }

                detail = new GraphOperatorDetail(configs);
            }

            IList<AnnotationDesc> annotations;
            if (ctx.annotationEnum() != null)
            {
                IList<EsperEPL2GrammarParser.AnnotationEnumContext> annoctxs = ctx.annotationEnum();
                annotations = new List<AnnotationDesc>();
                foreach (EsperEPL2GrammarParser.AnnotationEnumContext annoctx in annoctxs)
                {
                    annotations.Add(ASTAnnotationHelper.Walk(annoctx, importService));
                }
            }
            else
            {
                annotations = new EmptyList<AnnotationDesc>();
            }

            return new GraphOperatorSpec(operatorName, input, output, detail, annotations);
        }
Пример #2
0
        private static CreateTableColumn GetColumn(
            EsperEPL2GrammarParser.CreateTableColumnContext ctx,
            IDictionary<ITree, ExprNode> astExprNodeMap,
            StatementSpecMapEnv mapEnv)
        {
            var columnName = ctx.n.Text;

            ExprNode optExpression = null;
            if (ctx.builtinFunc() != null || ctx.chainable() != null)
            {
                optExpression = ASTExprHelper.ExprCollectSubNodes(ctx, 0, astExprNodeMap)[0];
            }

            var optType = ASTClassIdentifierHelper.Walk(ctx.classIdentifierWithDimensions());

            var primaryKey = false;
            if (ctx.p != null)
            {
                if (!string.Equals(ctx.p.Text, "primary", StringComparison.InvariantCultureIgnoreCase))
                {
                    throw ASTWalkException.From("Invalid keyword '" + ctx.p.Text + "' encountered, expected 'primary key'");
                }

                if (!string.Equals(ctx.k.Text, "key", StringComparison.InvariantCultureIgnoreCase))
                {
                    throw ASTWalkException.From("Invalid keyword '" + ctx.k.Text + "' encountered, expected 'primary key'");
                }

                primaryKey = true;
            }

            IList<AnnotationDesc> annots = new EmptyList<AnnotationDesc>();
            if (ctx.annotationEnum() != null)
            {
                annots = new List<AnnotationDesc>(ctx.annotationEnum().Length);
                foreach (EsperEPL2GrammarParser.AnnotationEnumContext anctx in ctx.annotationEnum())
                {
                    annots.Add(ASTAnnotationHelper.Walk(anctx, mapEnv.ImportService));
                }
            }

            if (ctx.typeExpressionAnnotation() != null)
            {
                if (annots.IsEmpty())
                {
                    annots = new List<AnnotationDesc>();
                }

                foreach (EsperEPL2GrammarParser.TypeExpressionAnnotationContext anno in ctx.typeExpressionAnnotation())
                {
                    annots.Add(new AnnotationDesc(anno.n.Text, anno.v.Text));
                }
            }

            return new CreateTableColumn(columnName, optExpression, optType, annots, primaryKey);
        }