public static void ValidateNoSpecialsGroupByExpressions(ExprNode[] groupByNodes) { ExprNodeSubselectDeclaredDotVisitor visitorSubselects = new ExprNodeSubselectDeclaredDotVisitor(); ExprNodeGroupingVisitorWParent visitorGrouping = new ExprNodeGroupingVisitorWParent(); IList<ExprAggregateNode> aggNodesInGroupBy = new List<ExprAggregateNode>(1); foreach (ExprNode groupByNode in groupByNodes) { // no subselects groupByNode.Accept(visitorSubselects); if (visitorSubselects.Subselects.Count > 0) { throw new ExprValidationException("Subselects not allowed within group-by"); } // no special grouping-clauses groupByNode.Accept(visitorGrouping); if (!visitorGrouping.GroupingIdNodes.IsEmpty()) { throw ExprGroupingIdNode.MakeException("grouping_id"); } if (!visitorGrouping.GroupingNodes.IsEmpty()) { throw ExprGroupingIdNode.MakeException("grouping"); } // no aggregations allowed ExprAggregateNodeUtil.GetAggregatesBottomUp(groupByNode, aggNodesInGroupBy); if (!aggNodesInGroupBy.IsEmpty()) { throw new ExprValidationException("Group-by expressions cannot contain aggregate functions"); } } }
public override ExprNode Validate(ExprValidationContext validationContext) { if (!validationContext.IsAllowRollupFunctions) { throw ExprGroupingIdNode.MakeException("grouping"); } return null; }