转载:http://blog.csdn.net/hxpjava1/article/details/20043703

环境:
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<Row>
        0.96.0时public class Put extends Mutation implements HeapSize, Comparable<Row>
解决方法:
        由public class
MonthUserLoginTimeIndexReducer extends
Reducer<BytesWritable,MonthUserLoginTimeIndexWritable,
ImmutableBytesWritable, Writable> {
改public class MonthUserLoginTimeIndexReducer
extends Reducer<BytesWritable,MonthUserLoginTimeIndexWritable,
ImmutableBytesWritable, Put> {
2.org.apache.hadoop.hbase.client.Mutation.familyMap
     org.apache.hadoop.hbase.client.Mutation.familyMap类型改变:
     /**
     * 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.*中是没有的
     */

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<KeyValue>改成List<Cell>
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<KeyValue> getColumn(byte[] family,byte[] qualifier)被弃用(Deprecated)
     方法public KeyValue getColumnLatest(byte[] family,byte[] qualifier)被弃用(Deprecated)
     Cell中:改成以下方法
     getRowArray()
     getFamilyArray()
     getQualifierArray()
     getValueArray()
     Result中:增加如下方法
     public List<KeyValue> 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<KeyValue> list = getKeyValueList(family);
          KeyValue kv = createPutKeyValue(family, qualifier, ts, value, length);
          list.add(kv);
          familyMap.put(kv.getFamily(), list);                                   
          //familyMap的类型已经改变
          return this;
      }
     private List<KeyValue> getKeyValueList(byte[] family) {
          List<KeyValue> list = familyMap.get(family);                     
          //familyMap的类型已经改变
          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);
     }
}

更改之后:

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<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);
     }
}

 

Hbase 0.96 比 hbase 0.94的改变的更多相关文章

  1. 【甘道夫】HBase(0.96以上版本号)过滤器Filter具体解释及实例代码

    说明: 本文參考官方Ref Guide,Developer API和众多博客.并结合实測代码编写.具体总结HBase的Filter功能,并附上每类Filter的对应代码实现. 本文尽量遵从Ref Gu ...

  2. HBase(0.96以上版本)过滤器Filter详解及实例代码

    说明: 本文参考官方Ref Guide,Developer API和众多博客,并结合实测代码编写,详细总结HBase的Filter功能,并附上每类Filter的相应代码实现. 本文尽量遵从Ref Gu ...

  3. Hadoop 2.2 & HBase 0.96 Maven 依赖总结

    由于Hbase 0.94对Hadoop 2.x的支持不是非常好,故直接添加Hbase 0.94的jar依赖可能会导致问题. 但是直接添加Hbase0.96的依赖,由于官方并没有发布Hbase 0.96 ...

  4. hbase 0.96 单机伪分布式配置文件及遇到的问题 find命令

    http://www.apache.org/dyn/closer.cgi/hbase/ 国外的站点下载速度慢,可以考虑国内的镜像网站~ 前面已经部署好了hadoop2.2.0单机伪分布式.必须先安装h ...

  5. hadoop 1.1.2和 hive 0.10 和hbase 0.94.9整合

    今天弄了一下hive0.10和hbase0.94.9整合,需要设置的并不多,但是也遇到了一些问题. 1.复制jar包 拷贝hbase-0.94.9.jar,zookeeper-3.4.5.jar,pr ...

  6. spark1.0.2读取hbase(CDH0.96.1)上的数据

    基本环境: 我是在win7环境下,spark1.0.2,HBase0.9.6.1 使用工具:IDEA14.1, scala 2.11.6, sbt.我现在是测试环境使用的是单节点 1.使用IDEA创建 ...

  7. 通过tarball形式安装HBASE Cluster(CDH5.0.2)——Hadoop NameNode HA 切换引起的Hbase错误,以及Hbase如何基于NameNode的HA进行配置

    通过tarball形式安装HBASE Cluster(CDH5.0.2)——Hadoop NameNode HA 切换引起的Hbase错误,以及Hbase如何基于NameNode的HA进行配置 配置H ...

  8. 从0开始的hbase

    2016马上要结束了,回顾一下这一年对hbase的学习历程. 1,年初hbase的状态 使用场景:主要是用来存储业务线的mysql表,增量同步到hbase,然后每天晚上全量导入hdfs做离线计算. h ...

  9. HFile解析 基于0.96

    什么是HFile HBase.BigTable以及其他分布式存储.查询系统的底层存储都采用SStable的思想,HBase的底层存储是HFile,他要解决的问题就是如果将内容存储到磁盘,以及如何高效的 ...

随机推荐

  1. Objective-C,复合类,Composition

     复合类 5.复合类现实中,复杂的对象都是由较小和较为简单的对象构成:由简单对象创建复杂对象的过程称作合成.合成通常使用在有has-a关系的对象:通常的基本数据类型可以满足构造简单和小的对象.为了从小 ...

  2. Eclipse中的TreeViewer类和ListViewer类

    TreeViewer和TableViewer在使用上还是有很多相似之处.TreeViewer中冶有TableViewer中的过滤器和排序器.具体使用看TableViewer中的使用. 和Table有J ...

  3. javascript/jquery给动态加载的元素添加click事件

    /** 这种写法:在重新加载数据后事件依然有效*/$(document).on('click', '#district_layer ul li', function () { });

  4. IE, FF, Safari前端开发常用调试工具

    一些前端开发 IE 中的常用调试工具: Microsoft Script Debugger —— Companion.JS need to install this Companion.JS —— J ...

  5. MySQL高可用解决方案(MySQL HA Solution)

    http://blog.sina.com.cn/s/blog_7e89c3f501012vtr.html 什么是高可用性?很多公司的服务都是24小时*365天不间断的.比如Call Center.这就 ...

  6. Mysql数据库的索引原理

    写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将 ...

  7. ubuntu 16.04 chrome flash player 过期

    今天手贱更新了系统,发现chrome flash插件过期了 解决方法: 使用全局代理打开 chrome $: google-chrome --proxy-server="socks5://1 ...

  8. Sqlserver 快照

    最近,开发系统使用SqlServer2008 R2,但是由于系统数据压力的增加,准备增加一个和正式数据库同步的库,用来供接口和报表使用,所以开始对SqlServer里面的一些技术开始研究,第一篇先来研 ...

  9. 编码神器之sublime(插件安装)

    一款优秀的编辑器是程序员的左膀右臂,相信每一个程序员手边都有自己熟悉的编辑器. 从一开始使用sublime的时候就开始喜欢上了这款编辑器,被他强大的功能深深的吸引了. sublime的强大来源于他的扩 ...

  10. 全面认识网络诊断命令功能与参数——netsh diagnostic命令

    netsh diagnostic是网络诊断命令,主要检测网络连接和服务器连接的状态.    注意:netsh不能在Window2000以下系统中使用.案例1:使用netsh diagnostic命令检 ...