In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
HBASE implements second-level Index based on coprocessor
The scenario is as follows: store UC_TWEETS table, ROWKEY design: folderId_dayId_siteId_docId, export has the following requirements: export according to campaignId, so you need to store the index table of campaignId
The implementation steps are as follows:
First, the code is implemented as follows:
Public class HbaseCoprocessor extends BaseRegionObserver {
@ Override
Public void prePut (final ObserverContext e, final Put put
Final WALEdit edit, final Durability durability) throws IOException {
Configuration configuration = HBaseConfiguration.create ()
Configuration.set ("hbase.regionserver.lease.period", "900000")
Configuration.set ("hbase.rpc.timeout", "1800000")
Configuration.set ("hbase.client.scanner.timeout.period", "1800000")
Configuration.set ("hbase.zookeeper.property.clientPort", "2181")
Configuration.set ("hbase.zookeeper.quorum", "DEV-HADOOP-01,DEV-HADOOP-02,DEV-HADOOP-03")
Configuration.set ("hbase.master", "DEV-HADOOP-01:60000")
HTable table = new HTable (configuration, "UC_INDEX")
List kv = put.get ("F1" .getBytes (), "campaignId" .getBytes ())
Iterator kvItor = kv.iterator ()
While (kvItor.hasNext ()) {
KeyValue tmp = (KeyValue) kvItor.next ()
String rowkey = new String (tmp.getRow ())
String value = new String (tmp.getValue ())
String newRowkey = value + "_" + rowkey
Put indexPut = new Put (newRowkey.getBytes ())
IndexPut.add ("F1" .getBytes (), tmp.getQualifier (), tmp.getValue ())
Table.put (indexPut)
}
Table.close ()
}
}
Second, export the above HbaseCoprocessor class. Select Export-> Jar File to export to a ucTweet.jar file
Third, upload the ucTweet.jar file to HDFS with the following command:. / hadoop fs-put / data/server/ucTweet_index.jar / jars
4. Set the coprocessor attribute of the UC_TWEETS table. The command is as follows: alter 'UC_TWEETS',METHOD= >' table_att','coprocessor'= > 'hdfs://192.168.9.110:9000/jars/ucTweet.jar | com.prime.dsc.inputservice.coprocessor.HbaseCoprocessor | 1001 |'
Fifth, insert the data into the UC_TWEETS table. If the UC_INDEX table also has data and conforms to the design, the secondary index is established successfully.
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.