Package org.apache.calcite.sql.type
Class SqlTypeCoercionRule
java.lang.Object
org.apache.calcite.sql.type.SqlTypeCoercionRule
- All Implemented Interfaces:
SqlTypeMappingRule
Rules that determine whether a type is castable from another type.
These rules specify the conversion matrix with explicit CAST.
The implicit type coercion matrix should be a sub-set of this explicit one. We do not define an implicit type coercion matrix, instead we have specific coercion rules for all kinds of SQL contexts which actually define the "matrix".
To add a new implementation to this class, follow these steps:
- Initialize a
SqlTypeMappingRules.Builderinstance with default mappings ofINSTANCE. - Modify the mappings with the Builder.
- Construct a new
SqlTypeCoercionRuleinstance with methodinstance(Map). - Set the
SqlTypeCoercionRuleinstance into theSqlValidator.
The code snippet below illustrates how to implement a customized instance.
// Initialize a Builder instance with the default mappings. Builder builder = SqlTypeMappingRules.builder(); builder.addAll(SqlTypeCoercionRules.instance().getTypeMapping()); // Do the tweak, for example, if we want to add a rule to allow // coerce BOOLEAN to TIMESTAMP. builder.add(SqlTypeName.TIMESTAMP, builder.copyValues(SqlTypeName.TIMESTAMP) .add(SqlTypeName.BOOLEAN).build()); // Initialize a SqlTypeCoercionRules with the new builder mappings. SqlTypeCoercionRules typeCoercionRules = SqlTypeCoercionRules.instance(builder.map); // Set the SqlTypeCoercionRules instance into the SqlValidator. SqlValidator.Config validatorConf ...; validatorConf.withTypeCoercionRules(typeCoercionRules); // Use this conf to initialize the SqlValidator.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionMap<SqlTypeName,com.google.common.collect.ImmutableSet<SqlTypeName>> Returns the type mappings of this rule instance.static SqlTypeCoercionRuleinstance()Returns an instance.static SqlTypeCoercionRuleinstance(Map<SqlTypeName, com.google.common.collect.ImmutableSet<SqlTypeName>> map) Returns an instance with specified type mappings.static SqlTypeCoercionRuleReturns an instance that allows more lenient type coercion.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.SqlTypeMappingRule
canApplyFrom
-
Field Details
-
THREAD_PROVIDERS
-
-
Method Details
-
instance
Returns an instance. -
lenientInstance
Returns an instance that allows more lenient type coercion. -
instance
public static SqlTypeCoercionRule instance(Map<SqlTypeName, com.google.common.collect.ImmutableSet<SqlTypeName>> map) Returns an instance with specified type mappings. -
getTypeMapping
Description copied from interface:SqlTypeMappingRuleReturns the type mappings of this rule instance.The mappings should be immutable.
- Specified by:
getTypeMappingin interfaceSqlTypeMappingRule
-