How To Turn A String Into An Integer In Hive SQL For Hadoop

You use the CAST function.

CAST(fieldname AS INT)

Let’s say you have a field called ‘subscription_ids’ in the ‘subscriber’ table that someone saved as a string but actually should be integers.

To change this to an integer, you would use the command:

SELECT CAST(subscription_ids AS INT) as subscription_ids_as_int

FROM Subscriber

Related books picked – and if possible read – by me. Sponsored by Amazon Associates.

Leave a Reply

Your email address will not be published. Required fields are marked *