Mapreduce, consolidated data dictionary table
The hole has been stepped on for a long time. The result is that the context in the map method is miswritten, resulting in an error.
Source data content. You just want the second column in the data table to be replaced with the second column in the dictionary table. That is, the red in the dictionary table is replaced by the blue of the dictionary table.
/ / data Table data.txt
/ / one 1 two qqq
/ / two 2 two ccc
/ / Dictionary table zidian.txt
/ / 1 male 1sex
/ / 2 female 2sex
/ / 3 unknown 0sex
/ / 4 Marriage 1marry
/ / 5 unmarried 2marry
/ / 6 unknown 0marry
The desired result is
Male
Female
Attach the code:
Import java.io.BufferedReader
Import java.io.FileReader
Import java.io.IOException
Import java.net.URI
Import java.net.URISyntaxException
Import java.util.HashMap
Import java.util.Iterator
Import java.util.Map
Import org.apache.hadoop.conf.Configuration
Import org.apache.hadoop.filecache.DistributedCache
Import org.apache.hadoop.fs.Path
Import org.apache.hadoop.io.Text
Import org.apache.hadoop.mapreduce.Job
Import org.apache.hadoop.mapreduce.Mapper
Import org.apache.hadoop.mapreduce.Reducer
Import org.apache.hadoop.mapreduce.lib.input.FileInputFormat
Import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat
Public class Cache {
Public static class Mapall extends Mapper {
Private Map sexMap = new HashMap ()
Private Path [] localFiles
/ / do distributed cache processing first, and change the data to memory
Public void setup (Context context) throws IOException {
Configuration conf = context.getConfiguration ()
LocalFiles = DistributedCache.getLocalCacheFiles (conf)
For (int I = 0 position I)