繁体   English   中英

使用Java在HBase中检索第N个限定词

[英]Retrieving nth qualifier in hbase using java

这个问题是开箱即用的,但是我需要它。

在list(collection)中,我们可以通过list.get(i);检索列表中的第n个元素。

同样,在hbase中,有没有使用Java API的方法,在给定行ID和ColumnFamily名称的情况下,我可以得到第n个限定符。

注意:我在columnFamily的单行中有百万个限定符。

抱歉,没有响应。 忙着重要的事情。 现在尝试一下:

package org.myorg.hbasedemo;

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 GetNthColunm {

    public static void main(String[] args) throws IOException {
        Configuration conf = HBaseConfiguration.create();
        HTable table = new HTable(conf, "TEST");
        Get g = new Get(Bytes.toBytes("4"));
        Result r = table.get(g);
        System.out.println("Enter column index :");
        Scanner reader = new Scanner(System.in);
        int index = reader.nextInt();
        System.out.println("index : " + index);
        int count = 0;      
        for (KeyValue kv : r.raw()) {
            if(++count!=index)
                continue;
            System.out.println("Qualifier : "
                    + Bytes.toString(kv.getQualifier()));
            System.out.println("Value : " + Bytes.toString(kv.getValue()));
        }       
        table.close();
        System.out.println("Done.");
    }
}

如果有更好的方法,请告诉您。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM