Class SqlTypeCoercionRule

All Implemented Interfaces:

public class SqlTypeCoercionRule extends Object implements 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:

  1. Initialize a SqlTypeMappingRules.Builder instance with default mappings of INSTANCE.
  2. Modify the mappings with the Builder.
  3. Construct a new SqlTypeCoercionRule instance with method instance(Map).
  4. Set the SqlTypeCoercionRule instance into the SqlValidator.

The code snippet below illustrates how to implement a customized instance.

     // Initialize a Builder instance with the default mappings.
     Builder builder = SqlTypeMappingRules.builder();

     // Do the tweak, for example, if we want to add a rule to allow
     // coerce BOOLEAN to TIMESTAMP.

     // Initialize a SqlTypeCoercionRules with the new builder mappings.
     SqlTypeCoercionRules typeCoercionRules = SqlTypeCoercionRules.instance(;

     // Set the SqlTypeCoercionRules instance into the SqlValidator.
     SqlValidator.Config validatorConf ...;
     // Use this conf to initialize the SqlValidator.