Method invoked on every tuple during foreach evaluation @param input tuple; first column is assumed to have the column to convert @exception java.io.IOException
(Tuple input)
| 51 | * @exception java.io.IOException |
| 52 | */ |
| 53 | @Override |
| 54 | public String exec(Tuple input) throws IOException { |
| 55 | if (input == null || input.size() < 3) |
| 56 | return null; |
| 57 | |
| 58 | String source = (String)input.get(0); |
| 59 | String target = (String)input.get(1); |
| 60 | |
| 61 | if (target == null) { |
| 62 | warn("Replace : Regular expression is null", PigWarning.UDF_WARNING_1); |
| 63 | return null; |
| 64 | } |
| 65 | |
| 66 | if (mPattern == null || ! target.equals(mPattern.pattern())) { |
| 67 | try { |
| 68 | mPattern = Pattern.compile(target); |
| 69 | } catch (Exception e) { |
| 70 | warn("Replace : Mal-Formed Regular expression : " + target, PigWarning.UDF_WARNING_1); |
| 71 | return null; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | String replacewith = (String)input.get(2); |
| 76 | |
| 77 | try { |
| 78 | return mPattern.matcher(source).replaceAll(replacewith); |
| 79 | }catch(Exception e){ |
| 80 | warn("Replace : Failed to process input; error - " + e.getMessage(), PigWarning.UDF_WARNING_1); |
| 81 | return null; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Schema outputSchema(Schema input) { |