Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How do I remove currency symbol from string and convert into int in hive? EXAMPLE (124$ INTO 124)

Solved Go to solution
Highlighted

How do I remove currency symbol from string and convert into int in hive? EXAMPLE (124$ INTO 124)

 
1 ACCEPTED SOLUTION

Accepted Solutions

Re: How do I remove currency symbol from string and convert into int in hive? EXAMPLE (124$ INTO 124)

Super Guru
@Venkat

Use regexp_replace function in hive to replace $ with '' then cast to int.

Example:

select int(regexp_replace(string("124$"),'\\$',''));
+------+--+
| _c0  |
+------+--+
| 124  |
+------+--+

(or)

Starting from Hive-1.3 version use replace function.

select int(replace(string("124$"),'$',''));
+------+--+
| _c0  |
+------+--+
| 124  |
+------+--+
1 REPLY 1

Re: How do I remove currency symbol from string and convert into int in hive? EXAMPLE (124$ INTO 124)

Super Guru
@Venkat

Use regexp_replace function in hive to replace $ with '' then cast to int.

Example:

select int(regexp_replace(string("124$"),'\\$',''));
+------+--+
| _c0  |
+------+--+
| 124  |
+------+--+

(or)

Starting from Hive-1.3 version use replace function.

select int(replace(string("124$"),'$',''));
+------+--+
| _c0  |
+------+--+
| 124  |
+------+--+
Don't have an account?
Coming from Hortonworks? Activate your account here