Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mapreduce, consolidated data dictionary table

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report