千家信息网

hbase-0.96.x相对hbase-0.94.x有什么改变

发表于:2025-02-05 作者:千家信息网编辑
千家信息网最后更新 2025年02月05日,小编给大家分享一下hbase-0.96.x相对hbase-0.94.x有什么改变,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下
千家信息网最后更新 2025年02月05日hbase-0.96.x相对hbase-0.94.x有什么改变

小编给大家分享一下hbase-0.96.x相对hbase-0.94.x有什么改变,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

环境:
Hadoop:hadoop-2.2.0
hbase:hbase-0.96.0
1.org.apache.hadoop.hbase.client.Put
<1>取消了无参的构造方法
<2>Put类不再继承Writable类
0.94.6时public class Put extends Mutation implements HeapSize, Writable, Comparable
0.96.0时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类型改变:
/**
* 0.94.6
* protected Map> familyMap
*
* 0.96.*
* protected NavigableMap> familyMap
* org.apache.hadoop.hbase.Cell hbase-0.94.*中是没有的
*/

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改成List
3. org.apache.hadoop.hbase.KeyValue
0.96.0中方法getFamily已被弃用(Deprecated),改成方法getFamilyArray()
4.org.apache.hadoop.hbase.HTableDescriptor
类org.apache.hadoop.hbase.HTableDescriptor的构造方法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
类org.apache.hadoop.hbase.client.HTablePool整个被弃用(Deprecated)
解决方法:使用HConnection.getTable(String)代替,HConnection是个接口,类CoprocessorHConnection是它唯一的实现类:
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 getColumn(byte[] family,byte[] qualifier)被弃用(Deprecated)
方法public KeyValue getColumnLatest(byte[] family,byte[] qualifier)被弃用(Deprecated)
Cell中:改成以下方法
getRowArray()
getFamilyArray()
getQualifierArray()
getValueArray()
Result中:增加如下方法
public List getColumnCells(byte[] family,byte[] qualifier)
public KeyValue getColumnLatestCell(byte[] family,byte[] qualifier)
改动:所有ipeijian_data中凡是和【新增用户活跃用户流失用户】相关的都做如下变化:
旧代码:if (value.raw().length == 1
新代码:if (value.rawCells().length == 1
7.job中设置TableInputFormat.SCAN
0.96.0中去掉了方法:public void write(DataOutput out)throws IOException
之前版本使用conf.set(TableInputFormat.SCAN, StatUtils.convertScanToString(scan));进行设置
StatUtils.convertScanToString的具体实现为:
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());
}
该方法的实现与TableMapReduceUtil.convertScanToString(Scan scan)是一样的。
但是当hbase升级到了0.96.*是对于类Scan弃用(不仅仅是Deprecated,而是Deleted)了方法write,所以上面
的实现变为不正确
hbase0.96.*中对该方法进行了重新的实现:
public static String convertScanToString(Scan scan) throws IOException {
ClientProtos.Scan proto = ProtobufUtil.toScan(scan);
return Base64.encodeBytes(proto.toByteArray());
}
所以做如下更改:
StatUtils类中方法convertScanToString的实现做如上更改以适配hbase0.96.*
8.cn.m15.ipj.db.hbase.MyPut
自定义的Put类,比传统的Put类多一个length,原版和新版代码比较:
原版:(红色字体为API变为新版时报错的地方)

public class MyPut extends Put {
public MyPut(byte[] row, int length) {
//原因是put的无参构造方法已经在新本中消失
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 list = getKeyValueList(family);
KeyValue kv = createPutKeyValue(family, qualifier, ts, value, length);
list.add(kv);
familyMap.put(kv.getFamily(), list);
//familyMap的类型已经改变
return this;
}
private List getKeyValueList(byte[] family) {
List list = familyMap.get(family);
//familyMap的类型已经改变
if (list == null) {
list = new ArrayList(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);
}
}

更改之后:

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 list = getCellsList(family);
KeyValue kv = createPutKeyValue(family, qualifier, ts, value, length);
list.add(kv);
familyMap.put(CellUtil.cloneFamily(kv), list);
return this;
}
private List getCellsList(byte[] family) {
List list = familyMap.get(family);
if (list == null) {
list = new ArrayList(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);
}
}

以上是"hbase-0.96.x相对hbase-0.94.x有什么改变"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

方法 代码 用户 篇文章 类型 内容 原版 不仅仅 不怎么 传统 原因 地方 大部分 如上 字体 建议 接口 时报 更多 版本 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 mui设置数据库地址 能在电脑上自学软件开发吗 青海软件开发外包详情 软件开发是个体劳动 数据库数据表定义语句 辽阳直销商城软件开发 四级考试网络技术教材 海南家用软件开发服务价格 温州吉加软件开发 结合教学工作落实网络安全 java软件开发最新面试题 手机测试腾讯服务器延迟 怀柔区信息化软件开发大概费用 华为手机如何设置网络安全 网络安全板块哪个公司好 用户浏览历史数据库设计 软件开发怎么找客户 世界互联网领先科技大学 扫码记录数据库 it网络技术专员招聘 在软件开发项目中 宁波直销软件开发工程 数据库sql语言实验报告南邮 外汇人员对网络技术的要求 软件开发与软件设计相同吗 密云区专业性网络技术推广系统 仓山区服务器维护 网络技术有什么推荐的书吗 红星美凯龙软件开发岗怎么样 智慧食堂网络安全性如何保证
0