10

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?

Alex K
  • 8,269
  • 9
  • 39
  • 57
activelearner
  • 7,055
  • 20
  • 53
  • 94

1 Answers1

22

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.

Jeremy Beard
  • 2,727
  • 1
  • 20
  • 25