Class SqlAggFunction
- Direct Known Subclasses:
MockSqlOperatorTable.MyAggFunc
,MockSqlOperatorTable.MyAvgAggFunction
,SqlAbstractGroupFunction
,SqlAnyValueAggFunction
,SqlAvgAggFunction
,SqlBasicAggFunction
,SqlBitOpAggFunction
,SqlCountAggFunction
,SqlCovarAggFunction
,SqlFirstLastValueAggFunction
,SqlHistogramAggFunction
,SqlJsonArrayAggAggFunction
,SqlJsonObjectAggAggFunction
,SqlLeadLagAggFunction
,SqlMinMaxAggFunction
,SqlNthValueAggFunction
,SqlNtileAggFunction
,SqlRankFunction
,SqlSingleValueAggFunction
,SqlSumAggFunction
,SqlSumEmptyIsZeroAggFunction
,SqlUserDefinedAggFunction
- See Also:
-
Field Summary
Fields inherited from class org.apache.calcite.sql.SqlOperator
kind, MDX_PRECEDENCE, NL
-
Constructor Summary
ModifierConstructorDescriptionprotected
SqlAggFunction
(String name, @Nullable SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, @Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType) Deprecated.protected
SqlAggFunction
(String name, @Nullable SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, @Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver) Deprecated.protected
SqlAggFunction
(String name, @Nullable SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, @Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver, Optionality requiresGroupOrder) Creates a built-in or user-defined SqlAggFunction or window function.protected
SqlAggFunction
(String name, SqlKind kind, SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, @Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Whether this aggregate function allows aFILTER (WHERE ...)
clause.boolean
Returns whether this aggregate function allows specifying null treatment (RESPECT NULLS
orIGNORE NULLS
).Returns whether this aggregate function allows theDISTINCT
keyword.getParameterTypes
(RelDataTypeFactory typeFactory) Deprecated.getReturnType
(RelDataTypeFactory typeFactory) Deprecated.@Nullable SqlAggFunction
Gets rollup aggregation function.boolean
Returns whether this operator is an aggregate function.boolean
Returns whether this aggregate function is a PERCENTILE function.boolean
Returns whether this function allows aDISTINCT
orALL
quantifier.Returns whether this aggregate function must, may, or must not contain aWITHIN GROUP (ORDER ...)
clause.final boolean
Returns whether this is a window function that requires ordering.final boolean
Returns whether this is a window function that requires an OVER clause.<T> @Nullable T
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, createCall, createCall, createCall, deriveOperandType, equals, getAllowedSignatures, getAllowedSignatures, getKind, getLeftPrec, getMonotonicity, getMonotonicity, getName, getOperandCountRange, getOperandTypeChecker, getOperandTypeInference, getReturnTypeInference, getRightPrec, getSignatureTemplate, getStrongPolicyInference, hashCode, inferReturnType, inferReturnType, isDeterministic, isDynamicFunction, isGroup, isGroupAuxiliary, isName, isSymmetrical, leftPrec, not, preValidateCall, requiresDecimalExpansion, reverse, rewriteCall, rightPrec, toString, unparseListClause, unparseListClause, validateOperands, validRexOperands
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.calcite.schema.Wrapper
maybeUnwrap, unwrapOrThrow
-
Constructor Details
-
SqlAggFunction
@Deprecated protected SqlAggFunction(String name, SqlKind kind, SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, @Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType) Deprecated.Creates a built-in SqlAggFunction. -
SqlAggFunction
@Deprecated protected SqlAggFunction(String name, @Nullable SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, @Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType) Deprecated.Creates a user-defined SqlAggFunction. -
SqlAggFunction
@Deprecated protected SqlAggFunction(String name, @Nullable SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, @Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver) Deprecated. -
SqlAggFunction
protected SqlAggFunction(String name, @Nullable SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, @Nullable 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 Details
-
unwrap
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:
-
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:
-
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:
-
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:
-
getDistinctOptionality
Returns whether this aggregate function allows theDISTINCT
keyword.The default implementation returns
Optionality.OPTIONAL
, which is appropriate for most aggregate functions, includingSUM
andCOUNT
.Some aggregate functions, for example
MIN
, produce the same result with or withoutDISTINCT
, and therefore returnOptionality.IGNORED
to indicate this. For such functions, Calcite will probably removeDISTINCT
while optimizing the query. -
getParameterTypes
Deprecated. -
getReturnType
Deprecated. -
allowsFilter
public boolean allowsFilter()Whether this aggregate function allows aFILTER (WHERE ...)
clause. -
allowsNullTreatment
public boolean allowsNullTreatment()Returns whether this aggregate function allows specifying null treatment (RESPECT NULLS
orIGNORE NULLS
). -
getRollup
Gets rollup aggregation function. -
isPercentile
public boolean isPercentile()Returns whether this aggregate function is a PERCENTILE function. Such functions require aWITHIN GROUP
clause that has precisely one sort key.NOTE: This API is experimental and subject to change without notice.
-