hadoop – how to replace characters in hive?

hadoop – how to replace characters in hive?

regexp_replace UDF performs my task. Below is the definition and usage from apache Wiki.

n

regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT):n

n

This returns the string resulting from replacing all substrings in INITIAL_STRINGnthat match the java regular expression syntax defined in PATTERN with instances of REPLACEMENT,

n

e.g.: regexp_replace(foobar, oo|ar, ) returns fb

Custom SerDe might be a way to do it. Or you could use some kind of mediation process with regex_replace:

n

create table tableB as nselect n    columnAn    regexp_replace(description, \\t, ) as descriptionnfrom tableAn;n

hadoop – how to replace characters in hive?

b’

select translate(description,\\t,) from myTable;n

n

n

Translates the input string by replacing the characters present in the from string with the corresponding characters in the to string. This is similar to the translate function in PostgreSQL. If any of the parameters to this UDF are NULL, the result is NULL as well. (Available as of Hive 0.10.0, for string types)

n

Char/varchar support added as of Hive 0.14.0

n

Leave a Reply

Your email address will not be published.