In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Import java.io.IOException;import java.util.HashMap;import java.util.Map;import java.util.Set;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.client.Put;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.MultiTableOutputFormat;import org.apache.hadoop.hbase.mapreduce.TableInputFormat 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.mapreduce.Job;import org.apache.hadoop.util.GenericOptionsParser;public class IndexBuilder {private class MyMapper extends TableMapper {private Map indexes = new HashMap (); private String columnFamily @ Override protected void map (ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException {Set keys = indexes.keySet (); for (byte [] k: keys) {ImmutableBytesWritable indexTableName = indexes.get (k); byte [] val = value.getValue (Bytes.toBytes (columnFamily), k); Put put = new Put (val) / / the rowkey of the index table is the value put.add of the original table (Bytes.toBytes ("F1"), Bytes.toBytes ("id"), key.get (); / / the content of the index table is the rowkey context.write (indexTableName, put) of the original table. } @ Override protected void setup (Context context) throws IOException, InterruptedException {Configuration conf = context.getConfiguration (); String tableName = conf.get ("tableName"); columnFamily = conf.get ("columnFamily"); String [] qualifiers = conf.getStrings ("qualifiers") / / key of indexes is the column name, and value is the index table name for (String Q: qualifiers) {indexes.put (Bytes.toBytes (Q), new ImmutableBytesWritable (Bytes.toBytes (tableName + "-" + Q) } public static void main (String [] args) throws IOException, ClassNotFoundException, InterruptedException {Configuration conf = HBaseConfiguration.create (); String [] otherargs = new GenericOptionsParser (conf, args) .getRemainingArgs () / / remove useless command line arguments / / input parameters: table name, column family name, column name if (otherargs.length < 3) {System.exit (- 1);} String tableName = otherargs [0]; String columnFamily = otherargs [1]; conf.set ("tableName", tableName); conf.set ("columnFamily", columnFamily) String [] qualifiers = new String [otherargs.length-2]; for (int I = 0; I < qualifiers.length; I +) {qualifiers [I] = otherargs [I + 2];} conf.setStrings ("qualifiers", qualifiers); Job job = new Job (conf, tableName); job.setJarByClass (IndexBuilder.class); job.setMapperClass (MyMapper.class); job.setNumReduceTasks (0) Job.setInputFormatClass (TableInputFormat.class); / / you can output multiple tables job.setOutputFormatClass (MultiTableOutputFormat.class); Scan scan = new Scan (); scan.setCaching (1000); TableMapReduceUtil.initTableMapperJob (tableName, scan, MyMapper.class, ImmutableBytesWritable.class, Put.class, job); job.waitForCompletion (true);}}
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.