2016-05-30 290 views
3

密钥类型我使用的CellUtil类包装在org.apache.hadoop.hbase创建细胞对象。功能标题如下所示:CellUtil:在createCell方法

public static Cell createCell(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte type, byte[] value) 

第5个是什么。参数字节类型代表?我看着KeyValueType类,它指的是如下定义枚举称为类型:

public static enum Type { 
Minimum((byte)0), 
Put((byte)4), 

Delete((byte)8), 
DeleteFamilyVersion((byte)10), 
DeleteColumn((byte)12), 
DeleteFamily((byte)14), 

// Maximum is used when searching; you look from maximum on down. 
Maximum((byte)255); 

private final byte code; 

Type(final byte c) { 
    this.code = c; 
} 

public byte getCode() { 
    return this.code; 
} 

我的问题是,什么样的类型是最小的,把等得到了与我想要的细胞类型做创造?

回答

3

沙林, 请参阅69.7.6. KeyValue

有一些场景中,您将使用这些枚举。例如,我正在写协处理器,像下面那样,我将使用KeyValue.Type.Put.getCode() 类似的其他枚举也可以像这样使用。 见下文实例协处理器使用...

package getObserver; 

import java.io.IOException; 
import java.util.List; 
import java.util.NavigableSet; 

import org.apache.hadoop.hbase.Cell; 
import org.apache.hadoop.hbase.CellUtil; 
import org.apache.hadoop.hbase.KeyValue; 
import org.apache.hadoop.hbase.client.Get; 
import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver; 
import org.apache.hadoop.hbase.coprocessor.ObserverContext; 
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; 

public class Observer extends BaseRegionObserver{ 

    private boolean isOewc; 

    @Override 
    public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> arg0, 
      Get arg1, List<Cell> arg2) throws IOException { 
     NavigableSet<byte[]> qset = arg1.getFamilyMap().get("colfam1".getBytes()); 
     if(qset==null){//do nothing 

     }else{ 

      String message = "qset.size() = "+String.valueOf(qset.size()); 
      String m = "isOewc = "+String.valueOf(isOewc); 
      this.isOewc = true; 
      Cell cell = CellUtil.createCell(
        "preGet Row".getBytes(), 
        m.getBytes(), 
        message.getBytes(), 
        System.currentTimeMillis(), 
        KeyValue.Type.Put.getCode(), 
        "preGet Value".getBytes()); 
      arg2.add(cell); 
     } 
    } 

    @Override 
    public void postGetOp(ObserverContext<RegionCoprocessorEnvironment> arg0, 
      Get arg1, List<Cell> arg2) throws IOException { 
     String m = "isOewc = "+String.valueOf(isOewc); 
     Cell cell = CellUtil.createCell(
       "postGet Row".getBytes(), 
       m.getBytes(), 
       "postGet Qualifier".getBytes(), 
       System.currentTimeMillis(), 
       KeyValue.Type.Put.getCode(), 
       "postGet Value".getBytes()); 
     arg2.add(cell); 
    } 
} 

下面EnumTypes其他同样可以使用,如果你不知道哪个 操作你要对协处理器事件进行..

enter image description here

programcreek examples清楚地解释了什么是认沽的使用,删除(准备突变键值对)最大值,最小值(对于范围C赫克)。上面的协处理器例子也使用Put。

+0

你可以设置Put,Minimum,Maximum和Delete的用法吗?只需一个班轮就足够了。 – Sarin

+0

上面给出的代码是协处理器。协处理器就像触发器一样工作。如果出现该事件,则需要执行Put,Delete或其他一些事情,才能通过枚举。这就是用法。 –

+0

让我换一种方式。假设我正在写MR单元测试,并且想使用CellUtil创建一个Cell。我应该使用哪些以及为什么。 – Sarin