1

UDF のファイル (sample.txt) にアクセスしようとしています。そのファイルを分散キャッシュに入れて、そこから使用したいと考えています。Pig ジョブを実行するために amazon EMR を使用しています。クラスターの作成中に 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

助けてください。

4

1 に答える 1

0

次のコマンドを使用して、ファイルを HDFS にコピーしてみてください。

Hadoop distcp s3n://bucket/file /home/filelocation

次に、次を使用して HDFS 上のファイルの存在を確認します。

hdfs dfs -ls /home/filelocation
于 2015-07-20T09:04:02.943 に答える