public MatchRecognizeRegEx CompileMatchRecognizePatternToSODA(string matchRecogPatternExpression) { var toCompile = "select * from System.object Match_recognize(measures a.b as c pattern (" + matchRecogPatternExpression + ") define A as true)"; var raw = EPAdministratorHelper.CompileEPL(toCompile, matchRecogPatternExpression, false, null, _services, SelectClauseStreamSelectorEnum.ISTREAM_ONLY); return(StatementSpecMapper.Unmap(raw.MatchRecognizeSpec.Pattern)); }
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 AnnotationPart CompileAnnotationToSODA(string annotationExpression) { var toCompile = annotationExpression + " select * from System.object"; var raw = EPAdministratorHelper.CompileEPL(toCompile, annotationExpression, false, null, _services, SelectClauseStreamSelectorEnum.ISTREAM_ONLY); return(StatementSpecMapper.Unmap(raw.Annotations[0])); }
public EPStatementObjectModel MapRawToSODA(StatementSpecRaw raw) { var unmapped = StatementSpecMapper.Unmap(raw); if (unmapped.SubstitutionParams.Count != 0) { throw new EPException(SUBS_PARAM_INVALID_USE); } return(unmapped.ObjectModel); }
public EPPreparedStatement PreparePattern(string patternExpression) { var rawPattern = EPAdministratorHelper.CompilePattern(patternExpression, patternExpression, true, _services, SelectClauseStreamSelectorEnum.ISTREAM_ONLY); // map to object model thus finding all substitution parameters and their indexes var unmapped = StatementSpecMapper.Unmap(rawPattern); // the prepared statement is the object model plus a list of substitution parameters // map to specification will refuse any substitution parameters that are unfilled return(new EPPreparedStatementImpl(unmapped.ObjectModel, unmapped.SubstitutionParams, null)); }
public EPStatementObjectModel CompileEPL(string eplStatement) { var statementSpec = EPAdministratorHelper.CompileEPL(eplStatement, eplStatement, true, null, _services, _defaultStreamSelector); var unmapped = StatementSpecMapper.Unmap(statementSpec); if (unmapped.SubstitutionParams.Count != 0) { throw new EPException(SUBS_PARAM_INVALID_USE); } return(unmapped.ObjectModel); }
public EPPreparedStatement PrepareEPL(string eplExpression) { // compile to specification var statementSpec = EPAdministratorHelper.CompileEPL(eplExpression, eplExpression, true, null, _services, _defaultStreamSelector); // map to object model thus finding all substitution parameters and their indexes var unmapped = StatementSpecMapper.Unmap(statementSpec); // the prepared statement is the object model plus a list of substitution parameters // map to specification will refuse any substitution parameters that are unfilled return(new EPPreparedStatementImpl(unmapped.ObjectModel, unmapped.SubstitutionParams, eplExpression)); }
public ExprNode Copy(ExprNode exprNode) { var expression = StatementSpecMapper.Unmap(exprNode); var mapEnv = services.StatementSpecMapEnv; var mapContext = new StatementSpecMapContext(contextCompileTimeDescriptor, mapEnv); var copy = StatementSpecMapper.MapExpression(expression, mapContext); statementSpecRaw.TableExpressions.AddAll(mapContext.TableExpressions); copy.Accept(visitor); return copy; }
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); }
public StatementSpecRaw MapSODAToRaw(EPStatementObjectModel model) { return(StatementSpecMapper.Map( model, _services.EngineImportService, _services.VariableService, _services.ConfigSnapshot, _services.SchedulingService, _services.EngineURI, _services.PatternNodeFactory, _services.NamedWindowMgmtService, _services.ContextManagementService, _services.ExprDeclaredService, _services.TableService)); }
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); }
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); }
internal static CompilerHelperSingleResult ParseCompileInlinedClassesWalk( Compilable compilable, StatementCompileTimeServices compileTimeServices) { CompilerHelperSingleResult result; try { if (compilable is CompilableEPL) { var compilableEPL = (CompilableEPL)compilable; // parse var parseResult = Parse(compilableEPL.Epl); // compile application-provided classes (both create-class as well as just class-keyword) var classesInlined = CompileAddExtensions(parseResult.Classes, compilable, compileTimeServices); // walk - this may use the new classes already such as for extension-single-row-function var raw = Walk(parseResult, compilableEPL.Epl, compileTimeServices.StatementSpecMapEnv); result = new CompilerHelperSingleResult(raw, classesInlined); } else if (compilable is CompilableSODA) { var soda = ((CompilableSODA)compilable).Soda; // compile application-provided classes (both create-class as well as just class-keyword) ClassProvidedPrecompileResult classesInlined; if ((soda.ClassProvidedExpressions != null && !soda.ClassProvidedExpressions.IsEmpty()) || soda.CreateClass != null) { IList <string> classTexts = new List <string>(); if (soda.ClassProvidedExpressions != null) { foreach (var inlined in soda.ClassProvidedExpressions) { classTexts.Add(inlined.ClassText); } } if (soda.CreateClass != null) { classTexts.Add(soda.CreateClass.ClassProvidedExpression.ClassText); } classesInlined = CompileAddExtensions(classTexts, compilable, compileTimeServices); } else { classesInlined = ClassProvidedPrecompileResult.EMPTY; } // map from soda to raw var raw = StatementSpecMapper.Map(soda, compileTimeServices.StatementSpecMapEnv); result = new CompilerHelperSingleResult(raw, classesInlined); } else { throw new IllegalStateException("Unrecognized compilable " + compilable); } } catch (StatementSpecCompileException) { throw; } catch (Exception ex) { throw new StatementSpecCompileException("Exception processing statement: " + ex.Message, ex, compilable.ToEPL()); } return(result); }
public PatternExpr CompilePatternToSODA(String expression) { EvalFactoryNode node = CompilePatternToNode(expression); return(StatementSpecMapper.Unmap(node)); }
public static MyPair 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.ToLowerInvariant().Trim().Equals("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 node = ASTExprHelper.ExprCollectSubNodes(ctx, 0, astExprNodeMap)[0]; var alias = ctx.name.Text; var expressionUnmap = StatementSpecMapper.Unmap(node); var decl = new ExpressionDeclItem(alias, new string[0], true); decl.OptionalSoda = expressionUnmap; return new MyPair(decl, null); } if (ctx.expressionDef().stringconstant() != null) { var expressionText = scriptBodies.DeleteAt(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 optionalEventTypeName = ASTTypeExpressionAnnoHelper.ExpectMayTypeAnno(ctx.typeExpressionAnnotation(), tokenStream); var script = new ExpressionScriptProvided( name, expressionText, parameters.ToArray(), optionalReturnType, optionalReturnTypeArray, optionalEventTypeName, optionalDialect); return new MyPair(null, script); } var ctxexpr = ctx.expressionDef(); var inner = ASTExprHelper.ExprCollectSubNodes(ctxexpr.expression(), 0, astExprNodeMap)[0]; IList<string> parametersNames = new EmptyList<string>(); var lambdactx = ctxexpr.expressionLambdaDecl(); if (ctxexpr.expressionLambdaDecl() != null) { parametersNames = ASTLambdaHelper.GetLambdaGoesParams(lambdactx); } var expression = StatementSpecMapper.Unmap(inner); var expr = new ExpressionDeclItem(name, parametersNames.ToArray(), false); expr.OptionalSoda = expression; return new MyPair(expr, null); }
public Expression CompileExpressionToSODA(string expression) { var node = CompileExpression(expression); return(StatementSpecMapper.Unmap(node)); }
public PatternExpr CompilePatternToSODA(string expression) { var node = CompilePatternToNode(expression); return(StatementSpecMapper.Unmap(node)); }