Пример #1
0
        private static GraphOperatorSpec ParseOp(EsperEPL2GrammarParser.GopContext ctx, IDictionary <ITree, Object> astGraphNodeMap, EngineImportService engineImportService)
        {
            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)
            {
                var configs = new LinkedHashMap <String, Object>();
                var 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)
            {
                var annoctxs = ctx.annotationEnum();
                annotations = annoctxs
                              .Select(annoctx => ASTAnnotationHelper.Walk(annoctx, engineImportService))
                              .ToList();
            }
            else
            {
                annotations = Collections.GetEmptyList <AnnotationDesc>();
            }

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

            ExprNode optExpression = null;

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

            string optTypeName             = null;
            bool?  optTypeIsArray          = null;
            bool?  optTypeIsPrimitiveArray = null;

            if (ctx.createTableColumnPlain() != null)
            {
                EsperEPL2GrammarParser.CreateTableColumnPlainContext sub = ctx.createTableColumnPlain();
                optTypeName             = ASTUtil.UnescapeClassIdent(sub.classIdentifier());
                optTypeIsArray          = sub.b != null;
                optTypeIsPrimitiveArray = ASTCreateSchemaHelper.ValidateIsPrimitiveArray(sub.p);
            }

            bool primaryKey = false;

            if (ctx.p != null)
            {
                if (ctx.p.Text.ToLower() != "primary")
                {
                    throw ASTWalkException.From("Invalid keyword '" + ctx.p.Text + "' encountered, expected 'primary key'");
                }
                if (ctx.k.Text.ToLower() != "key")
                {
                    throw ASTWalkException.From("Invalid keyword '" + ctx.k.Text + "' encountered, expected 'primary key'");
                }
                primaryKey = true;
            }

            IList <AnnotationDesc> annots = Collections.GetEmptyList <AnnotationDesc>();

            if (ctx.annotationEnum() != null)
            {
                annots = new List <AnnotationDesc>(ctx.annotationEnum().Length);
                foreach (EsperEPL2GrammarParser.AnnotationEnumContext anctx in ctx.annotationEnum())
                {
                    annots.Add(ASTAnnotationHelper.Walk(anctx, engineImportService));
                }
            }
            if (ctx.propertyExpressionAnnotation() != null)
            {
                if (annots.IsEmpty())
                {
                    annots = new List <AnnotationDesc>();
                }
                foreach (EsperEPL2GrammarParser.PropertyExpressionAnnotationContext anno in ctx.propertyExpressionAnnotation())
                {
                    annots.Add(new AnnotationDesc(anno.n.Text, anno.v.Text));
                }
            }

            return(new CreateTableColumn(columnName, optExpression, optTypeName, optTypeIsArray, optTypeIsPrimitiveArray, annots, primaryKey));
        }