In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you about the special usage of HBase API, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's learn about it!
Go directly to the code:
Connection conn = ConnectionFactory.createConnection (conf); TableName tn = TableName.valueOf (strTN); Table table = conn.getTable (tn); RowFilter logFileTableFilter = new RowFilter (CompareFilter.CompareOp.EQUAL, new SubstringComparator ("0UAV0020109000574633450")); Scan s = new Scan (); s.setFilter (logFileTableFilter); ResultScanner ss = table.getScanner (s); for (Result r: ss) {for (Cell cell: r.listCells ()) {KeyValue kv = (KeyValue) cell System.out.print (new String (Arrays.copyOfRange (kv.getFamilyArray (), kv.getFamilyOffset (), kv.getFamilyOffset () + kv.getFamilyLength () + "); System.out.print (new String (Arrays.copyOfRange (kv.getQualifierArray (), kv.getQualifierOffset (), kv.getQualifierOffset () + kv.getQualifierLength () +") System.out.println (new String (Arrays.copyOfRange (kv.getValueArray (), kv.getValueOffset (), kv.getValueOffset () + kv.getValueLength ()) + ");}}
The first part is normal, layer 2 loops, the first layer is the loop result, which simply means the loop row, and the second layer loops each field.
Please note that the part I marked out looks easy to understand, which is to take the column family, column, and value, respectively.
But the truth is not like this. Take a look at the following picture:
All right, let's take another look at the source code:
Public byte [] getFamilyArray () {return this.bytes;} public byte [] getQualifierArray () {return this.bytes;} public byte [] getValueArray () {return this.bytes;}
Isn't this tmd the same thing?
All right, weird is weird, the key is not easy to use, it probably means to give you a byte array, all the data about this field is in this array, and then tell you the offset and length of families, columns, values, and so on, so you can dig it out yourself. If you have to do this every time, don't go crazy.
Arrays.copyOfRange (kv.getValueArray (), kv.getValueOffset (), kv.getValueOffset () + kv.getValueLength ())
Take a look at the following code, there is still a normal api, this is in line with human habits.
For (Result r: ss) {NavigableMap maps = r.getNoVersionMap (); for (byte [] fKey: maps.keySet ()) {NavigableMap map = maps.get (fKey); for (byte [] key: map.keySet ()) {System.out.print (new String (fKey) + ":"); System.out.print (new String (key) + "); System.out.println (new String (map.get (key) The above is all the content of this article "Special HBase API usage". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.