1
我試圖訪問UDF中的文件(sample.txt)。我想把這個文件放在分佈式緩存中並從那裏使用它。我正在使用亞馬遜EMR運行Pig作業。我在創建集羣時使用EMR bootstrap-action將文件(sample.txt)複製到HDFS。在豬UDF Java類中訪問分佈式緩存中的文件Amazon EMR
bootstrap.sh(拷貝文件從S3到HDFS)
hadoop fs -copyToLocal s3n://s3_path/sample.txt /mnt/sample.txt
UsingSample.java(UDF使用sample.txt的)
public class UsingSample extends EvalFunc<String>{
public String useSampleText(String str) throws Exception{
File sampleFile = new File(「./sample」);
//do something with sampleFile
}
@Override
public String exec(Tuple input) throws IOException {
if (input == null || input.size() == 0)
return null;
String str = (String) input.get(0);
String result = "";
try {
result = useSampleText(str);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
public List<String> getCacheFiles() {
List<String> list = new ArrayList<String>(1);
list.add("/mnt/sample.txt#sample"); // not sure if the path I am passing is correct
return list;
}
}
create_cluster.sh(腳本,創建羣集並執行腳本豬)
aws emr create-cluster
--auto-terminate
--name "sample cluster"
--ami-version 3.8.0
--enable-debugging
--applications Name=Pig
--use-default-roles
--instance-type m1.large
--instance-count 3
--steps Type=PIG,Name="Pig Program",ActionOnFailure=CONTINUE,Args=[-f,$S3_PIG_SCRIPT_URL,-p,INPUT=$INPUT,-p,OUTPUT=$OUTPUT]
--bootstrap-action Path=s3://s3_bootstrapscript_path/bootstrap.sh
我正的錯誤是試圖getCacheFiles訪問sample.txt的時候FileNotFound異常() 。
我使用:
Hadoop 2.4 Pig 0.12
請幫助。