Esempio n. 1
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);
        }
Esempio n. 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));
        }