In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to transplant a known table to another table in HBase". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Migrate the data from an existing table, such as blog, to another new table.
/ * migrate data from one table in HBase to another table. * * / 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); / / instantiate the scan object. 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 ("Table does not exist, new table created successfully") }} public static class FindFriendMapper extends TableMapper {@ Override / / key is the row key in hbase / / value is all the data protected void map (ImmutableBytesWritable key, Result value) of all row keys in hbase 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) This is the content of "how to migrate a known table to another table in HBase". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.