public class SqlTypeCoercionRule extends Object implements SqlTypeMappingRule
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:
SqlTypeMappingRules.Builder instance
with default mappings of INSTANCE.SqlTypeCoercionRule instance with method
instance(Map).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();
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.
| Modifier and Type | Field and Description |
|---|---|
static ThreadLocal<SqlTypeCoercionRule> |
THREAD_PROVIDERS |
| Modifier and Type | Method and Description |
|---|---|
Map<SqlTypeName,com.google.common.collect.ImmutableSet<SqlTypeName>> |
getTypeMapping()
Returns the type mappings of this rule instance.
|
static SqlTypeCoercionRule |
instance()
Returns an instance.
|
static SqlTypeCoercionRule |
instance(Map<SqlTypeName,com.google.common.collect.ImmutableSet<SqlTypeName>> map)
Returns an instance with specified type mappings.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcanApplyFrompublic static final ThreadLocal<SqlTypeCoercionRule> THREAD_PROVIDERS
public static SqlTypeCoercionRule instance()
public static SqlTypeCoercionRule instance(Map<SqlTypeName,com.google.common.collect.ImmutableSet<SqlTypeName>> map)
public Map<SqlTypeName,com.google.common.collect.ImmutableSet<SqlTypeName>> getTypeMapping()
SqlTypeMappingRuleThe mappings should be immutable.
getTypeMapping in interface SqlTypeMappingRuleCopyright © 2012-2022 Apache Software Foundation. All Rights Reserved.