2017-01-31 4 views
0

Hadoopが新しくなりました。私は、次のコードを知りたい:hadoopのaddCacheFile

DistributedCache.addCacheFile(new Path(args[0]).toUri(), conf); 

私の手段:=>のarg [0] .toUri()

と "addCachFile"

おかげ

答えて

0
について

分散キャッシュのadCacheFile()メソッドは、分散キャッシュに追加するファイルのURI、新しいパス(args [0])を入力引数から取り、そのURIを変換してこのURI i hadoopの分散キャッシュにファイルを追加するために使用されます。

パス - ファイル名またはディレクトリ名を指定できます。

このファイルを分散キャッシュに追加すると、ファイルはすべてのマッパーで使用できるようになります。ファイルサイズが小さい場合は、hadoopの最適化手法の1つです。すべてのノードにアクセス可能にすることで、データへのアクセスを高速化できます。あなたがこれを確認することができます詳細については

: -

https://hadoop.apache.org/docs/r1.2.1/api/org/apache/hadoop/fs/Path.html

Confusion about distributed cache in Hadoop

0

おかげParitoshアフジャ、

私はポリゴン約2つのTXTファイルがあります。この

ため 私の完全なコードを
public class OverlayPhase2 extends Configured implements Tool 
{ 
    public int run(String[] args) throws IOException 
    { 
    JobConf conf = new JobConf(getConf(), OverlayPhase2.class); 
    if (conf == null) { 
    return -1; 
    } 
    conf.setOutputKeyClass(IntWritable.class); 
    conf.setOutputValueClass(Text.class); 
    conf.setMapperClass(OverlayPhase2Mapper.class); 

    conf.setReducerClass(OverlayPhase2Reducer.class); 
    conf.setNumMapTasks(2); 
    conf.setNumReduceTasks(8); 

    DistributedCache.addCacheFile(new Path(args[0]).toUri(), conf); 

    Path inp1 = new Path(arg[1]); 
    Path inp2 = new Path(arg[2]); 
    Path out1 = new Path(arg[3]); 
    FileInputFormat.setInputPaths(conf, inp1); 
    FileInputFormat.setInputPaths(conf, inp2); 
    FileInputFormat.setOutputPath(conf, out1); 
    JobClient.runJob(conf); 
    return 0; 
} 

public static void main(String[] args) throws Exception 
{ 
    int exitCode = ToolRunner.run(new OverlayPhase2(), args); 
    System.exit(exitCode); 
} 

及びIは、Argためを設定する[1]、引数[2]、引数[3]これ:

arg[1] =/home/mostafa/Desktop/b1.txt 
arg[2] = /home/mostafa/Desktop.b2.txt 
arg[3] = /home/mostafa/Desktaop/output 

よく、引数[0]:?

Mostafa