Package org.teiid.translator.jdbc
Class ConvertModifier
- java.lang.Object
-
- org.teiid.translator.jdbc.FunctionModifier
-
- org.teiid.translator.jdbc.ConvertModifier
-
public class ConvertModifier extends FunctionModifier
Base class for handling the convert function.Convert is by far the most complicated pushdown function since it actually represents a matrix of possible functions. Additionally not every source supports the same semantics as our conversions.
Each instance of this class makes a best effort at handling converts for for a given source - compensating for differing string representation, the lack a time type etc.
The choice of conversion logic is as follows:
- Provide specific conversion between the source and target -
addConvert(int, int, FunctionModifier)
mostly one do not need to provide any conversion if the default is cast(srcType AS targetType), however if the source database requires different specific format for example to cast(srctype, targetType FORMAT 'more-info') this conversion needs to be added - Filter common implicit conversions
- Look for a general source conversion -
addSourceConversion(FunctionModifier, int...)
- Look for a general target conversion -
addTypeConversion(FunctionModifier, int...)
. If the source database provides a specific function for converting *any* source datatype to this target datatype then use this to define it. Like in oracle "to_char" function will convert any other data type to string. Use this to define those kind of conversions convert any data type to string. so you can use this for purpose. - Type maps from database data type to Teiid runtime types. -
addTypeMapping(String, int...)
define mappings for every datatype available in database. The cast operation will replace the target type (teiid type) with the given native type in the cast operation generated. Do not need to really look at implicit/explicit conversions that are supported by the source database, because when a cast is defined on the sql it is up to the source database to apply it as implicit or explicit operation. Teiid generates cast always when needed - Drop the conversion
- Provide specific conversion between the source and target -
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConvertModifier.FormatModifier
-
Constructor Summary
Constructors Constructor Description ConvertModifier()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConvert(int sourceType, int targetType, FunctionModifier convert)
void
addNumericBooleanConversions()
void
addSourceConversion(FunctionModifier convert, int... sourceType)
void
addTypeConversion(FunctionModifier convert, int... targetType)
void
addTypeMapping(String nativeType, int... targetType)
static Function
createConvertFunction(LanguageFactory langFactory, Expression expr, String typeName)
IMPORTANT: only for use with default runtime type namesString
getSimpleTypeMapping(int code)
Return the direct type mapping for a given type codeboolean
hasTypeMapping(int type)
Return true if there is a type mapping or simple modifier for the given typevoid
setBooleanNullable(boolean booleanNullable)
void
setWideningNumericImplicit(boolean wideningNumericImplicit)
List<?>
translate(Function function)
Return a List of translated parts (LanguageObject
s and Objects), or null if this FunctionModifier wishes to rely on the default translation of the conversion visitor.-
Methods inherited from class org.teiid.translator.jdbc.FunctionModifier
getCode
-
-
-
-
Method Detail
-
addTypeConversion
public void addTypeConversion(FunctionModifier convert, int... targetType)
-
addSourceConversion
public void addSourceConversion(FunctionModifier convert, int... sourceType)
-
addTypeMapping
public void addTypeMapping(String nativeType, int... targetType)
-
setWideningNumericImplicit
public void setWideningNumericImplicit(boolean wideningNumericImplicit)
-
addConvert
public void addConvert(int sourceType, int targetType, FunctionModifier convert)
-
translate
public List<?> translate(Function function)
Description copied from class:FunctionModifier
Return a List of translated parts (LanguageObject
s and Objects), or null if this FunctionModifier wishes to rely on the default translation of the conversion visitor.- Specified by:
translate
in classFunctionModifier
- Parameters:
function
- IFunction to be translated- Returns:
- List of translated parts, or null
-
createConvertFunction
public static Function createConvertFunction(LanguageFactory langFactory, Expression expr, String typeName)
IMPORTANT: only for use with default runtime type names- Parameters:
langFactory
-expr
-typeName
-- Returns:
-
addNumericBooleanConversions
public void addNumericBooleanConversions()
-
setBooleanNullable
public void setBooleanNullable(boolean booleanNullable)
-
hasTypeMapping
public boolean hasTypeMapping(int type)
Return true if there is a type mapping or simple modifier for the given type- Parameters:
type
-- Returns:
-
getSimpleTypeMapping
public String getSimpleTypeMapping(int code)
Return the direct type mapping for a given type code- Parameters:
code
-- Returns:
-
-