Proposal for implementing a CAST mechanism in Drill.
The casting mechanism would be of two types
- Implicit type casting
- Explicit type casting
- The Implicit type cast would take care of the casting of the lower datatype holders to the higher datatype holders automatically.
Eg. IntHolder would be casted to Float4Holder/Float8Holder directly.
- The explicit type casting would enable the user to use a CAST() function to cast some value to another datatype by specifying the type. The cast function would be a function exposed with syntax similar to standard SQL format.
Eg. SELECT CAST (somevalue AS INT) FROM sometable;
Type conversion rules:
Conversion rules have to be similar to SQL standards.
Implicit type conversion:
- For arithmetic & comparison operators (+, -, *, /, <, >, =, etc) -
- If both operands types are different, Strings would be converted to Double, and then both the operands would be converted to the same type by choosing the type with higher precision.
- For values passed to a Function/UDF -
- The values would be converted to the parameter accepted by the Function.
- In case of multiple overloaded functions are present, the function with least number of conversions would be selected.
- In case there are multiple functions with least number of conversions, there would be an error returned to user for ambiguous function.
Explicit Type Conversion
- User would use the CAST Function for converting types to another specified type.
- For nonconvertible types user gets an error back.
|Workflow||no-reopen-closed, patch-avail, testing [ 12860544 ]||Drill workflow [ 12934246 ]|
|Fix Version/s||0.4.0 [ 12324963 ]|
|Workflow||no-reopen-closed, patch-avail [ 12820300 ]||no-reopen-closed, patch-avail, testing [ 12860544 ]|
|Status||Open [ 1 ]||Resolved [ 5 ]|
|Assignee||Jinfeng Ni [ jni ]|
|Resolution||Fixed [ 1 ]|