Example #1
0
 public EPStatementObjectModel EplToModel(
     string stmtText,
     Configuration configuration)
 {
     try {
         var mapEnv = new StatementSpecMapEnv(
             MakeImportService(configuration),
             VariableCompileTimeResolverEmpty.INSTANCE,
             configuration,
             ExprDeclaredCompileTimeResolverEmpty.INSTANCE,
             ContextCompileTimeResolverEmpty.INSTANCE,
             TableCompileTimeResolverEmpty.INSTANCE,
             ScriptCompileTimeResolverEmpty.INSTANCE,
             new CompilerServicesImpl(),
             new ClassProvidedExtensionImpl(ClassProvidedCompileTimeResolverEmpty.INSTANCE));
         var statementSpec = ParseWalk(stmtText, mapEnv);
         var unmapped = StatementSpecMapper.Unmap(statementSpec);
         return unmapped.ObjectModel;
     }
     catch (StatementSpecCompileException ex) {
         throw new EPCompileException(ex.Message, ex, new EmptyList<EPCompileExceptionItem>());
     }
     catch (Exception t) {
         throw new EPCompileException(t.Message, t, new EmptyList<EPCompileExceptionItem>());
     }
 }
        public static StatementSpecRaw ParseWalk(
            string epl,
            StatementSpecMapEnv mapEnv)
        {
            var parseResult = Parse(epl);

            return(Walk(parseResult, epl, mapEnv));
        }
Example #3
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);
        }
Example #4
0
        public static EPLTreeWalkerListener MakeWalker(
            CommonTokenStream tokenStream,
            ImportServiceCompileTime engineImportService)
        {
            StatementSpecMapEnv mapEnv = SupportStatementSpecMapEnv.Make(engineImportService);

            return(new EPLTreeWalkerListener(
                       tokenStream,
                       SelectClauseStreamSelectorEnum.ISTREAM_ONLY,
                       EmptyList <string> .Instance,
                       EmptyList <string> .Instance,
                       mapEnv));
        }
Example #5
0
        public static IList<CreateTableColumn> GetColumns(
            IList<EsperEPL2GrammarParser.CreateTableColumnContext> ctxs,
            IDictionary<ITree, ExprNode> astExprNodeMap,
            StatementSpecMapEnv mapEnv)
        {
            IList<CreateTableColumn> cols = new List<CreateTableColumn>(ctxs.Count);
            foreach (var colctx in ctxs)
            {
                cols.Add(GetColumn(colctx, astExprNodeMap, mapEnv));
            }

            return cols;
        }
Example #6
0
        private static Pair<ExprNode, StatementSpecMapContext> GetExprDeclaredNode(
            Expression expression,
            ICollection<ExpressionDeclItem> stmtLocalExpressions,
            ContextCompileTimeDescriptor contextCompileTimeDescriptor,
            StatementSpecMapEnv mapEnv)
        {
            var mapContext = new StatementSpecMapContext(contextCompileTimeDescriptor, mapEnv);
            foreach (var item in stmtLocalExpressions) {
                mapContext.AddExpressionDeclarations(item);
            }

            var body = StatementSpecMapper.MapExpression(expression, mapContext);
            return new Pair<ExprNode, StatementSpecMapContext>(body, mapContext);
        }
Example #7
0
        private static Pair<ExprNode, StatementSpecMapContext> GetExprDeclaredNode(
            Expression expression,
            ICollection<ExpressionDeclItem> stmtLocalExpressions,
            ContextCompileTimeDescriptor contextCompileTimeDescriptor,
            StatementSpecMapEnv mapEnv,
            LazyAllocatedMap<HashableMultiKey, AggregationMultiFunctionForge> plugInAggregations,
            IList<ExpressionScriptProvided> scripts)
        {
            var mapContext = new StatementSpecMapContext(contextCompileTimeDescriptor, mapEnv, plugInAggregations, scripts);
            foreach (var item in stmtLocalExpressions) {
                mapContext.AddExpressionDeclaration(item);
            }

            var body = StatementSpecMapper.MapExpression(expression, mapContext);
            return new Pair<ExprNode, StatementSpecMapContext>(body, mapContext);
        }
