コード例 #1
0
        public void TestEvaluate()
        {
            var eparams = new EvaluateParams(null, false, null);

            _minMaxNode = new ExprMinMaxRowNode(MinMaxTypeEnum.MAX);
            SetupNode(_minMaxNode, 10, 1.5, null);
            Assert.AreEqual(10d, _minMaxNode.Evaluate(eparams));

            _minMaxNode = new ExprMinMaxRowNode(MinMaxTypeEnum.MAX);
            SetupNode(_minMaxNode, 1, 1.5, null);
            Assert.AreEqual(1.5d, _minMaxNode.Evaluate(eparams));

            _minMaxNode = new ExprMinMaxRowNode(MinMaxTypeEnum.MIN);
            SetupNode(_minMaxNode, 1, 1.5, null);
            Assert.AreEqual(1d, _minMaxNode.Evaluate(eparams));

            _minMaxNode = new ExprMinMaxRowNode(MinMaxTypeEnum.MAX);
            SetupNode(_minMaxNode, 1, 1.5, 2.0f);
            Assert.AreEqual(2.0d, _minMaxNode.Evaluate(eparams));

            _minMaxNode = new ExprMinMaxRowNode(MinMaxTypeEnum.MIN);
            SetupNode(_minMaxNode, 6, 3.5, 2.0f);
            Assert.AreEqual(2.0d, _minMaxNode.Evaluate(eparams));

            _minMaxNode = MakeNode(null, typeof(int), 5, typeof(int), 6, typeof(int));
            Assert.IsNull(_minMaxNode.Evaluate(eparams));
            _minMaxNode = MakeNode(7, typeof(int), null, typeof(int), 6, typeof(int));
            Assert.IsNull(_minMaxNode.Evaluate(eparams));
            _minMaxNode = MakeNode(3, typeof(int), 5, typeof(int), null, typeof(int));
            Assert.IsNull(_minMaxNode.Evaluate(eparams));
            _minMaxNode = MakeNode(null, typeof(int), null, typeof(int), null, typeof(int));
            Assert.IsNull(_minMaxNode.Evaluate(eparams));
        }
コード例 #2
0
 private static void SetupNode(ExprMinMaxRowNode nodeMin, int intValue, double doubleValue, float?floatValue)
 {
     nodeMin.AddChildNode(new SupportExprNode(intValue));
     nodeMin.AddChildNode(new SupportExprNode(doubleValue));
     if (floatValue != null)
     {
         nodeMin.AddChildNode(new SupportExprNode(floatValue));
     }
     nodeMin.Validate(ExprValidationContextFactory.MakeEmpty());
 }
コード例 #3
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);
        }
コード例 #4
0
        private ExprMinMaxRowNode MakeNode(Object valueOne, Type typeOne,
                                           Object valueTwo, Type typeTwo,
                                           Object valueThree, Type typeThree)
        {
            var maxNode = new ExprMinMaxRowNode(MinMaxTypeEnum.MAX);

            maxNode.AddChildNode(new SupportExprNode(valueOne, typeOne));
            maxNode.AddChildNode(new SupportExprNode(valueTwo, typeTwo));
            maxNode.AddChildNode(new SupportExprNode(valueThree, typeThree));
            maxNode.Validate(ExprValidationContextFactory.MakeEmpty());
            return(maxNode);
        }
コード例 #5
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);
        }
コード例 #6
0
 public void QExprMinMaxRow(ExprMinMaxRowNode exprMinMaxRowNode)
 {
 }
コード例 #7
0
 public void SetUp()
 {
     _minMaxNode = new ExprMinMaxRowNode(MinMaxTypeEnum.MAX);
 }
コード例 #8
0
 public void SetUp()
 {
     _container  = SupportContainer.Reset();
     _minMaxNode = new ExprMinMaxRowNode(MinMaxTypeEnum.MAX);
 }