Class AggregatingSelectScope

  • All Implemented Interfaces:
    AggregatingScope, SqlValidatorScope

    public class AggregatingSelectScope
    extends DelegatingScope
    implements AggregatingScope
    Scope for resolving identifiers within a SELECT statement that has a GROUP BY clause.

    The same set of identifiers are in scope, but it won't allow access to identifiers or expressions which are not group-expressions.

    • Field Detail

      • distinct

        private final boolean distinct
      • temporaryGroupExprList

        private java.util.List<SqlNode> temporaryGroupExprList
        Use while under construction.
    • Constructor Detail

      • AggregatingSelectScope

        AggregatingSelectScope​(SqlValidatorScope selectScope,
                               SqlSelect select,
                               boolean distinct)
        Creates an AggregatingSelectScope
        selectScope - Parent scope
        select - Enclosing SELECT node
        distinct - Whether SELECT is DISTINCT
    • Method Detail

      • getGroupExprs

        private Pair<<SqlNode>,​<SqlNode>> getGroupExprs()
        Returns the expressions that are in the GROUP BY clause (or the SELECT DISTINCT clause, if distinct) and that can therefore be referenced without being wrapped in aggregate functions.

        The expressions are fully-qualified, and any "*" in select clauses are expanded.

        list of grouping expressions
      • allContain

        private static boolean allContain​(java.util.List<ImmutableBitSet> bitSets,
                                          int bit)
      • getOperandScope

        public SqlValidatorScope getOperandScope​(SqlCall call)
        Description copied from interface: SqlValidatorScope
        Returns the scope within which operands to a call are to be validated. Usually it is this scope, but when the call is to an aggregate function and this is an aggregating scope, it will be a a different scope.
        Specified by:
        getOperandScope in interface SqlValidatorScope
        getOperandScope in class DelegatingScope
        call - Call
        Scope within which to validate arguments to call.
      • checkAggregateExpr

        public boolean checkAggregateExpr​(SqlNode expr,
                                          boolean deep)
        Description copied from interface: AggregatingScope
        Checks whether an expression is constant within the GROUP BY clause. If the expression completely matches an expression in the GROUP BY clause, returns true. If the expression is constant within the group, but does not exactly match, returns false. If the expression is not constant, throws an exception. Examples:
        • If we are 'f(b, c)' in 'SELECT a + f(b, c) FROM t GROUP BY a', then the whole expression matches a group column. Return true.
        • Just an ordinary expression in a GROUP BY query, such as 'f(SUM(a), 1, b)' in 'SELECT f(SUM(a), 1, b) FROM t GROUP BY b'. Returns false.
        • Illegal expression, such as 'f(5, a, b)' in 'SELECT f(a, b) FROM t GROUP BY a'. Throws when it enounters the 'b' operand, because it is not in the group clause.
        Specified by:
        checkAggregateExpr in interface AggregatingScope
      • validateExpr

        public void validateExpr​(SqlNode expr)
        Description copied from interface: SqlValidatorScope
        Performs any scope-specific validation of an expression. For example, an aggregating scope requires that expressions are valid aggregations. The expression has already been validated.
        Specified by:
        validateExpr in interface SqlValidatorScope
        validateExpr in class DelegatingScope