Class SqlAggFunction

    • Field Detail

      • requiresOrder

        private final boolean requiresOrder
      • requiresOver

        private final boolean requiresOver
      • requiresGroupOrder

        private final Optionality requiresGroupOrder
    • Method Detail

      • unwrap

        public <T> T unwrap​(java.lang.Class<T> clazz)
        Description copied from interface: Wrapper
        Finds an instance of an interface implemented by this object, or returns null if this object does not support that interface.
        Specified by:
        unwrap in interface Wrapper
      • isAggregator

        public boolean isAggregator()
        Description copied from class: SqlOperator
        Returns whether this operator is an aggregate function. By default, subclass type is used (an instance of SqlAggFunction is assumed to be an aggregator; anything else is not).

        Per SQL:2011, there are aggregate functions and window functions. Every aggregate function (e.g. SUM) is also a window function. There are window functions that are not aggregate functions, e.g. RANK, NTILE, LEAD, FIRST_VALUE.

        Collectively, aggregate and window functions are called analytic functions. Despite its name, this method returns true for every analytic function.

        isAggregator in class SqlOperator
        whether this operator is an analytic function (aggregate function or window function)
        See Also:
      • isQuantifierAllowed

        public boolean isQuantifierAllowed()
        Description copied from class: SqlFunction
        Returns whether this function allows a DISTINCT or ALL quantifier. The default is false; some aggregate functions return true.
        isQuantifierAllowed in class SqlFunction
      • requiresOrder

        public final boolean requiresOrder()
        Description copied from class: SqlOperator
        Returns whether this is a window function that requires ordering.

        Per SQL:2011, 2, 6.10: "If <ntile function>, <lead or lag function>, RANK or DENSE_RANK is specified, then the window ordering clause shall be present."

        requiresOrder in class SqlOperator
        See Also:
      • requiresGroupOrder

        public Optionality requiresGroupOrder()
        Returns whether this aggregate function must, may, or must not contain a WITHIN GROUP (ORDER ...) clause.


        • If Optionality.MANDATORY, then AGG(x) WITHIN GROUP (ORDER BY 1) is valid, and AGG(x) is invalid.
        • If Optionality.OPTIONAL, then AGG(x) WITHIN GROUP (ORDER BY 1) and AGG(x) are both valid.
        • If Optionality.IGNORED, then AGG(x) is valid, and AGG(x) WITHIN GROUP (ORDER BY 1) is valid but is treated the same as AGG(x).
        • If Optionality.FORBIDDEN, then AGG(x) WITHIN GROUP (ORDER BY 1) is invalid, and AGG(x) is valid.
      • getDistinctOptionality

        public Optionality getDistinctOptionality()
        Returns whether this aggregate function allows the DISTINCT keyword.

        The default implementation returns Optionality.OPTIONAL, which is appropriate for most aggregate functions, including SUM and COUNT.

        Some aggregate functions, for example MIN, produce the same result with or without DISTINCT, and therefore return Optionality.IGNORED to indicate this. For such functions, Calcite will probably remove DISTINCT while optimizing the query.

      • allowsFilter

        public boolean allowsFilter()
        Whether this aggregate function allows a FILTER (WHERE ...) clause.
      • allowsNullTreatment

        public boolean allowsNullTreatment()
        Returns whether this aggregate function allows specifying null treatment (RESPECT NULLS or IGNORE NULLS).