簡體   English   中英

如何將內容從映射器寫入文件-Hadoop

[英]How to write the contents from mapper into file - Hadoop

如何將映射器的內容寫入文件。 這樣好嗎

public class MyMapper extends
        Mapper<Object, Text, Text, MatrixWritable > {
public void map(Object key, Text value, Context context)
            throws IOException, InterruptedException {

 Configuration conf = new Configuration();
  FileSystem fs = FileSystem.get(conf);

  Path inputfile = new Path("in/map");
  BufferedWriter getdatabuffer = new BufferedWriter(new OutputStreamWriter(fs.create(inputfile)));
  if(value.toString()!= null){
             getdatabuffer.write(value.toString());
         }
             getdatabuffer.close();

如果我的輸入文件被分割,上面的代碼是否工作正常?

在reducer中,我正在組合所有映射器數據。

編輯

        Path inputfile = new Path("in/map");
             FSDataOutputStream out = fs.create(inputfile);
         if(value.toString()!= null){
            out.writeBytes(value.toString());
         }
            out.close();

映射器任務在Hadoop集群中的多個節點上同時運行。 您使用普通Java Writer類進行寫入的方法僅由於需要使用HDFS API寫入數據而無法使用。

而是在map方法中使用context.write()將數據寫入HDFS文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM