Support Questions
Find answers, ask questions, and share your expertise

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

 
1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

1 REPLY 1

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

View solution in original post