Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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

avatar
 
1 ACCEPTED SOLUTION

avatar
Master 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  |
+------+--+

View solution in original post

1 REPLY 1

avatar
Master 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  |
+------+--+