[Solved-3 Solutions] Pig Script REPLACE with pipe symbol ?
Problem:
- If you want to strip characters outside of the curly brackets in rows that look like the following.
- Stripping the '35|' from the front and the trailing '|' from the end.
- Initially working on the first 3 characters, If you try the following but it removes everything.
Solution 1:
|
and{
and}
are special characters in regular expressions and the second parameter forREPLACE
is a regular expression.- Try to escape the characters:
Solution 2:
- Function (UDF) which takes your data as input and returns the processed data. If we want to transform data into a more complex form which cant be achieved simply by REPLACE , we can create a Javascript/Java/Jython/Ruby/Groovy/Python User Defined
Example of Javascript UDF:
Pig Script:
test.js
Solution 3:
- We could use REGEX_EXTRACT :