Hive:将String转换为Integer

时间:2012-09-10 07:01:04

标签: string hive user-defined-functions hiveql

我正在寻找内置UDF,在我的hive表中将字符串列的值转换为整数,以便使用SELECT和ORDER BY进行排序。我在语言手册中搜索过但没有用。任何其他建议也欢迎。

3 个答案:

答案 0 :(得分:104)

cast(str_column as int)

来自:Language manual UDFs - type conversion functions

答案 1 :(得分:3)

如果该值介于–2147483648和2147483647之间,则cast(string_filed as int)将起作用。否则强制转换(string_filed为bigint)

    hive> select cast('2147483647' as int);
    OK
    2147483647
    
    hive> select cast('2147483648' as int);
    OK
    NULL
    
    hive> select cast('2147483648' as bigint);
    OK
    2147483648

答案 2 :(得分:0)

它将返回NULL,但是如果将其作为BIGINT将显示数字