Class SqlFunction
- java.lang.Object
-
- org.apache.calcite.sql.SqlOperator
-
- org.apache.calcite.sql.SqlFunction
-
- Direct Known Subclasses:
SqlAbstractTimeFunction
,SqlAggFunction
,SqlBaseContextVariable
,SqlCastFunction
,SqlCoalesceFunction
,SqlConvertFunction
,SqlCurrentDateFunction
,SqlDatePartFunction
,SqlExtractFunction
,SqlGroupedWindowFunction
,SqlJdbcFunctionCall
,SqlJsonArrayFunction
,SqlJsonExistsFunction
,SqlJsonObjectFunction
,SqlJsonQueryFunction
,SqlJsonValueFunction
,SqlMonotonicUnaryFunction
,SqlNullifFunction
,SqlOverlayFunction
,SqlPositionFunction
,SqlRandFunction
,SqlRandIntegerFunction
,SqlSubstringFunction
,SqlTimestampAddFunction
,SqlTimestampDiffFunction
,SqlTranslate3Function
,SqlTrimFunction
,SqlUnresolvedFunction
,SqlUserDefinedFunction
,SqlUserDefinedTableMacro
public class SqlFunction extends SqlOperator
ASqlFunction
is a type of operator which has conventional function-call syntax.
-
-
Field Summary
Fields Modifier and Type Field Description private SqlFunctionCategory
category
private java.util.List<RelDataType>
paramTypes
private SqlIdentifier
sqlIdentifier
-
Fields inherited from class org.apache.calcite.sql.SqlOperator
kind, MDX_PRECEDENCE, NL
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SqlFunction(java.lang.String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, java.util.List<RelDataType> paramTypes, SqlFunctionCategory category)
Internal constructor.SqlFunction(java.lang.String name, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory category)
Creates a new SqlFunction for a call to a builtin function.SqlFunction(SqlIdentifier sqlIdentifier, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, java.util.List<RelDataType> paramTypes, SqlFunctionCategory funcType)
Creates a placeholder SqlFunction for an invocation of a function with a possibly qualified name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
containsRowArg(java.util.List<SqlNode> args)
RelDataType
deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call)
Derives the type of a call to this operator.private RelDataType
deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call, boolean convertRowArgToColumnList)
SqlFunctionCategory
getFunctionType()
SqlIdentifier
getNameAsId()
Returns the fully-qualified name of this operator.java.util.List<java.lang.String>
getParamNames()
Returns a list of parameter names.java.util.List<RelDataType>
getParamTypes()
SqlIdentifier
getSqlIdentifier()
SqlSyntax
getSyntax()
Returns the syntactic type of this operator, never null.boolean
isQuantifierAllowed()
Returns whether this function allows aDISTINCT
orALL
quantifier.void
unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)
Writes a SQL representation of a call to this operator to a writer, including parentheses if the operators on either side are of greater precedence.void
validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope)
Validates a call to this operator.protected void
validateQuantifier(SqlValidator validator, SqlCall call)
Throws a validation error if a DISTINCT or ALL quantifier is present but not allowed.-
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, isAggregator, isDeterministic, isDynamicFunction, isGroup, isGroupAuxiliary, isName, leftPrec, needsSpace, preValidateCall, requiresDecimalExpansion, requiresOrder, requiresOver, rewriteCall, rightPrec, toString, unparseListClause, unparseListClause, validateOperands, validRexOperands
-
-
-
-
Field Detail
-
category
private final SqlFunctionCategory category
-
sqlIdentifier
private final SqlIdentifier sqlIdentifier
-
paramTypes
private final java.util.List<RelDataType> paramTypes
-
-
Constructor Detail
-
SqlFunction
public SqlFunction(java.lang.String name, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory category)
Creates a new SqlFunction for a call to a builtin function.- Parameters:
name
- Name of builtin functionkind
- kind of operator implemented by functionreturnTypeInference
- strategy to use for return type inferenceoperandTypeInference
- strategy to use for parameter type inferenceoperandTypeChecker
- strategy to use for parameter type checkingcategory
- categorization for function
-
SqlFunction
public SqlFunction(SqlIdentifier sqlIdentifier, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, java.util.List<RelDataType> paramTypes, SqlFunctionCategory funcType)
Creates a placeholder SqlFunction for an invocation of a function with a possibly qualified name. This name must be resolved into either a builtin function or a user-defined function.- Parameters:
sqlIdentifier
- possibly qualified identifier for functionreturnTypeInference
- strategy to use for return type inferenceoperandTypeInference
- strategy to use for parameter type inferenceoperandTypeChecker
- strategy to use for parameter type checkingparamTypes
- array of parameter typesfuncType
- function category
-
SqlFunction
protected SqlFunction(java.lang.String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, java.util.List<RelDataType> paramTypes, SqlFunctionCategory category)
Internal constructor.
-
-
Method Detail
-
getSyntax
public SqlSyntax getSyntax()
Description copied from class:SqlOperator
Returns the syntactic type of this operator, never null.- Specified by:
getSyntax
in classSqlOperator
-
getSqlIdentifier
public SqlIdentifier getSqlIdentifier()
- Returns:
- fully qualified name of function, or null for a builtin function
-
getNameAsId
public SqlIdentifier getNameAsId()
Description copied from class:SqlOperator
Returns the fully-qualified name of this operator.- Overrides:
getNameAsId
in classSqlOperator
-
getParamTypes
public java.util.List<RelDataType> getParamTypes()
- Returns:
- array of parameter types, or null for builtin function
-
getParamNames
public java.util.List<java.lang.String> getParamNames()
Returns a list of parameter names.The default implementation returns
[arg0, arg1, ..., argN]
.
-
unparse
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)
Description copied from class:SqlOperator
Writes a SQL representation of a call to this operator to a writer, including parentheses if the operators on either side are of greater precedence.The default implementation of this method delegates to
SqlSyntax.unparse(org.apache.calcite.sql.SqlWriter, org.apache.calcite.sql.SqlOperator, org.apache.calcite.sql.SqlCall, int, int)
.- Overrides:
unparse
in classSqlOperator
-
getFunctionType
@Nonnull public SqlFunctionCategory getFunctionType()
- Returns:
- function category
-
isQuantifierAllowed
public boolean isQuantifierAllowed()
Returns whether this function allows aDISTINCT
orALL
quantifier. The default isfalse
; some aggregate functions returntrue
.
-
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 classSqlOperator
- 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)
-
validateQuantifier
protected void validateQuantifier(SqlValidator validator, SqlCall call)
Throws a validation error if a DISTINCT or ALL quantifier is present but not allowed.
-
deriveType
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call)
Description copied from class:SqlOperator
Derives the type of a call to this operator.This method is an intrinsic part of the validation process so, unlike
SqlOperator.inferReturnType(org.apache.calcite.sql.SqlOperatorBinding)
, specific operators would not typically override this method.- Overrides:
deriveType
in classSqlOperator
- Parameters:
validator
- Validatorscope
- Scope of validationcall
- Call to this operator- Returns:
- Type of call
-
deriveType
private RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call, boolean convertRowArgToColumnList)
-
containsRowArg
private boolean containsRowArg(java.util.List<SqlNode> args)
-
-