Hbase之getroworbefore()函数

来源:互联网 发布:网络锁是什么意思 编辑:程序博客网 时间:2024/06/15 15:40

现在表emp1中插入如下两条数据



那么我们要运用函数getroworbefore把这两条数据查出来

import java.io.IOException;import java.util.Scanner;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.KeyValue;import org.apache.hadoop.hbase.client.Get;import org.apache.hadoop.hbase.client.HTable;import org.apache.hadoop.hbase.client.Result;import org.apache.hadoop.hbase.util.Bytes;public class Get_list {static Configuration conf = null;      static {          conf = HBaseConfiguration.create();               }public static void main(String[] args) throws IOException {        // Instantiating HTable class      HTable table = new HTable(conf, "emp1");      // Instantiating Get class      //Get g = new Get(Bytes.toBytes("rowkey10000"));      //g.addFamily("author");      // Reading the data      Result result = table.getRowOrBefore(Bytes.toBytes("row"),Bytes.toBytes("artcle"));      for (KeyValue kv : result.list()) {   System.out.println("family:" + Bytes.toString(kv.getFamily()));   System.out   .println("qualifier:" + Bytes.toString(kv.getQualifier()));   System.out.println("value:" + Bytes.toString(kv.getValue()));   System.out.println("Timestamp:" + kv.getTimestamp());   System.out.println("-------------------------------------------");  }}}

我们可以看到我们在设置行键限制的时候输入了row,而表emp1中并没有行键为row的数据


但是这个函数可以查出row或row之前的一条数据

运行结果:


查询成功

原创粉丝点击