Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Mapreduce, consolidated data dictionary table

Shulou Source: shulou.com Published: 2022-06-03 03:44:16 10月04日 Update

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)

Tags: Data dictionary that is content datasheet results code location examples memory distribution fields forms text methods time men and women red cache blue Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology vpn OPPO Reno Shulou Information Xiaomi