Pig/hadoop 的新手..
在当地跑猪。
java -Xmx512m -Xmx1024m -cp $PIGDIR/pig.jar org.apache.pig.Main -Dpig.temp.dir=/tmp/$USER/$RANDOM -stop_on_failure -x local script-buzz.pig
用我的 script.pig:
(...)
buzz = FOREACH files GENERATE chiron.buzz.Honey(file, id) as buzz_file, id;
尝试使用我的 UDF raise 编写文件夹/文件:
[JobControl] ERROR org.apache.hadoop.security.UserGroupInformation - PriviledgedActionException as:felipehorta cause:org.apache.pig.backend.executionengine.ExecException: ERROR 2118: Input path does not exist: file:/Users/felipehorta/dev/ufrj/pig/pig-buzz/output
以下代码必须(!)写入在下一次加载时使用的文件。
jar 适用于: $ java -jar Pgm.jar *
(...)
public String exec(Tuple input) throws IOException {
try{
System.out.println(input.get(0).toString());
BumbleBee b = new BumbleBee(input.get(0).toString());
return b.writeRelation(input.get(1).toString());
} catch(Exception e){
System.err.println("Failed to process input; error - " + e.getMessage());
return null;
}
}
public String writeRelation(String folder) throws IOException {
try {
// writing file!
File output = new File("output/ERelation_" + folder + ".txt");
output.getParentFile().mkdirs();
FileWriter fw = new FileWriter(output);
String line = System.getProperty("line.separator");
fw.append("YEAR;WORD;COUNT" + line);
for (Integer year : buzzCandidates.keySet()) {
Map<String, Long> wordCounts = buzzCandidates.get(year);
for (String word : wordCounts.keySet()) {
long value = wordCounts.get(word);
if (value >= 3) {
fw.append(year + ";" + word.replace(" ", "_") + ";" + String.valueOf(value) + line);
}
}
}
fw.flush();
fw.close();
return output.getAbsolutePath();
} catch (Exception e) {
System.out.println(">>> ERROR!!\t" + e.getMessage());
return "ERROR";
}
}
我认为这是关于使用 UDF 写入文件的权限,但我不知道在哪里设置权限。有什么帮助吗?
先谢谢各位了!