MCPcopy Create free account
hub / github.com/apache/pig / exec

Method exec

src/org/apache/pig/builtin/REPLACE.java:53–83  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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) {

Callers 2

testREPLACEMethod · 0.95
testReplaceMethod · 0.95

Calls 6

sizeMethod · 0.65
getMethod · 0.65
warnMethod · 0.65
equalsMethod · 0.45
compileMethod · 0.45
getMessageMethod · 0.45

Tested by 2

testREPLACEMethod · 0.76
testReplaceMethod · 0.76