我正在尝试访问 UDF 中的文件 (sample.txt)。我想将该文件放在分布式缓存中并从那里使用它。我正在使用亚马逊 EMR 来运行 Pig 作业。我在创建集群时使用 EMR 引导操作将文件 (sample.txt) 复制到 HDFS。
bootstrap.sh(将文件从 s3 复制到 hdfs)
hadoop fs -copyToLocal s3n://s3_path/sample.txt /mnt/sample.txt
UsingSample.java(使用 sample.txt 的 UDF)
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(创建集群并执行 Pig 脚本的脚本)
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
请帮忙。