使用java检索hbase中的第n个限定符 [英] Retrieving nth qualifier in hbase using java

查看:164
本文介绍了使用java检索hbase中的第n个限定符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在列表(集合)中,我们可以通过list.get()获取列表中的第n个元素i);

类似地,在hbase中有使用java API的方法,其中我可以通过给定行ID和ColumnFamily名称获得第n个限定符。



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

解决方案

对不起因为没有反应。忙于重要的事情。现在试试这个:

  package org.myorg.hbasedemo; 

import java.io.IOException;
import java.util.Scanner;

导入org.apache.hadoop.conf.Configuration;
导入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;
导入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));
结果r = table.get(g);
System.out.println(输入列索引:);
扫描仪阅读器=新扫描仪(System.in);
int index = reader.nextInt();
System.out.println(index:+ index);
int count = 0; (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(完成。);






$ b

如果我有更好的方法可以让你知道做到这一点。


This question is quite out of box but i need it.

In list(collection), we can retrieve the nth element in the list by list.get(i);

similarly is there any method, in hbase, using java API, where i can get the nth qualifier given the row id and ColumnFamily name.

NOTE: I have million qualifiers in single row in single columnFamily.

解决方案

Sorry for being unresponsive. Busy with something important. Try this for right now :

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

Will let you know if I get a better way to do this.

这篇关于使用java检索hbase中的第n个限定符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