Example #8
0
        public static Pair<ExprDeclaredNodeImpl, StatementSpecMapContext> GetExistsDeclaredExpr(
            string name,
            IList<ExprNode> parameters,
            ICollection<ExpressionDeclItem> stmtLocalExpressions,
            ContextCompileTimeDescriptor contextCompileTimeDescriptor,
            StatementSpecMapEnv mapEnv,
            LazyAllocatedMap<HashableMultiKey, AggregationMultiFunctionForge> plugInAggregations,
            IList<ExpressionScriptProvided> scripts)
        {
            // Find among local expressions
            if (!stmtLocalExpressions.IsEmpty()) {
                foreach (var declNode in stmtLocalExpressions) {
                    if (declNode.Name.Equals(name)) {
                        var pair = GetExprDeclaredNode(
                            declNode.OptionalSoda,
                            stmtLocalExpressions,
                            contextCompileTimeDescriptor,
                            mapEnv,
                            plugInAggregations,
                            scripts);
                        var declared = new ExprDeclaredNodeImpl(
                            declNode,
                            parameters,
                            contextCompileTimeDescriptor,
                            pair.First);
                        return new Pair<ExprDeclaredNodeImpl, StatementSpecMapContext>(declared, pair.Second);
                    }
                }
            }

            // find among global expressions
            var found = mapEnv.ExprDeclaredCompileTimeResolver.Resolve(name);
            if (found != null) {
                var expression = found.OptionalSoda;
                if (expression == null) {
                    var bytes = found.OptionalSodaBytes.Invoke();
                    expression = (Expression) SerializerUtil.ByteArrToObject(bytes);
                }

                var pair = GetExprDeclaredNode(expression, stmtLocalExpressions, contextCompileTimeDescriptor, mapEnv, plugInAggregations, scripts);
                var declared = new ExprDeclaredNodeImpl(found, parameters, contextCompileTimeDescriptor, pair.First);
                return new Pair<ExprDeclaredNodeImpl, StatementSpecMapContext>(declared, pair.Second);
            }

            return null;
        }
Example #9
0
        public static void ProcessChainable(
            EsperEPL2GrammarParser.ChainableContext ctx,
            IDictionary <ITree, ExprNode> astExprNodeMap,
            ContextCompileTimeDescriptor contextCompileTimeDescriptor,
            StatementSpecMapEnv mapEnv,
            StatementSpecRaw statementSpec,
            ExpressionDeclDesc expressionDeclarations,
            LazyAllocatedMap <HashableMultiKey, AggregationMultiFunctionForge> plugInAggregations,
            IList <ExpressionScriptProvided> scriptExpressions)
        {
            // we first convert the event property into chain spec
            IList <Chainable> chain = ASTChainSpecHelper.GetChainables(ctx, astExprNodeMap);

            // process chain
            StatementSpecMapContext mapContext = new StatementSpecMapContext(contextCompileTimeDescriptor, mapEnv, plugInAggregations, scriptExpressions);

            mapContext.AddExpressionDeclarations(expressionDeclarations);
            ExprNode node = ChainableWalkHelper.ProcessDot(false, true, chain, mapContext);

            astExprNodeMap.Put(ctx, node);
            mapContext.AddTo(statementSpec);
        }
Example #10
0
        public static ExprNodeScript GetExistsScript(
            string defaultDialect,
            string expressionName,
            IList<ExprNode> parameters,
            ICollection<ExpressionScriptProvided> scriptExpressions,
            StatementSpecMapEnv mapEnv)
        {
            ExpressionScriptProvided script;

            if (!scriptExpressions.IsEmpty()) {
                script = FindScript(expressionName, parameters.Count, scriptExpressions);
                if (script != null) {
                    return new ExprNodeScript(defaultDialect, script, parameters);
                }
            }

            script = mapEnv.ScriptCompileTimeResolver.Resolve(expressionName, parameters.Count);
            if (script != null) {
                return new ExprNodeScript(defaultDialect, script, parameters);
            }

            return null;
        }
Example #11
0
        private static StatementSpecRaw Walk(
            ParseResult parseResult,
            string epl,
            StatementSpecMapEnv mapEnv)
        {
            var ast = parseResult.Tree;

            var defaultStreamSelector =
                StatementSpecMapper.MapFromSODA(mapEnv.Configuration.Compiler.StreamSelection.DefaultStreamSelector);
            var walker = new EPLTreeWalkerListener(
                parseResult.TokenStream,
                defaultStreamSelector,
                parseResult.Scripts,
                parseResult.Classes,
                mapEnv);

            try {
                ParseHelper.Walk(ast, walker, epl, epl);
            }
            catch (ASTWalkException ex) {
                throw new StatementSpecCompileException(ex.Message, ex, epl);
            }
            catch (ValidationException ex) {
                throw new StatementSpecCompileException(ex.Message, ex, epl);
            }
            catch (Exception ex) {
                var message = "Invalid expression encountered";
                throw new StatementSpecCompileException(GetNullableErrortext(message, ex.Message), ex, epl);
            }

            if (Log.IsDebugEnabled)
            {
                ASTUtil.DumpAST(ast);
            }

            return(walker.StatementSpec);
        }
Example #12
0
 public StatementSpecRaw ParseWalk(
     string epl,
     StatementSpecMapEnv mapEnv)
 {
     return CompilerHelperSingleEPL.ParseWalk(epl, mapEnv);
 }