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
public class CompositeOperandTypeChecker extends java.lang.Object implements SqlOperandTypeChecker
This class allows multiple existingSqlOperandTypeChecker
rules to be combined into one rule. For example, allowing an operand to be either string or numeric could be done by:CompositeOperandsTypeChecking newCompositeRule = new CompositeOperandsTypeChecking(Composition.OR, new SqlOperandTypeChecker[]{stringRule, numericRule});
Similarly a rule that would only allow a numeric literal can be done by:
CompositeOperandsTypeChecking newCompositeRule = new CompositeOperandsTypeChecking(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:
CompositeOperandsTypeChecking newCompositeRule = new CompositeOperandsTypeChecking(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 Classes Modifier and Type Class Description static class
CompositeOperandTypeChecker.Composition
How operands are composed.-
Nested classes/interfaces inherited from interface org.apache.calcite.sql.type.SqlOperandTypeChecker
SqlOperandTypeChecker.Consistency
-
-
Field Summary
Fields Modifier and Type Field Description protected com.google.common.collect.ImmutableList<? extends SqlOperandTypeChecker>
allowedRules
private java.lang.String
allowedSignatures
protected CompositeOperandTypeChecker.Composition
composition
private SqlOperandCountRange
range
-
Constructor Summary
Constructors Constructor Description CompositeOperandTypeChecker(CompositeOperandTypeChecker.Composition composition, com.google.common.collect.ImmutableList<? extends SqlOperandTypeChecker> allowedRules, java.lang.String allowedSignatures, SqlOperandCountRange range)
Package private.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
check(SqlCallBinding callBinding)
boolean
checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
Checks the types of all operands to an operator call.java.lang.String
getAllowedSignatures(SqlOperator op, java.lang.String opName)
Returns a string describing the allowed formal signatures of a call, e.g.SqlOperandTypeChecker.Consistency
getConsistency()
Returns the strategy for making the arguments have consistency types.SqlOperandCountRange
getOperandCountRange()
com.google.common.collect.ImmutableList<? extends SqlOperandTypeChecker>
getRules()
boolean
isOptional(int i)
Returns whether thei
th operand is optional.private int
maxMax(java.util.List<SqlOperandCountRange> ranges)
private int
minMin(java.util.List<SqlOperandCountRange> ranges)
-
-
-
Field Detail
-
range
private final SqlOperandCountRange range
-
allowedRules
protected final com.google.common.collect.ImmutableList<? extends SqlOperandTypeChecker> allowedRules
-
composition
protected final CompositeOperandTypeChecker.Composition composition
-
allowedSignatures
private final java.lang.String allowedSignatures
-
-
Constructor Detail
-
CompositeOperandTypeChecker
CompositeOperandTypeChecker(CompositeOperandTypeChecker.Composition composition, com.google.common.collect.ImmutableList<? extends SqlOperandTypeChecker> allowedRules, @Nullable java.lang.String allowedSignatures, @Nullable SqlOperandCountRange range)
-
-
Method Detail
-
isOptional
public boolean isOptional(int i)
Description copied from interface:SqlOperandTypeChecker
Returns whether thei
th operand is optional.- Specified by:
isOptional
in interfaceSqlOperandTypeChecker
-
getRules
public com.google.common.collect.ImmutableList<? extends SqlOperandTypeChecker> getRules()
-
getConsistency
public SqlOperandTypeChecker.Consistency getConsistency()
Description copied from interface:SqlOperandTypeChecker
Returns the strategy for making the arguments have consistency types.- Specified by:
getConsistency
in interfaceSqlOperandTypeChecker
-
getAllowedSignatures
public java.lang.String getAllowedSignatures(SqlOperator op, java.lang.String opName)
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
public SqlOperandCountRange getOperandCountRange()
- Specified by:
getOperandCountRange
in interfaceSqlOperandTypeChecker
- Returns:
- range of operand counts allowed in a call
-
minMin
private int minMin(java.util.List<SqlOperandCountRange> ranges)
-
maxMax
private int maxMax(java.util.List<SqlOperandCountRange> ranges)
-
checkOperandTypes
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure)
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
-
check
private boolean check(SqlCallBinding callBinding)
-
-