コード例 #1
0
        // 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);
        }
コード例 #2
0
        private static ExprNode HandleMinMaxNode(
            string chainFirstLowerCase,
            Chainable spec)
        {
            MinMaxTypeEnum minMaxTypeEnum;
            var            filtered = chainFirstLowerCase.StartsWith("f");

            if (chainFirstLowerCase.Equals("min") || chainFirstLowerCase.Equals("fmin"))
            {
                minMaxTypeEnum = MinMaxTypeEnum.MIN;
            }
            else if (chainFirstLowerCase.Equals("max") || chainFirstLowerCase.Equals("fmax"))
            {
                minMaxTypeEnum = MinMaxTypeEnum.MAX;
            }
            else
            {
                throw new ValidationException("Uncountered unrecognized min or max node '" + spec.GetRootNameOrEmptyString() + "'");
            }

            var args              = spec.GetParametersOrEmpty();
            var distinct          = spec.IsDistinct;
            var numArgsPositional = ExprAggregateNodeUtil.CountPositionalArgs(args);

            if (numArgsPositional > 1 && spec.IsDistinct && !filtered)
            {
                throw new ValidationException(
                          "The distinct keyword is not valid in per-row min and max " +
                          "functions with multiple sub-expressions");
            }

            ExprNode minMaxNode;

            if (!distinct && numArgsPositional > 1 && !filtered)
            {
                // use the row function
                minMaxNode = new ExprMinMaxRowNode(minMaxTypeEnum);
            }
            else
            {
                // use the aggregation function
                minMaxNode = new ExprMinMaxAggrNode(distinct, minMaxTypeEnum, filtered, false);
            }

            minMaxNode.AddChildNodes(args);
            return(minMaxNode);
        }