设为首页 加入收藏

TOP

HBase用一个MR同时写入两张表(二)
2014-11-24 08:32:24 来源: 作者: 【 】 浏览:1
Tags:HBase 一个 同时 写入 张表
Put put = new Put(Bytes.toBytes(name+","+age));
put.add(t1_fam,t1_qua,Bytes.toBytes(age));
context.write(putTable, put);

// write to the second table row=name+webPage,value=webPage
putTable = new ImmutableBytesWritable(table2);
put = new Put(Bytes.toBytes(name+","+webPage));
put.add(t2_fam,t2_qua,Bytes.toBytes(webPage));
context.write(putTable, put);
}
}


上面的代码只用了一个Mapper,同时写入两个HBase表中。这里的要点是设置Mapper的输出key和value的类型,按照上面的代码类型为:ImmutableBytesWritable和Writable,而且在job的声明处要设置输出类型:job.setOutputFormatClass(MultiTableOutputFormat.class);


如何运行上面的程序?


(1)在HBase中创建两张表:
create 'table1','info'
create 'table2','info'
(2)ImportToHB的输入参数如下:
hdfs://master:9000/user/fansy/input/info.dat table1 info age table2 info webPage
(3)直接在eclipse中运行


运行后在HBase中察看输出的数据如下:



首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux下多线程通过蒙特卡洛法来求.. 下一篇Linux下用GDB调试可加载模块

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·怎样用 Python 写一 (2025-12-27 02:49:19)
·如何学习python数据 (2025-12-27 02:49:16)
·想要自学数据分析, (2025-12-27 02:49:14)
·Java 集合框架 - 菜 (2025-12-27 02:19:36)
·Java集合框架最全详 (2025-12-27 02:19:33)