public abstract class SqlAggFunction extends SqlFunction implements Context
Modifier and Type | Field and Description |
---|---|
private Optionality |
requiresGroupOrder |
private boolean |
requiresOrder |
private boolean |
requiresOver |
kind, MDX_PRECEDENCE, NL
Modifier | Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
allowsFilter()
Whether this aggregate function allows a
FILTER (WHERE ...)
clause. |
boolean |
allowsNullTreatment()
Returns whether this aggregate function allows specifying null treatment
(
RESPECT NULLS or IGNORE NULLS ). |
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 a
DISTINCT or
ALL quantifier. |
Optionality |
requiresGroupOrder()
Returns whether this aggregate function must, may, or must not contain a
WITHIN 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.
|
deriveType, getFunctionType, getNameAsId, getParamNames, getParamTypes, getSqlIdentifier, getSyntax, unparse, validateQuantifier
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
private final boolean requiresOrder
private final boolean requiresOver
private final Optionality requiresGroupOrder
@Deprecated protected SqlAggFunction(java.lang.String name, 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)
@Deprecated protected SqlAggFunction(java.lang.String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver)
protected SqlAggFunction(java.lang.String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver, Optionality requiresGroupOrder)
A user-defined function will have a value for sqlIdentifier
; for
a built-in function it will be null.
public <T> T unwrap(java.lang.Class<T> clazz)
Wrapper
public boolean isAggregator()
SqlOperator
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
SqlOperator.requiresOrder()
public boolean isQuantifierAllowed()
SqlFunction
DISTINCT
or
ALL
quantifier. The default is false
; some aggregate
functions return true
.isQuantifierAllowed
in class SqlFunction
public void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope)
SqlOperator
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 of SqlCall
never call this method.
validateCall
in class SqlFunction
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 scopesSqlNode.validateExpr(SqlValidator, SqlValidatorScope)
,
SqlOperator.deriveType(SqlValidator, SqlValidatorScope, SqlCall)
public final boolean requiresOrder()
SqlOperator
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
SqlOperator.isAggregator()
@Nonnull public Optionality requiresGroupOrder()
WITHIN GROUP (ORDER ...)
clause.
Cases:
Optionality.MANDATORY
,
then AGG(x) WITHIN GROUP (ORDER BY 1)
is valid,
and AGG(x)
is invalid.
Optionality.OPTIONAL
,
then AGG(x) WITHIN GROUP (ORDER BY 1)
and AGG(x)
are both valid.
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)
.
Optionality.FORBIDDEN
,
then AGG(x) WITHIN GROUP (ORDER BY 1)
is invalid,
and AGG(x)
is valid.
public final boolean requiresOver()
SqlOperator
For example, returns true for RANK
, DENSE_RANK
and
other ranking functions; returns false for SUM
, COUNT
,
MIN
, MAX
, AVG
(they can be used as non-window
aggregate functions).
If requiresOver
returns true, then SqlOperator.isAggregator()
must
also return true.
requiresOver
in class SqlOperator
SqlOperator.allowsFraming()
,
SqlOperator.requiresOrder()
@Deprecated public java.util.List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory)
@Deprecated public RelDataType getReturnType(RelDataTypeFactory typeFactory)
public boolean allowsFilter()
FILTER (WHERE ...)
clause.public boolean allowsNullTreatment()
RESPECT NULLS
or IGNORE NULLS
).Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.