news 2026/5/26 16:54:52

mapreduce输出乱码的处理

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
mapreduce输出乱码的处理

mapreduce输出乱码的处理,主要在于数据的编码,默认是以utf-8编码。

若数据源不是以utf-8编码,如以gbk编码的。若在mapreduce中要以gbk进行解码。

核心语句:

String str = new String(value.getBytes(), 0, value.getLength(), "GBK");

解释:value.getBytes()是获取字节码数据,转换成字符码是需要加相应编码。

程序实验:

package org.two; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.NullWritable; 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; import java.io.IOException; public class CleanOneDriver { public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException { Configuration conn = new Configuration(); Job job = Job.getInstance(conn); job.setJarByClass(CleanOneDriver.class); job.setMapperClass(CleanOneMapper.class); job.setReducerClass(CleanOneReduce.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(NullWritable.class); FileInputFormat.addInputPath(job,new Path(args[0])); FileOutputFormat.setOutputPath(job,new Path(args[1])); System.exit(job.waitForCompletion(true)?0:1); } private static class CleanOneMapper extends Mapper<LongWritable,Text,Text,NullWritable> { @Override protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, NullWritable>.Context context) throws IOException, InterruptedException { String str = new String(value.getBytes(), 0, value.getLength(), "GBK"); context.write(new Text(str),NullWritable.get()); } } private static class CleanOneReduce extends Reducer<Text,NullWritable,Text,NullWritable> { @Override protected void reduce(Text key, Iterable<NullWritable> values, Reducer<Text, NullWritable, Text, NullWritable>.Context context) throws IOException, InterruptedException { context.write(key,NullWritable.get()); } } }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/22 9:52:57

ccmusic-database详细步骤:基于466MB save.pt权重的本地化部署全流程

ccmusic-database详细步骤&#xff1a;基于466MB save.pt权重的本地化部署全流程 1. 这不是“听歌识曲”&#xff0c;而是一个专注音乐流派的AI分类器 你可能用过那些能识别歌曲名的App&#xff0c;但ccmusic-database干的是另一件事&#xff1a;它不关心“这是哪首歌”&…

作者头像 李华
网站建设 2026/5/20 15:53:01

护眼工具Dark Reader:夜间浏览与屏幕保护的终极解决方案

护眼工具Dark Reader&#xff1a;夜间浏览与屏幕保护的终极解决方案 【免费下载链接】darkreader Dark Reader Chrome and Firefox extension 项目地址: https://gitcode.com/gh_mirrors/da/darkreader 你是否在深夜浏览网页时感到眼睛刺痛&#xff1f;是否尝试过系统自…

作者头像 李华
网站建设 2026/5/26 5:44:15

GenomicSEM:基于GWAS数据的结构方程建模工具

GenomicSEM&#xff1a;基于GWAS数据的结构方程建模工具 【免费下载链接】GenomicSEM R-package for structural equation modeling based on GWAS summary data 项目地址: https://gitcode.com/gh_mirrors/ge/GenomicSEM 一、工具概述与核心价值 GenomicSEM是一款专为…

作者头像 李华
网站建设 2026/5/20 16:44:50

BGE-Reranker-v2-m3省钱部署:按需计费GPU降低50%成本

BGE-Reranker-v2-m3省钱部署&#xff1a;按需计费GPU降低50%成本 在构建RAG系统时&#xff0c;你是否遇到过这样的问题&#xff1a;向量检索返回了10个文档&#xff0c;但真正有用的只有第7个&#xff1f;前几条全是关键词匹配的“伪相关”结果&#xff0c;大模型却照单全收&a…

作者头像 李华
网站建设 2026/5/23 15:06:03

5个维度解析OpCore Simplify:让智能硬件配置效率提升80%

5个维度解析OpCore Simplify&#xff1a;让智能硬件配置效率提升80% 【免费下载链接】OpCore-Simplify A tool designed to simplify the creation of OpenCore EFI 项目地址: https://gitcode.com/GitHub_Trending/op/OpCore-Simplify 你是否曾因繁琐的黑苹果配置流程而…

作者头像 李华