HBase中怎么将已知表移植到另一张表中
发表于:2025-12-01 作者:千家信息网编辑
千家信息网最后更新 2025年12月01日,本篇内容介绍了"HBase中怎么将已知表移植到另一张表中"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成
千家信息网最后更新 2025年12月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安全错误
数据库的锁怎样保障安全
网络安全实训是做什么的
软件开发行业缺人
用数据库做服务器
福建网络技术服务报价
共享网络安全主题活动
山西工业软件开发成本价
网络安全红蓝对抗思路
网络安全领域重点保护哪些领域
数据防泄密软件开发公司怎么样
网络安全 接入安全
智赢收款机怎么备份数据库
服务器的小电风扇三线怎样接线
数据库起名
网络安全新驱动新特点新常态
智能安全行车服务器idas
反欺诈系统软件开发环境
华为网络技术工程师15k
水果店管理系统数据库代码
最新网络安全通报预警
oracle数据库连接名
平江县软件开发培训班
数据库授予语句题目
安徽网络技术推广
无限低速网络技术
软件开发工程师厉害吗
服务器黑屏但是可以开机
毕业设计软件开发
网吧网络安全审核登记表
post上传图片到服务器
兰州佳桥通信网络技术有限公司