Example #1
0
        public void ValidatePositionals(ExprValidationContext validationContext)
        {
            ExprAggregateNodeParamDesc paramDesc = ExprAggregateNodeUtil.GetValidatePositionalParams(ChildNodes, true);
            if (validationContext.StatementRawInfo.StatementType == StatementType.CREATE_TABLE &&
                (paramDesc.OptLocalGroupBy != null || paramDesc.OptionalFilter != null)) {
                throw new ExprValidationException(
                    "The 'group_by' and 'filter' parameter is not allowed in create-table statements");
            }

            optionalAggregateLocalGroupByDesc = paramDesc.OptLocalGroupBy;
            optionalFilter = paramDesc.OptionalFilter;
            if (optionalAggregateLocalGroupByDesc != null) {
                ExprNodeUtilityValidate.ValidateNoSpecialsGroupByExpressions(
                    optionalAggregateLocalGroupByDesc.PartitionExpressions);
            }

            if (optionalFilter != null) {
                ExprNodeUtilityValidate.ValidateNoSpecialsGroupByExpressions(new[] {optionalFilter});
            }

            if (optionalFilter != null && IsFilterExpressionAsLastParameter) {
                if (paramDesc.PositionalParams.Length > 1) {
                    throw new ExprValidationException("Only a single filter expression can be provided");
                }

                positionalParams = ExprNodeUtilityMake.AddExpression(paramDesc.PositionalParams, optionalFilter);
            }
            else {
                positionalParams = paramDesc.PositionalParams;
            }
        }
Example #2
0
        public void TestGetAggregatesBottomUp()
        {
            ExprNode top = new SupportAggregateExprNode(null);
            ExprNode c1  = new SupportExprNode(null);
            ExprNode c2  = new SupportExprNode(null);

            top.AddChildNode(c1);
            top.AddChildNode(c2);

            ExprNode c1_1 = new SupportAggregateExprNode(null);
            ExprNode c1_2 = new SupportAggregateExprNode(null);

            c1.AddChildNode(c1_1);
            c1.AddChildNode(c1_2);
            c1_1.AddChildNode(new SupportExprNode(null));
            c1_2.AddChildNode(new SupportExprNode(null));

            ExprNode c2_1 = new SupportExprNode(null);
            ExprNode c2_2 = new SupportExprNode(null);

            c2.AddChildNode(c2_1);
            c2.AddChildNode(c2_2);
            c2_2.AddChildNode(new SupportExprNode(null));

            ExprNode c2_1_1 = new SupportAggregateExprNode(null);
            ExprNode c2_1_2 = new SupportAggregateExprNode(null);

            c2_1.AddChildNode(c2_1_1);
            c2_1.AddChildNode(c2_1_2);

            IList <ExprAggregateNode> aggregates = new List <ExprAggregateNode>();

            ExprAggregateNodeUtil.GetAggregatesBottomUp(top, aggregates);

            Assert.AreEqual(5, aggregates.Count);
            Assert.AreSame(c2_1_1, aggregates[0]);
            Assert.AreSame(c2_1_2, aggregates[1]);
            Assert.AreSame(c1_1, aggregates[2]);
            Assert.AreSame(c1_2, aggregates[3]);
            Assert.AreSame(top, aggregates[4]);

            // Test no aggregates
            aggregates.Clear();
            ExprAggregateNodeUtil.GetAggregatesBottomUp(new SupportExprNode(null), aggregates);
            Assert.IsTrue(aggregates.IsEmpty());
        }