HBase中怎么将已知表移植到另一张表中
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,本篇内容介绍了"HBase中怎么将已知表移植到另一张表中"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成
千家信息网最后更新 2026年11月01日HBase中怎么将已知表移植到另一张表中
本篇内容介绍了"HBase中怎么将已知表移植到另一张表中"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
将已经存在某张表,比如 blog,将此表中的数据"移植"到另外一张新表中。
/** * 将HBase中一张表的数据移植到另一张表中。 * */public class HBaseAndMapReduce4 { public static void main(String[] args) throws Exception { System.exit(run()); } public static int run() throws Exception { Configuration conf = new Configuration(); conf = HBaseConfiguration.create(conf); conf.set("hbase.zookeeper.quorum", "192.168.226.129"); Job job = Job.getInstance(conf, "findFriend"); job.setJarByClass(HBaseAndMapReduce4.class); //实例化scan对象。 Scan scan = new Scan(); scan.addColumn(Bytes.toBytes("article"), Bytes.toBytes("tags")); scan.addColumn(Bytes.toBytes("author"), Bytes.toBytes("nickname")); TableMapReduceUtil.initTableMapperJob("blog", scan, FindFriendMapper.class, ImmutableBytesWritable.class, ImmutableBytesWritable.class,job); TableMapReduceUtil.initTableReducerJob("friend02", FindFriendReducer.class, job); checkTable(conf); return job.waitForCompletion(true) ? 0 : 1; } private static void checkTable(Configuration conf) throws Exception { Connection con = ConnectionFactory.createConnection(conf); Admin admin = con.getAdmin(); TableName tn = TableName.valueOf("friend02"); if (!admin.tableExists(tn)){ HTableDescriptor htd = new HTableDescriptor(tn); HColumnDescriptor hcd = new HColumnDescriptor("person"); htd.addFamily(hcd); admin.createTable(htd); System.out.println("表不存在,新创建表成功...."); } } public static class FindFriendMapper extends TableMapper{ @Override //key是hbase中的行键 //value是hbase中的所行键的所有数据 protected void map( ImmutableBytesWritable key, Result value, Mapper.Context context) throws IOException, InterruptedException { ImmutableBytesWritable v = null; String[] kStrs = null; List cs = value.listCells(); for (Cell cell : cs) { if ("tags".equals(Bytes.toString(CellUtil.cloneQualifier(cell)))){ kStrs = Bytes.toString(CellUtil.cloneValue(cell)).split(","); } else if ("nickname".equals(Bytes.toString(CellUtil.cloneQualifier(cell)))){ v = new ImmutableBytesWritable(CellUtil.cloneValue(cell)); } } for (String kStr : kStrs) { context.write(new ImmutableBytesWritable(Bytes.toBytes(kStr.toLowerCase())), v); } } } public static class FindFriendReducer extends TableReducer { @Override protected void reduce( ImmutableBytesWritable key, Iterable values, Reducer.Context context) throws IOException, InterruptedException { System.out.println( "key--->"+key.get() ); Put put = new Put(key.get()); StringBuilder vStr = new StringBuilder(); for (ImmutableBytesWritable value : values) { System.out.println( "value-->"+value.get() ); vStr.append((vStr.length() > 0 ? ",":"") + Bytes.toString(value.get())); } put.addColumn(Bytes.toBytes("person"), Bytes.toBytes("nickname"),Bytes.toBytes(vStr.toString())); context.write(key, put); } }} | "HBase中怎么将已知表移植到另一张表中"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
移植
数据
内容
更多
知识
实用
成功
学有所成
接下来
困境
实例
实际
对象
情况
文章
案例
编带
网站
行业
过程
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
新华互联网科技
蓝思科技飞鸽互联网
重生之互联网科技帝国
科技金融是不是互联网金融
今日互联网科技
互联网科技有限公司经营范围
互联网 科技
互联网科技公司电话
互联网 新科技
广州慧亚互联网科技怎么样
剑昆互联网络科技有限公司临桂
互联网金融科技公司干啥的
美国互联网科技公司
互联网安防科技感
本届互联网大会上的黑科技
互联网科技平台产品运营
银川新华互联网科技学校是国营吗
互联网科技的前景
互联网领先科技成果宣传视频
知域互联网科技有限公司官网
什么是科技互联网
有木互联网科技
天下捷融互联网科技
长亮科技 互联网金融
互联网科技大会
互联网科技公司做什么
全球顶尖互联网科技公司
互联网科技商业
朱啸虎曾投资哪些互联网科技企业
陕西云淼互联网科技公司