重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
小編給大家分享一下hbase-0.96.x相對(duì)hbase-0.94.x有什么改變,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
雷州網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。成都創(chuàng)新互聯(lián)公司自2013年起到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專(zhuān)注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司。
環(huán)境:
Hadoop:hadoop-2.2.0
hbase:hbase-0.96.0
1.org.apache.hadoop.hbase.client.Put
<1>取消了無(wú)參的構(gòu)造方法
<2>Put類(lèi)不再繼承Writable類(lèi)
0.94.6時(shí)public class Put extends Mutation implements HeapSize, Writable, Comparable
0.96.0時(shí)public class Put extends Mutation implements HeapSize, Comparable
解決方法:
由public class MonthUserLoginTimeIndexReducer extends Reducer
改public class MonthUserLoginTimeIndexReducer extends Reducer
2.org.apache.hadoop.hbase.client.Mutation.familyMap
org.apache.hadoop.hbase.client.Mutation.familyMap類(lèi)型改變:
/**
* 0.94.6
* protected Map
*
* 0.96.*
* protected NavigableMap
* org.apache.hadoop.hbase.Cell hbase-0.94.*中是沒(méi)有的
*/
org.apache.hadoop.hbase.KeyValue的改變:
/**
* 0.94.*
* public class KeyValue extends Object implements Writable, HeapSize
*
* 0.96.0
* public class KeyValue extends Object implements Cell, HeapSize, Cloneable
*/
解決方法:將代碼中的List
3. org.apache.hadoop.hbase.KeyValue
0.96.0中方法getFamily已被棄用(Deprecated),改成方法getFamilyArray()
4.org.apache.hadoop.hbase.HTableDescriptor
類(lèi)org.apache.hadoop.hbase.HTableDescriptor的構(gòu)造方法public HTableDescriptor(String name)已被棄用(Deprecated)
解決方法:使用public HTableDescriptor(TableName name)
舊:HTableDescriptor tableDesc = new HTableDescriptor(tableName);
新:HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(tableName));
5.org.apache.hadoop.hbase.client.HTablePool
類(lèi)org.apache.hadoop.hbase.client.HTablePool整個(gè)被棄用(Deprecated)
解決方法:使用HConnection.getTable(String)代替,HConnection是個(gè)接口,類(lèi)CoprocessorHConnection是它唯一的實(shí)現(xiàn)類(lèi):
HRegionServer hRegionServer = new HRegionServer(conf) ;
HConnection connection = HConnectionManager.createConnection(conf);
hConnection = new CoprocessorHConnection(connection,hRegionServer);
6.org.apache.hadoop.hbase.client.Result
方法public KeyValue[] raw()被棄用(Deprecated),建議使用public Cell[] rawCells()
方法getRow被棄用(Deprecated)
方法getFamily被棄用(Deprecated)
方法getQualifier被棄用(Deprecated)
方法getValue被棄用(Deprecated)
方法public List
方法public KeyValue getColumnLatest(byte[] family,byte[] qualifier)被棄用(Deprecated)
Cell中:改成以下方法
getRowArray()
getFamilyArray()
getQualifierArray()
getValueArray()
Result中:增加如下方法
public List
public KeyValue getColumnLatestCell(byte[] family,byte[] qualifier)
改動(dòng):所有ipeijian_data中凡是和【新增用戶活躍用戶流失用戶】相關(guān)的都做如下變化:
舊代碼:if (value.raw().length == 1
新代碼:if (value.rawCells().length == 1
7.job中設(shè)置TableInputFormat.SCAN
0.96.0中去掉了方法:public void write(DataOutput out)throws IOException
之前版本使用conf.set(TableInputFormat.SCAN, StatUtils.convertScanToString(scan));進(jìn)行設(shè)置
StatUtils.convertScanToString的具體實(shí)現(xiàn)為:
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());
}
該方法的實(shí)現(xiàn)與TableMapReduceUtil.convertScanToString(Scan scan)是一樣的。
但是當(dāng)hbase升級(jí)到了0.96.*是對(duì)于類(lèi)Scan棄用(不僅僅是Deprecated,而是Deleted)了方法write,所以上面
的實(shí)現(xiàn)變?yōu)椴徽_
hbase0.96.*中對(duì)該方法進(jìn)行了重新的實(shí)現(xiàn):
public static String convertScanToString(Scan scan) throws IOException {
ClientProtos.Scan proto = ProtobufUtil.toScan(scan);
return Base64.encodeBytes(proto.toByteArray());
}
所以做如下更改:
StatUtils類(lèi)中方法convertScanToString的實(shí)現(xiàn)做如上更改以適配hbase0.96.*
8.cn.m15.ipj.db.hbase.MyPut
自定義的Put類(lèi),比傳統(tǒng)的Put類(lèi)多一個(gè)length,原版和新版代碼比較:
原版:(紅色字體為API變?yōu)樾掳鏁r(shí)報(bào)錯(cuò)的地方)
public class MyPut extends Put {
public MyPut(byte[] row, int length) {
//原因是put的無(wú)參構(gòu)造方法已經(jīng)在新本中消失
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 kv = createPutKeyValue(family, qualifier, ts, value, length);
list.add(kv);
familyMap.put(kv.getFamily(), list);
//familyMap的類(lèi)型已經(jīng)改變
return this;
}
private List
List
//familyMap的類(lèi)型已經(jīng)改變
if (list == null) {
list = new ArrayList
}
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);
}
}
更改之后:
public MyPut(byte[] row, int length) {
super(row,length);
//新增加
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 kv = createPutKeyValue(family, qualifier, ts, value, length);
list.add(kv);
familyMap.put(CellUtil.cloneFamily(kv), list);
return this;
}
private List
List
if (list == null) {
list = new ArrayList
}
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);
}
}
以上是“hbase-0.96.x相對(duì)hbase-0.94.x有什么改變”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!