Data type conversions

Similar to SQL, HQL supports both implicit and explicit type conversion. Primitive-type conversion from a narrow to a wider type is known as implicit conversion. However, the reverse conversion is not allowed. All the integral numeric types, FLOAT, and STRING can be implicitly converted to DOUBLE, and TINYINT, SMALLINT, and INT can all be converted to FLOATBOOLEAN types cannot be converted to any other type. There is a data type cross-table describing the allowed implicit conversion between every two types, which can be found at https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types. Explicit-type conversion uses the CAST function with the CAST(value as TYPE) syntax. For example, CAST('100' as INT) will convert the 100 string to the 100 integer value. If the cast fails, such as CAST('INT' as INT), the function returns NULL.

In addition, the BINARY type can only first cast to STRING, then cast from STRING to other types if needed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.232.152