Package org.apache.calcite.sql.type
Class CompositeOperandTypeChecker
java.lang.Object
org.apache.calcite.sql.type.CompositeOperandTypeChecker
- All Implemented Interfaces:
SqlOperandTypeChecker
- Direct Known Subclasses:
CompositeSingleOperandTypeChecker
This class allows multiple existing
SqlOperandTypeChecker
rules to be
combined into one rule. For example, allowing an operand to be either string
or numeric could be done by:
CompositeOperandTypeChecker newCompositeRule = new CompositeOperandTypeChecker(Composition.OR, new SqlOperandTypeChecker[]{stringRule, numericRule});
Similarly a rule that would only allow a numeric literal can be done by:
CompositeOperandTypeChecker newCompositeRule = new CompositeOperandTypeChecker(Composition.AND, new SqlOperandTypeChecker[]{numericRule, literalRule});
Finally, creating a signature expecting a string for the first operand and a numeric for the second operand can be done by:
CompositeOperandTypeChecker newCompositeRule = new CompositeOperandTypeChecker(Composition.SEQUENCE, new SqlOperandTypeChecker[]{stringRule, numericRule});
For SEQUENCE composition, the rules must be instances of SqlSingleOperandTypeChecker, and signature generation is not supported. For AND composition, only the first rule is used for signature generation.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
How operands are composed.Nested classes/interfaces inherited from interface org.apache.calcite.sql.type.SqlOperandTypeChecker
SqlOperandTypeChecker.Consistency
-
Field Summary
Modifier and TypeFieldDescriptionprotected final com.google.common.collect.ImmutableList<@UnknownKeyFor ? extends SqlOperandTypeChecker>
protected final CompositeOperandTypeChecker.Composition
-
Constructor Summary
ModifierConstructorDescriptionprotected
CompositeOperandTypeChecker
(CompositeOperandTypeChecker.Composition composition, com.google.common.collect.ImmutableList<? extends SqlOperandTypeChecker> allowedRules, @Nullable String allowedSignatures, @Nullable BiFunction<SqlOperator, String, String> signatureGenerator, @Nullable SqlOperandCountRange range) Creates a CompositeOperandTypeChecker. -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkOperandTypes
(SqlCallBinding callBinding, boolean throwOnFailure) Checks the types of all operands to an operator call.getAllowedSignatures
(SqlOperator op, String opName) Returns a string describing the allowed formal signatures of a call, e.g.Returns the range of operand counts allowed in a call.com.google.common.collect.ImmutableList<? extends SqlOperandTypeChecker>
getRules()
boolean
isOptional
(int i) Returns whether thei
th operand is optional.@Nullable SqlOperandTypeInference
Converts this type checker to a type inference; returns null if not possible.withGenerator
(BiFunction<SqlOperator, String, String> signatureGenerator) Returns a copy of this checker with the given signature generator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.calcite.sql.type.SqlOperandTypeChecker
and, getConsistency, isFixedParameters, or
-
Field Details
-
allowedRules
protected final com.google.common.collect.ImmutableList<@UnknownKeyFor ? extends SqlOperandTypeChecker> allowedRules -
composition
-
-
Constructor Details
-
CompositeOperandTypeChecker
protected CompositeOperandTypeChecker(CompositeOperandTypeChecker.Composition composition, com.google.common.collect.ImmutableList<? extends SqlOperandTypeChecker> allowedRules, @Nullable String allowedSignatures, @Nullable BiFunction<SqlOperator, String, String> signatureGenerator, @Nullable SqlOperandCountRange range) Creates a CompositeOperandTypeChecker. Outside this package, useSqlOperandTypeChecker.and(SqlOperandTypeChecker)
,OperandTypes.and(org.apache.calcite.sql.type.SqlOperandTypeChecker...)
,OperandTypes.or(org.apache.calcite.sql.type.SqlOperandTypeChecker...)
and similar.
-
-
Method Details
-
withGenerator
public CompositeOperandTypeChecker withGenerator(BiFunction<SqlOperator, String, String> signatureGenerator) Description copied from interface:SqlOperandTypeChecker
Returns a copy of this checker with the given signature generator.- Specified by:
withGenerator
in interfaceSqlOperandTypeChecker
-
isOptional
public boolean isOptional(int i) Description copied from interface:SqlOperandTypeChecker
Returns whether thei
th operand is optional.- Specified by:
isOptional
in interfaceSqlOperandTypeChecker
-
getRules
-
getAllowedSignatures
Description copied from interface:SqlOperandTypeChecker
Returns a string describing the allowed formal signatures of a call, e.g. "SUBSTR(VARCHAR, INTEGER, INTEGER)".- Specified by:
getAllowedSignatures
in interfaceSqlOperandTypeChecker
- Parameters:
op
- the operator being checkedopName
- name to use for the operator in case of aliasing- Returns:
- generated string
-
getOperandCountRange
Description copied from interface:SqlOperandTypeChecker
Returns the range of operand counts allowed in a call.- Specified by:
getOperandCountRange
in interfaceSqlOperandTypeChecker
-
checkOperandTypes
Description copied from interface:SqlOperandTypeChecker
Checks the types of all operands to an operator call.- Specified by:
checkOperandTypes
in interfaceSqlOperandTypeChecker
- Parameters:
callBinding
- description of the call to be checkedthrowOnFailure
- whether to throw an exception if check fails (otherwise returns false in that case)- Returns:
- whether check succeeded
-
typeInference
Description copied from interface:SqlOperandTypeChecker
Converts this type checker to a type inference; returns null if not possible.- Specified by:
typeInference
in interfaceSqlOperandTypeChecker
-