Hive - Converting a string to bigint

activelearner picture activelearner · Mar 5, 2015 · Viewed 36.4k times · Source

Suppose I have a string like '00321' and I want to convert it into a BIGINT in Hive, how would I do it?

Follow-up question: would the resulting BIGINT value be 321 or 00321?

Answer

Jeremy Beard picture Jeremy Beard · Mar 5, 2015

You can use the CAST function to cast your STRING to a BIGINT, like so:

SELECT CAST('00321' AS BIGINT) FROM table;

As a BIGINT it will show on the screen and in delimited text files as 321.