2013-10-11 18 views
6

Tôi cố gắng để tách đầu ra của tôi từ giảm tốc đến các thư mục khác nhau ..Viết cho nhiều thư mục trong hadoop?

My dirver has the following code: 
FileOutputFormat.setOutputPath(job, new Path(output)); 
      //MultipleOutputs.addNamedOutput(job, namedOutput, outputFormatClass, keyClass, valueClass) 
      //MultipleOutputs.addNamedOutput(job, namedOutput, outputFormatClass, keyClass, valueClass) 
      MultipleOutputs.addNamedOutput(job, "foo", TextOutputFormat.class, NullWritable.class, Text.class); 
      MultipleOutputs.addNamedOutput(job, "bar", TextOutputFormat.class, Text.class,NullWritable.class); 
      MultipleOutputs.addNamedOutput(job, "foobar", TextOutputFormat.class, Text.class, NullWritable.class); 

And then my reducer has the following code: 
mos.write("foo",NullWritable.get(),new Text(jsn.toString())); 
mos.write("bar", key,NullWritable.get()); 
mos.write("foobar", key,NullWritable.get()); 

But in the output, I see: 

output/foo-r-0001 
output/foo-r-0002 
output/foobar-r-0001 
output/bar-r-0001 


But what I am trying is : 

output/foo/part-r-0001 
output/foo/part-r-0002 
output/bar/part-r-0001 

đầu ra/foobar/part-r-0001

Làm thế nào để làm điều này? Cảm ơn

+1

phiên bản Hadoop này là gì? –

Trả lời

4

Nếu bạn có ý nghĩa MultipleOutputs này, cách đơn giản nhất sẽ được làm một trong những điều sau đây từ bạn giảm -

  1. Sử dụng tên đầu ra với một con đường ra căn cứ. See this function.
  2. Nếu không có đầu ra được đặt tên và chỉ sử dụng một đường dẫn đầu ra cơ sở, See this function

Trong trường hợp của bạn, nó là điểm 1, vì vậy, hãy thay đổi như sau -

mos.write("foo",NullWritable.get(),new Text(jsn.toString())); 
mos.write("bar", key,NullWritable.get()); 
mos.write("foobar", key,NullWritable.get()); 

đến,

mos.write("foo",NullWritable.get(),new Text(jsn.toString()), "foo/part"); 
mos.write("bar", key,NullWritable.get(), "bar/part"); 
mos.write("foobar", key,NullWritable.get(), "foobar/part"); 

Ở đâu, "foo/part", "thanh/một phần""foobar/part" tương ứng với baseOutputPath. Do đó, các thư mục foo, bar và foobar sẽ được tạo và bên trong các tệp part-r-xxxxx đó.

Bạn cũng có thể thử điểm 2 ở trên, điều này thực sự không cần bất kỳ đầu ra nào có tên.

Hãy liên hệ lại với tôi để được giải thích thêm, nếu cần.

Các vấn đề liên quan