Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

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

avatar

How do I remove a currency symbol from a string and convert it into an int in Hive? For example, how do I change '124$' into 124?

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