Generating Separate Output files in Hadoop Streaming

后端 未结 3 970
一向
一向 2020-12-28 10:25

Using only a mapper (a Python script) and no reducer, how can I output a separate file with the key as the filename, for each line of output, rather than having long files o

相关标签:
3条回答
  • 2020-12-28 10:55

    You can either write to a text file on the local filesystem using python file functions or if you want to use HDFS use the Thrift API.

    0 讨论(0)
  • 2020-12-28 10:55

    The input and outputformat classes can be replaced by use of the -inputformat and -outputformat commandline parameters.

    One example of how to do this can be found in the dumbo project, which is a python framework for writing streaming jobs. It has a feature for writing to multiple files, and internally it replaces the output format with a class from its sister project, feathers - fm.last.feathers.output.MultipleTextFiles.

    The reducer then needs to emit a tuple as key, with the first component of the tuple being the path to the directory where the files with the key/value pairs should be written. There might still be multiple files, that depends on the number of reducers and the application.

    I recommend looking into dumbo, it has many features that makes it easier to write Map/Reduce programs on Hadoop in python.

    0 讨论(0)
  • 2020-12-28 11:01

    Is it possible to replace the outputFormatClass, when using streaming? In a native Java implementation you would extend the MultipleTextOutputFormat class and modify the method that names the output file. Then define your implementation as new outputformat with JobConf's setOutputFormat method

    you should verify, if this is possible in streaming too. I donno :-/

    0 讨论(0)
提交回复
热议问题