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
Nested ClassesModifier and TypeClassDescriptionstatic enumHow operands are composed.Nested classes/interfaces inherited from interface org.apache.calcite.sql.type.SqlOperandTypeChecker
SqlOperandTypeChecker.Consistency -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.google.common.collect.ImmutableList<@UnknownKeyFor ? extends SqlOperandTypeChecker>protected final CompositeOperandTypeChecker.Composition -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCompositeOperandTypeChecker(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 TypeMethodDescriptionbooleancheckOperandTypes(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()booleanisOptional(int i) Returns whether theith operand is optional.@Nullable SqlOperandTypeInferenceConverts 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, waitMethods 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:SqlOperandTypeCheckerReturns a copy of this checker with the given signature generator.- Specified by:
withGeneratorin interfaceSqlOperandTypeChecker
-
isOptional
public boolean isOptional(int i) Description copied from interface:SqlOperandTypeCheckerReturns whether theith operand is optional.- Specified by:
isOptionalin interfaceSqlOperandTypeChecker
-
getRules
-
getAllowedSignatures
Description copied from interface:SqlOperandTypeCheckerReturns a string describing the allowed formal signatures of a call, e.g. "SUBSTR(VARCHAR, INTEGER, INTEGER)".- Specified by:
getAllowedSignaturesin 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:SqlOperandTypeCheckerReturns the range of operand counts allowed in a call.- Specified by:
getOperandCountRangein interfaceSqlOperandTypeChecker
-
checkOperandTypes
Description copied from interface:SqlOperandTypeCheckerChecks the types of all operands to an operator call.- Specified by:
checkOperandTypesin 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:SqlOperandTypeCheckerConverts this type checker to a type inference; returns null if not possible.- Specified by:
typeInferencein interfaceSqlOperandTypeChecker
-