Dear Wiki user, You have subscribed to a wiki page or wiki category on "Hadoop Wiki" for change notification.
The following page has been changed by ZhengShao: http://wiki.apache.org/hadoop/Hive/HiveQL/Types ------------------------------------------------------------------------------ == Implicit and Explicit Type Conversions == In most cases, users don't need to care about the types because Hive is able to do implicit type conversions. - However there are some cases that user wants to explicitly convert the type. + However there are some cases that user wants to explicitly convert the type. Please see + === Implicit Type Conversion Rules === + If the operator is an arithmetic operator (+, -, *, /, etc), STRING will be converted to DOUBLE, and then we will make the 2 operands of the same type, by choosing the type with higher precision. + + If the operator is a comparison operator (=, <>, >, <, etc), STRING will be converted to DOUBLE, and then we will make the 2 operands of the same type, by choosing the type with higher precision. + + Otherwise, the operator is probably a UDF/UDAF function. In that case, we will try to convert the parameters to the types that are accepted by the UDF/UDAF function. + If the UDF/UDAF function is overloaded (with more than 1 implementations with different types), we will try to find the one with least number of type conversions needed. If there are more than 1 with the same least number of type conversions, an error is thrown saying the query is ambiguous. In this case, it is necessary to explicitly convert the types. + + === Explicit Type Conversion Examples === {{{ CAST(1.5 AS INT) = 2 CAST(-1.5 AS INT) = -2
