Class SqlConvertFunction
- Direct Known Subclasses:
SqlTranslateFunction
CONVERT
function, which converts a string from one character
set to another.
Also the base class for the CONVERT(string USING transcoding)
and TRANSLATE(string USING transcoding)
functions (see
SqlTranslateFunction
).
The SQL syntax is
CONVERT(characterString, sourceCharset, destCharset)
-
Field Summary
Fields inherited from class org.apache.calcite.sql.SqlOperator
kind, MDX_PRECEDENCE, NL
-
Constructor Summary
ModifierConstructorDescriptionprotected
SqlConvertFunction
(String name) protected
SqlConvertFunction
(String name, SqlKind kind, @Nullable SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, @Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory category) -
Method Summary
Modifier and TypeMethodDescription<R> void
acceptCall
(SqlVisitor<R> visitor, SqlCall call, boolean onlyExpressions, SqlBasicVisitor.ArgHandler<R> argHandler) Accepts aSqlVisitor
, directing anSqlBasicVisitor.ArgHandler
to visit an operand of a call.boolean
checkOperandTypes
(SqlCallBinding callBinding, boolean throwOnFailure) Checks that the operand values in aSqlCall
to this operator are valid.deriveType
(SqlValidator validator, SqlValidatorScope scope, SqlCall call) Derives the type of a call to this operator.Returns a constraint on the number of operands expected by this operator.getSignatureTemplate
(int operandsCount) Returns a template describing how the operator signature is to be built.void
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.Methods inherited from class org.apache.calcite.sql.SqlFunction
getFunctionType, getNameAsId, getParamNames, getParamTypes, getSqlIdentifier, getSyntax, isQuantifierAllowed, validateQuantifier
Methods inherited from class org.apache.calcite.sql.SqlOperator
acceptCall, adjustType, allowsFraming, argumentMustBeScalar, checkOperandCount, constructArgNameList, constructArgTypeList, constructOperandList, createCall, createCall, createCall, createCall, createCall, createCall, createCall, deriveOperandType, equals, getAllowedSignatures, getAllowedSignatures, getKind, getLeftPrec, getMonotonicity, getMonotonicity, getName, getOperandTypeChecker, getOperandTypeInference, getReturnTypeInference, getRightPrec, getStrongPolicyInference, hashCode, inferReturnType, inferReturnType, isAggregator, isDeterministic, isDynamicFunction, isGroup, isGroupAuxiliary, isName, isSymmetrical, leftPrec, not, preValidateCall, requiresDecimalExpansion, requiresOrder, requiresOver, reverse, rewriteCall, rightPrec, toString, unparseListClause, unparseListClause, validateOperands, validRexOperands
-
Constructor Details
-
SqlConvertFunction
-
SqlConvertFunction
protected SqlConvertFunction(String name, SqlKind kind, @Nullable SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, @Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory category)
-
-
Method Details
-
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:
-
acceptCall
public <R> void acceptCall(SqlVisitor<R> visitor, SqlCall call, boolean onlyExpressions, SqlBasicVisitor.ArgHandler<R> argHandler) Description copied from class:SqlOperator
Accepts aSqlVisitor
, directing anSqlBasicVisitor.ArgHandler
to visit an operand of a call.The argument handler allows fine control about how the operands are visited, and how the results are combined.
- Overrides:
acceptCall
in classSqlOperator
- Parameters:
visitor
- Visitorcall
- Call to visitonlyExpressions
- If true, ignores operands which are not expressions. For example, in the call to theAS
operatorargHandler
- Called for each operand
-
deriveType
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 classSqlFunction
- Parameters:
validator
- Validatorscope
- Scope of validationcall
- Call to this operator- Returns:
- Type of call
-
checkOperandTypes
Description copied from class:SqlOperator
Checks that the operand values in aSqlCall
to this operator are valid. Subclasses must either override this method or supply an instance ofSqlOperandTypeChecker
to the constructor.- Overrides:
checkOperandTypes
in classSqlOperator
- Parameters:
callBinding
- description of callthrowOnFailure
- whether to throw an exception if check fails (otherwise returns false in that case)- Returns:
- whether check succeeded
-
unparse
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 classSqlFunction
-
getSignatureTemplate
Description copied from class:SqlOperator
Returns a template describing how the operator signature is to be built. E.g for the binary + operator the template looks like "{1} {0} {2}" {0} is the operator, subsequent numbers are operands.- Overrides:
getSignatureTemplate
in classSqlOperator
- Parameters:
operandsCount
- is used with functions that can take a variable number of operands- Returns:
- signature template, or null to indicate that a default template will suffice
-
getOperandCountRange
Description copied from class:SqlOperator
Returns a constraint on the number of operands expected by this operator. Subclasses may override this method; when they don't, the range is derived from theSqlOperandTypeChecker
associated with this operator.- Overrides:
getOperandCountRange
in classSqlOperator
- Returns:
- acceptable range
-