public static IList <ExprNode> GetExprNodesLibFunc(EsperEPL2GrammarParser.LibFunctionArgsContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap) { if (ctx == null) { return(Collections.GetEmptyList <ExprNode>()); } IList <EsperEPL2GrammarParser.LibFunctionArgItemContext> args = ctx.libFunctionArgItem(); if (args == null || args.IsEmpty()) { return(Collections.GetEmptyList <ExprNode>()); } IList <ExprNode> parameters = new List <ExprNode>(args.Count); foreach (var arg in args) { if (arg.expressionLambdaDecl() != null) { var lambdaparams = GetLambdaGoesParams(arg.expressionLambdaDecl()); var goes = new ExprLambdaGoesNode(lambdaparams); var lambdaExpr = ASTExprHelper.ExprCollectSubNodes(arg.expressionWithNamed(), 0, astExprNodeMap)[0]; goes.AddChildNode(lambdaExpr); parameters.Add(goes); } else { var parameter = ASTExprHelper.ExprCollectSubNodes(arg.expressionWithNamed(), 0, astExprNodeMap)[0]; parameters.Add(parameter); } } return(parameters); }
// Min/Max nodes can be either an aggregate or a per-row function depending on the number or arguments private static void HandleMinMax( string ident, EsperEPL2GrammarParser.LibFunctionArgsContext ctxArgs, IDictionary <ITree, ExprNode> astExprNodeMap) { // Determine min or max var childNodeText = ident; MinMaxTypeEnum minMaxTypeEnum; var filtered = childNodeText.StartsWith("f"); if (childNodeText.ToLowerInvariant().Equals("min") || childNodeText.ToLowerInvariant().Equals("fmin")) { minMaxTypeEnum = MinMaxTypeEnum.MIN; } else if (childNodeText.ToLowerInvariant().Equals("max") || childNodeText.ToLowerInvariant().Equals("fmax")) { minMaxTypeEnum = MinMaxTypeEnum.MAX; } else { throw ASTWalkException.From("Uncountered unrecognized min or max node '" + ident + "'"); } var args = Collections.GetEmptyList <ExprNode>(); if (ctxArgs != null && ctxArgs.libFunctionArgItem() != null) { args = ASTExprHelper.ExprCollectSubNodes(ctxArgs, 0, astExprNodeMap); } var numArgsPositional = ExprAggregateNodeUtil.CountPositionalArgs(args); var isDistinct = ctxArgs != null && ctxArgs.DISTINCT() != null; if (numArgsPositional > 1 && isDistinct && !filtered) { throw ASTWalkException.From( "The distinct keyword is not valid in per-row min and max " + "functions with multiple sub-expressions"); } ExprNode minMaxNode; if (!isDistinct && numArgsPositional > 1 && !filtered) { // use the row function minMaxNode = new ExprMinMaxRowNode(minMaxTypeEnum); } else { // use the aggregation function minMaxNode = new ExprMinMaxAggrNode(isDistinct, minMaxTypeEnum, filtered, false); } minMaxNode.AddChildNodes(args); astExprNodeMap.Put(ctxArgs, minMaxNode); }