自定义 MR1 之 Mapper | 学习笔记

简介: 快速学习自定义 MR1 之 Mapper。

开发者学堂课程【分布式数据库 HBase 快速入门:自定义 MR1 之 Mapper 】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/101/detail/1755


自定义 MR1 之 Mapper


内容介绍

一、自定义 MR1 之 Mapper


一、自定义 MR1 之 Mapper

自定义 HBase-MapReduce1

目标:将 fruit 表中的一部分数据,通过 MR 迁入到 fruit_mr 表中。

分步实现:

1.构建 ReadFruitMapper 类,用于读取 fruit 表中的数据

package com.atguigu . hbase_mr;  

import java.io.IOException;  

import org.apache.hadoop.hbase.cell;  

import org. apache.hadoop. hbase.cellutil;  

import org.apache.hadoop.hbase.client. Put;  

import org.apache.hadoop.hbase.client. Result;  

Import org.apache.hadoop.hbase.io. ImmutableByteswritable;

import org.apache.hadoop.hbase.mapreduce.TableMapper;

import org.apache.hadoop. hbase.util.Bytes;  

Public              class              ReadFruitMapper           extends

TableMapper {

@override

protected void map(ImmutableByteswritable key,Result value,Context context)  

throws IOException,InterruptedException {

Tota1 time spent by a17 maps in occupied slots (ms)=5222Tota1 time spent by a17 reduces in occupied slots (ms)=0Total time spent by al7 map tasks (ms)=5222

Tota1 vcore-mi11iseconds taken by a17 map tasks=5222

Total megabyte-mil7iseconds taken by a17 map tasks=5347328

Map-Reduce Framework

Map input records=3Map output records=3Input split bytes=96spi77ed Records=oFailed shuffles=oMerged Map outputs=o

Gc time elapsed (ms)=272CPu time spent (ms)=2510

Physical memory (bytes) snapshot=222109696virtua7 memory (bytes) snapshot=3001012224Tota1 committed heap usage' (bytes)=152043520

ImportTsv

Bad Lines=o

File Input Format counters

Bytes Read=54

File output Format counters

Bytes written=o

[atguigu@hadoop102 hbase]$

/**

*Extends the base Mapper class to add the required input Key  

*and value classes.

*

*@param  The type of the key.

*@param  The type of the value.

*@see org.apache. hadoop. mapreduce.Mapper

*/

@InterfaceAudience.Public

@InterfaceStability.Stable

public abstract class TableMapper

extends Mapper{

}

import org.apache.hadoop. hbase. mapreduce.TableMapper;

import org.apache. hadoop.hbase.uti1.Bytes;

import java.io.IOException;

public class FruitMapper extends TableMapper

@Override

protected void map(ImmutableBytesWritable key,Result value,Context context) throws

IOException,InterruptedException {

//构建Put对象

Put put = new Put(key.get()) ;

//遍历数据

Cell[] cells = value.rawCells();

cell[] cells = value.rawCells();

for (Cell cell : cells){

if ("name".equals(Bytes.toString(CellUtil.cloneQualifier(cell)))){

  Putadd(cell);

}

}

相关实践学习
lindorm多模间数据无缝流转
展现了Lindorm多模融合能力——用kafka API写入,无缝流转在各引擎内进行数据存储和计算的实验。
云数据库HBase版使用教程
  相关的阿里云产品:云数据库 HBase 版 面向大数据领域的一站式NoSQL服务,100%兼容开源HBase并深度扩展,支持海量数据下的实时存储、高并发吞吐、轻SQL分析、全文检索、时序时空查询等能力,是风控、推荐、广告、物联网、车联网、Feeds流、数据大屏等场景首选数据库,是为淘宝、支付宝、菜鸟等众多阿里核心业务提供关键支撑的数据库。 了解产品详情: https://cn.aliyun.com/product/hbase   ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
JavaEE--通用分页3
JavaEE--通用分页3
27 0
|
关系型数据库 MySQL
JavaEE--通用分页1
JavaEE--通用分页1
38 0
|
3月前
|
分布式计算 Hadoop Java
hadoop编写Mapper类
【7月更文挑战第10天】
18 2
|
10月前
|
Java 数据库连接 网络性能优化
动态mapper日志问题
动态mapper日志问题
63 1
JavaEE--通用分页2
JavaEE--通用分页2
33 0
|
Java 数据库连接 开发者
获得Mapper对象|学习笔记
快速学习获得Mapper对象
243 0
获得Mapper对象|学习笔记
|
SQL Java 数据库连接
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part B)(上)
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part B)
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part B)(上)
|
XML SQL 缓存
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part D)(上)
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part D)
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part D)(上)
|
存储 XML SQL
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part D)(下)
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part D)
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part D)(下)
|
SQL XML Java
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part A)(下)
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part A)
Data Access 之 MyBatis(八)- MyBatis 通用 Mapper(Part A)(下)