Changes in hbase 0.96 to hbase 0.94

Source: Internet
Author: User
Tags comparable

 

Reprinted: http://blog.csdn.net/hxpjava1/article/details/20043703

Environment:
Hadoop: hadoop-2.2.0
Hbase: hbase-0.96.0.
1.org. Apache. hadoop. hbase. Client. Put
<1> cancel construction without Parameters
<2> The put class no longer inherits the writable class.
0.94.6 public class put extends mutation implements heapsize, writable, comparable <row>
0.96.0 public class put extends mutation implements heapsize, comparable <row>
Solution:
By public class monthuserlogintimeindexreducer extends reducer <byteswritable, monthuserlogintimeindexwritable, immutablebyteswritable, writable> {
Change public class monthuserlogintimeindexreducer extends reducer <byteswritable, monthuserlogintimeindexwritable, immutablebyteswritable, put> {
2.org. Apache. hadoop. hbase. Client. Mutation. familymap
Org. Apache. hadoop. hbase. Client. Mutation. familymap type changed:
/**
* 0.94.6
* Protected Map <byte [], list <keyValue> familymap
*
* 0. 96 .*
* Protected navigablemap <byte [], list <cell> familymap
* Org. Apache. hadoop. hbase. Cell hbase-0.94. * does not exist.
*/

Org. Apache. hadoop. hbase. keyValue change:
/**
* 0. 94 .*
* Public class keyValue extends object implements writable, heapsize
*
* 0.96.0
* Public class keyValue extends object implements cell, heapsize, cloneable
*/
Solution: Change List <keyValue> In the code to list <cell>
3. org. Apache. hadoop. hbase. keyValue
In 0.96.0, The getfamily method has been deprecated and changed to the getfamilyarray () method ()
4.org. Apache. hadoop. hbase. htabledescriptor
The public htabledescriptor (string name) Construction Method of org. Apache. hadoop. hbase. htabledescriptor is deprecated)
Solution: use public htabledescriptor (tablename name)
Old: htabledescriptor tabledesc = new htabledescriptor (tablename );
New: htabledescriptor tabledesc = new htabledescriptor (tablename. valueof (tablename ));
5.org. Apache. hadoop. hbase. Client. htablepool
Deprecated)
Solution: Use hconnection. gettable (string) instead. hconnection is an interface, and the coprocessorhconnection class is its unique implementation class:
Hregionserver = new hregionserver (CONF );
Hconnection connection = hconnectionmanager. createconnection (CONF );
Hconnection = new coprocessorhconnection (connection, hregionserver );
6.org. Apache. hadoop. hbase. Client. Result
The public keyValue [] raw () method is deprecated. We recommend that you use public cell [] rawcells ()
The getrow method is deprecated)
The getfamily method is deprecated)
The getqualifier method is deprecated)
The getvalue method is deprecated)
Method public list <keyValue> getcolumn (byte [] family, byte [] qualifier) Deprecated)
Method public keyValue getcolumnlatest (byte [] family, byte [] qualifier) Deprecated)
Cell: change to the following method:
Getrowarray ()
Getfamilyarray ()
Getqualifierarray ()
Getvaluearray ()
Result: add the following method:
Public list <keyValue> getcolumncells (byte [] family, byte [] qualifier)
Public keyValue getcolumnlatestcell (byte [] family, byte [] qualifier)
Change: All ipeijian_data changes related to [new active user loss user] as follows:
Old Code: If (value. Raw (). Length = 1
New Code: If (value. rawcells (). Length = 1
7. Set tableinputformat. Scan in job
The public void write (dataoutput out) throws ioexception method is removed in 0.96.0.
Earlier versions use Conf. Set (tableinputformat. Scan, statutils. convertscantostring (SCAN );
The specific implementation of statutils. convertscantostring is:
Public static string convertscantostring (SCAN scan) throws ioexception {
Bytearrayoutputstream out = new bytearrayoutputstream ();
Dataoutputstream dos = new dataoutputstream (out );
Scan. Write (DOS );
Return base64.encodebytes (Out. tobytearray ());
}
The implementation of this method is the same as tablemapreduceutil. convertscantostring (SCAN scan.
However, when hbase is upgraded to 0. 96. *, the method write is discarded for the class scan (not only deprecated, but deleted), so the above
Is incorrect
Hbase0.96. * implements this method again:
Public static string convertscantostring (SCAN scan) throws ioexception {
Clientprotos. Scan proto = protobufutil. toscan (SCAN );
Return base64.encodebytes (PROTO. tobytearray ());
}
Make the following changes:
Implement convertscantostring in statutils to adapt to hbase0.96 .*
8.cn. m15.ipj. DB. hbase. myput
The custom put class has one more length than the traditional put class. The original and new versions of the Code are compared:
Original version: (the red font indicates the new version of the API)

Public class myput extends put {
Public myput (byte [] row, int length ){
// The cause is that the put no-argument constructor has disappeared in the new version.
If (ROW = NULL | length> hconstants. max_row_length ){
Throw new illegalargumentexception ("row key is invalid ");
}
This. Row = arrays. copyof (row, length );
This. Ts = hconstants. latest_timestamp;
}
Public myput add (byte [] family, byte [] qualifier, long ts, byte [] value, int length ){
List <keyValue> List = getkeyvaluelist (family );
KeyValue KV = createputkeyvalue (family, qualifier, ts, value, length );
List. Add (Kv );
Familymap. Put (Kv. getfamily (), list );
// The familymap type has changed
Return this;
}
Private list <keyValue> getkeyvaluelist (byte [] Family ){
List <keyValue> List = familymap. Get (family );
// The familymap type has changed
If (list = NULL ){
List = new arraylist <keyValue> (0 );
}
Return list;
}
Private keyValue createputkeyvalue (byte [] family, byte [] qualifier, long ts, byte [] value, int length ){
Return new keyValue (this. Row, 0, this. Row. length, family, 0,
Family. length, qualifier, 0, qualifier. length, ts,
KeyValue. type. Put, value, 0, length );
}
}

After modification:

Public myput (byte [] row, int length ){
Super (row, length );
// New
If (ROW = NULL | length> hconstants. max_row_length ){
Throw new illegalargumentexception ("row key is invalid ");
}
This. Row = arrays. copyof (row, length );
This. Ts = hconstants. latest_timestamp;
}
Public myput add (byte [] family, byte [] qualifier, long ts, byte [] value, int length ){
List <cell> List = getcellslist (family );
KeyValue KV = createputkeyvalue (family, qualifier, ts, value, length );
List. Add (Kv );
Familymap. Put (cellutil. clonefamily (Kv), list );
Return this;
}
Private list <cell> getcellslist (byte [] Family ){
List <cell> List = familymap. Get (family );
If (list = NULL ){
List = new arraylist <cell> (0 );
}
Return list;
}
Private keyValue createputkeyvalue (byte [] family, byte [] qualifier, long ts, byte [] value, int length ){
Return new keyValue (this. Row, 0, this. Row. length, family, 0, family. length, qualifier, 0, qualifier. length, ts,
KeyValue. type. Put, value, 0, length );
}
}

 

Changes in hbase 0.96 to hbase 0.94

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.