使用java检索hbase中的第n个限定符

ddhy6vgd  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(363)

这个问题很离题,但我需要它。
在list(collection)中,我们可以通过list.get(i)检索list中的第n个元素;
类似地,在hbase中,有任何方法使用javaapi,在这里我可以获得给定行id和列族名称的第n个限定符。
注意:我有一百万个限定符在单列族的单行中。

bqf10yzr

bqf10yzr1#

抱歉没有React。忙着做重要的事情。现在就试试这个:

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

如果我能找到更好的方法,我会告诉你的。

相关问题