Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive: Convert String to Integer

I am looking for a Built-in UDF to convert values of a string column to integer in my hive table for sorting using SELECT and ORDER BY. I searched in the Language Manual, but no use. Any other suggestions also welcome.

like image 265
Srinivas Avatar asked Sep 10 '12 07:09

Srinivas


People also ask

How do I convert a string to an int in hive?

Converting a String column to an Integer column or converting a column from one type to another is quite simple in Hive. Simply use the cast function to cast the type from one to another.

How do you change the datatype in hive?

Hive CAST(from_datatype as to_datatype) function is used to convert from one data type to another for example to cast String to Integer(int), String to Bigint, String to Decimal, Decimal to Int data types, and many more.

How do I convert a string to a date in hive?

2.3 to_date(string timestamp) – Converts Timestamp string to Date type. to_date() function takes timestamp as an input string in the default format yyyy-MM-dd HH:mm:ss and converts into Date type.

What is Concat_ws in hive?

Description. CONCAT_WS() stands for Concatenate With Separator and is a special form of CONCAT() . The first argument is the separator for the rest of the arguments. The separator is added between the strings to be concatenated. The separator can be a string, as can the rest of the arguments.


1 Answers

cast(str_column as int)

From: Language manual UDFs - type conversion functions

like image 89
Joe K Avatar answered Sep 22 '22 21:09

Joe K