package foo.bar.MR; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil; import org.apache.hadoop.hbase.mapreduce.TableMapper; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.output.NullOutputFormat; import foo.bar.validate.Const; public class DropRowByTimeStampMapReduce { public static Configuration configuration; public static List<String> rowkeyList = new ArrayList<String>(); public static List<String> qualifierList = new ArrayList<String>(); static { configuration = HBaseConfiguration.create(); configuration.set("hbase.zookeeper.quorum",Const.ZOOKEEPER_QUORAM); configuration.set("hbase.rootdir", Const.HBASE_ROOTDIR); } static class MyMapper extends TableMapper<Text, LongWritable> { public void map(ImmutableBytesWritable row, Result r, Context context) throws InterruptedException, IOException { String tableName = context.getConfiguration().get("tableName"); HTable htbl = new HTable(configuration, tableName); List<Delete> lists = new ArrayList<Delete>(); for (KeyValue kv : r.raw()) { Delete dlt = new Delete(kv.getRow()); dlt.deleteColumn(kv.getFamily(), kv.getQualifier(), kv.getTimestamp()); lists.add(dlt); System.out.println("delete-- gv:"+Bytes.toString(kv.getRow())+",family:"+Bytes.toString(kv.getFamily())+",qualifier:"+Bytes.toString(kv.getQualifier())+",timestamp:"+kv.getTimestamp()); } htbl.delete(lists); htbl.flushCommits(); htbl.close(); } } public static void main(String[] args) throws Exception { if(args.length!=2){ return ; } String tableName = args[0]; String timeStamp = args[1]; Configuration config = HBaseConfiguration.create(); config.set("tableName", tableName); Job job = new Job(config, "ExampleRead"); job.setJarByClass(DropRowByTimeStamp.class); // class that contains mapper Scan scan = new Scan(); scan.setCaching(500); // 1 is the default in Scan, which will be bad for MapReduce jobs scan.setCacheBlocks(false); // don't set to true for MR jobs scan.setTimeStamp(new Long(timeStamp)); TableMapReduceUtil.initTableMapperJob( tableName, // input HBase table name scan, // Scan instance to control CF and attribute selection MyMapper.class, // mapper null, // mapper output key null, // mapper output value job); job.setOutputFormatClass(NullOutputFormat.class); // because we aren't emitting anything from mapper boolean b = job.waitForCompletion(true); if (!b) { throw new IOException("error with job!"); } } }
相关推荐
使用spark读取hbase中的数据,并插入到mysql中
通过java api 接口 利用thrift读取hbase表中的数据 解压后包含两个文件 一个是实验步骤文档 一个是java 代码
spark使用java读取hbase数据做分布式计算.pdf
最近看了hbase的源码根据源码写了一些scala调动hbase表的API,话不多说直接上代码!Hadoop的版本是2.7.3,scala版本是2.1.1,hbase的版本是1.1.2 如果版本不同可以修改pom的依赖项,但要注意版本冲突。 并且在scala...
因工作需要用python通过hbase的thrift服务读取Hbase表数据,发现公司的测试环境还不支持,于是自己动手准备环境,在此我将在安装步骤尽可能描述清楚,旨在给第一次动手安装的朋友,此过程亲测成功! 安装过程如下: ...
从HBase表读取并写入HBase表的简单Spark Streaming项目 #Prereqs运行 创建一个要写入的hbase表:a)启动hbase shell $ hbase shell b)创建表create'/ user / chanumolu / sensor',{NAME =>'data'},{NAME =>'...
java操作Hbase之从Hbase中读取数据写入hdfs中源码,附带全部所需jar包,欢迎下载学习。
一款强大的HBase表管理系统,目前系统集成的功能有,命名空间管理,表管理,列簇管理,标签机制,快照管理,以及一些常见的统计指标展示等,另外,系统还内置了HBaseSQL的功能,欢迎大家下载。 一款强大的HBase表...
java代码将mysql表数据导入HBase表 + 样例mysql表和数据 + HBase表创建
HBase – Hadoop Database,是一...Google运行MapReduce来处理Bigtable中的海量数据,HBase同样利用Hadoop MapReduce来处理HBase中的海量数据;Google Bigtable利用 Chubby作为协同服务,HBase利用Zookeeper作为对应。
HBASE的一个读取数据流程的解析,清晰的画出整个过程,十分有利于理解
Hbase笔记 —— 利用JavaAPI的方式操作Hbase数据库(往hbase的表中批量插入数据)
Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询
springboot搭建的hbase可视化界面 支持hbase的建表与删除 支持根据rowkey查询数据
删除Hbase中某个表的一列值 命令 java -jar deleteOneColumn.jar(这个文件的路径) '表名' '列簇名' '列名'
hbase表结构设计,新建表,查询表语句,删除表数据,删除表的例子。
hbase表操作工具类.连接hbase数据库,根据rowkey删除单条记录,批量删除记录。获取某个字段的值,判断记录是否存在,向hbase表中插单条数据,批量插入到hbase表。 查询表,获取某个字段的值列表,hbase工具
假设有一个不知道是干什么表:) 表里需要存入人员和其相对应的部门信息 HBaseAdmin admin = new HBaseAdmin(configuration); List<Put> putuser = new ArrayList();
4. 陌陌消息HBase表结构设计 5. 性能问题 6. Apache Phoenix 7. 基于Phoenix消息数据查询 第三章 HBase高级 1. 重要工作机制 2. HBase批量装载——Bulk load 3. HBase的协处理器(Coprocessor) 4. HBase事务 5. ...