Class SqlAggFunction
- java.lang.Object
-
- org.apache.calcite.sql.SqlOperator
-
- org.apache.calcite.sql.SqlFunction
-
- org.apache.calcite.sql.SqlAggFunction
-
- Direct Known Subclasses:
SqlAbstractGroupFunction
,SqlAnyValueAggFunction
,SqlAvgAggFunction
,SqlCountAggFunction
,SqlCovarAggFunction
,SqlFirstLastValueAggFunction
,SqlHistogramAggFunction
,SqlJsonArrayAggAggFunction
,SqlJsonObjectAggAggFunction
,SqlLeadLagAggFunction
,SqlMinMaxAggFunction
,SqlNthValueAggFunction
,SqlNtileAggFunction
,SqlRankFunction
,SqlSingleValueAggFunction
,SqlSumAggFunction
,SqlSumEmptyIsZeroAggFunction
,SqlUserDefinedAggFunction
public abstract class SqlAggFunction extends SqlFunction implements Context
Abstract base class for the definition of an aggregate function: an operator which aggregates sets of values into a result.
-
-
Field Summary
Fields Modifier and Type Field Description private Optionality
requiresGroupOrder
private boolean
requiresOrder
private boolean
requiresOver
-
Fields inherited from class org.apache.calcite.sql.SqlOperator
kind, MDX_PRECEDENCE, NL
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SqlAggFunction(java.lang.String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType)
Deprecated.protected
SqlAggFunction(java.lang.String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver)
Deprecated.protected
SqlAggFunction(java.lang.String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver, Optionality requiresGroupOrder)
Creates a built-in or user-defined SqlAggFunction or window function.protected
SqlAggFunction(java.lang.String name, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
allowsFilter()
Whether this aggregate function allows aFILTER (WHERE ...)
clause.java.util.List<RelDataType>
getParameterTypes(RelDataTypeFactory typeFactory)
Deprecated.RelDataType
getReturnType(RelDataTypeFactory typeFactory)
Deprecated.boolean
isAggregator()
Returns whether this operator is an aggregate function.boolean
isQuantifierAllowed()
Returns whether this function allows aDISTINCT
orALL
quantifier.Optionality
requiresGroupOrder()
Returns whether this aggregate function must, may, or must not contain aWITHIN GROUP (ORDER ...)
clause.boolean
requiresOrder()
Returns whether this is a window function that requires ordering.boolean
requiresOver()
Returns whether this is a window function that requires an OVER clause.<T> T
unwrap(java.lang.Class<T> clazz)
Finds an instance of an interface implemented by this object, or returns null if this object does not support that interface.void
validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope)
Validates a call to this operator.-
Methods inherited from class org.apache.calcite.sql.SqlFunction
deriveType, getFunctionType, getNameAsId, getParamNames, getParamTypes, getSqlIdentifier, getSyntax, unparse, validateQuantifier
-
Methods inherited from class org.apache.calcite.sql.SqlOperator
acceptCall, acceptCall, adjustType, allowsFraming, argumentMustBeScalar, checkOperandCount, checkOperandTypes, constructArgNameList, constructArgTypeList, constructOperandList, createCall, createCall, createCall, createCall, equals, getAllowedSignatures, getAllowedSignatures, getKind, getLeftPrec, getMonotonicity, getMonotonicity, getName, getOperandCountRange, getOperandTypeChecker, getOperandTypeInference, getReturnTypeInference, getRightPrec, getSignatureTemplate, hashCode, inferReturnType, inferReturnType, isDeterministic, isDynamicFunction, isGroup, isGroupAuxiliary, isName, leftPrec, needsSpace, preValidateCall, requiresDecimalExpansion, rewriteCall, rightPrec, toString, unparseListClause, unparseListClause, validateOperands, validRexOperands
-
-
-
-
Field Detail
-
requiresOrder
private final boolean requiresOrder
-
requiresOver
private final boolean requiresOver
-
requiresGroupOrder
private final Optionality requiresGroupOrder
-
-
Constructor Detail
-
SqlAggFunction
@Deprecated protected SqlAggFunction(java.lang.String name, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType)
Deprecated.Creates a built-in SqlAggFunction.
-
SqlAggFunction
@Deprecated protected SqlAggFunction(java.lang.String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType)
Deprecated.Creates a user-defined SqlAggFunction.
-
SqlAggFunction
@Deprecated protected SqlAggFunction(java.lang.String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver)
Deprecated.
-
SqlAggFunction
protected SqlAggFunction(java.lang.String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver, Optionality requiresGroupOrder)
Creates a built-in or user-defined SqlAggFunction or window function.A user-defined function will have a value for
sqlIdentifier
; for a built-in function it will be null.
-
-
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.
-
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.
- Overrides:
isAggregator
in classSqlOperator
- Returns:
- whether this operator is an analytic function (aggregate function or window function)
- See Also:
SqlOperator.requiresOrder()
-
isQuantifierAllowed
public boolean isQuantifierAllowed()
Description copied from class:SqlFunction
Returns whether this function allows aDISTINCT
orALL
quantifier. The default isfalse
; some aggregate functions returntrue
.- Overrides:
isQuantifierAllowed
in classSqlFunction
-
validateCall
public void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope)
Description copied from class:SqlOperator
Validates a call to this operator.This method should not perform type-derivation or perform validation related related to types. That is done later, by
SqlOperator.deriveType(SqlValidator, SqlValidatorScope, SqlCall)
. This method should focus on structural validation.A typical implementation of this method first validates the operands, then performs some operator-specific logic. The default implementation just validates the operands.
This method is the default implementation of
SqlCall.validate(org.apache.calcite.sql.validate.SqlValidator, org.apache.calcite.sql.validate.SqlValidatorScope)
; but note that some sub-classes ofSqlCall
never call this method.- Overrides:
validateCall
in classSqlFunction
- Parameters:
call
- the call to this operatorvalidator
- the active validatorscope
- validator scopeoperandScope
- validator scope in which to validate operands to this call; usually equal to scope, but not always because some operators introduce new scopes- See Also:
SqlNode.validateExpr(SqlValidator, SqlValidatorScope)
,SqlOperator.deriveType(SqlValidator, SqlValidatorScope, SqlCall)
-
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."
- Overrides:
requiresOrder
in classSqlOperator
- See Also:
SqlOperator.isAggregator()
-
requiresGroupOrder
@Nonnull public Optionality requiresGroupOrder()
Returns whether this aggregate function must, may, or must not contain aWITHIN GROUP (ORDER ...)
clause.Cases:
- If
Optionality.MANDATORY
, thenAGG(x) WITHIN GROUP (ORDER BY 1)
is valid, andAGG(x)
is invalid. - If
Optionality.OPTIONAL
, thenAGG(x) WITHIN GROUP (ORDER BY 1)
andAGG(x)
are both valid. - If
Optionality.IGNORED
, thenAGG(x)
is valid, andAGG(x) WITHIN GROUP (ORDER BY 1)
is valid but is treated the same asAGG(x)
. - If
Optionality.FORBIDDEN
, thenAGG(x) WITHIN GROUP (ORDER BY 1)
is invalid, andAGG(x)
is valid.
- If
-
requiresOver
public final boolean requiresOver()
Description copied from class:SqlOperator
Returns whether this is a window function that requires an OVER clause.For example, returns true for
RANK
,DENSE_RANK
and other ranking functions; returns false forSUM
,COUNT
,MIN
,MAX
,AVG
(they can be used as non-window aggregate functions).If
requiresOver
returns true, thenSqlOperator.isAggregator()
must also return true.- Overrides:
requiresOver
in classSqlOperator
- See Also:
SqlOperator.allowsFraming()
,SqlOperator.requiresOrder()
-
getParameterTypes
@Deprecated public java.util.List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory)
Deprecated.
-
getReturnType
@Deprecated public RelDataType getReturnType(RelDataTypeFactory typeFactory)
Deprecated.
-
allowsFilter
public boolean allowsFilter()
Whether this aggregate function allows aFILTER (WHERE ...)
clause.
-
-