Java 在HBase中格式化输出

Java 在HBase中格式化输出,java,hbase,Java,Hbase,我想在应用单列值过滤器后从HBase获取所选列族的行 在我的表“Projectdata”中,我有一个列族,如 name|story|type|keyword aritra| kl |ac |happy nill |jk |bc |sad bob |pk |dd |happy 。当他们的“关键字”满意时,我想得到“姓名”的列表。 这是我的密码 public class ByCategory { public static void main(

我想在应用单列值过滤器后从HBase获取所选列族的行

在我的表“Projectdata”中,我有一个列族,如

    name|story|type|keyword

  aritra| kl  |ac  |happy
   nill |jk   |bc  |sad
   bob  |pk   |dd  |happy
。当他们的“关键字”满意时,我想得到“姓名”的列表。 这是我的密码

public class ByCategory {

    public static void main(String [] args) throws Exception{

        Configuration conf = HBaseConfiguration.create();
        HTable table = new HTable(conf, "Projectdata");

        SingleColumnValueFilter filter_by_happycategory = new SingleColumnValueFilter(
                Bytes.toBytes("keyword" ),
                Bytes.toBytes(""),
                CompareOp.EQUAL,
                Bytes.toBytes("happy")
                );
        FilterList filterListk =new FilterList();
        filterListk.addFilter(filter_by_happycategory);

        Scan scanh = new Scan();
        scanh.addFamily(Bytes.toBytes("name"));
        scanh.addFamily(Bytes.toBytes("keyword"));
        scanh.setFilter(filterListk);


        ResultScanner scannerh = table.getScanner(scanh);
        String key = new String("~");
        String keyFlag = new String("~");
        System.out.println("Scanning table... ");

            for(Result resulth: scannerh){
                //System.out.println("getRow:"+Bytes.toString(resulth.getRow()));
                 key = "~";
                for(KeyValue kv:resulth.raw())
                {
                    if(key.compareTo(keyFlag)==0){
                        key=Bytes.toString(kv.getRow());
                        System.out.print("Key: "+key);
                    }
                    System.out.print(Bytes.toString(kv.getValue()));

                }
                System.out.println("");

            }
            scannerh.close();
            System.out.println("complete");  
            table.close();
        }

    }
我得到这样的输出

Key: 102happybob
Key: 109happyaritra
但我只想知道你的名字。我正试着去

 Key: 102bob
 Key: 109aritra
在hbase中可能吗?我的错到底在哪里?

使用

for(Result resulth: scannerh){
        System.out.println("Key: "+Bytes.toString(resulth.getRow())+Bytes.toString(resulth.getValue(Bytes.toBytes("name"),Bytes.toBytes(""))));
    }

您将获得所需的输出。此处
resulth.getRow()
为您提供
rowkey
,而
.getValue(columnfamily,column)
为您提供特定列的值,该列在您的情况下是

您的问题既混乱又不清楚。你说‘在‘name’列中我有像{aritra,nill,bob,jakob}这样的值,在‘keyword’列中有{happy,sad,emotional}等’,还有‘scanh.addFamily(Bytes.toBytes(“name”);’。那么这些专栏是家庭专栏还是专栏?对不起,我已经编辑了我的问题。所有这些都是列族。仍然不清楚,没有列名,columnfamily怎么可能有值?是行键还是列名?删除前面的答案,问题清楚后将回答。我已更新我的问题。这里我没有限定符。这就是为什么在单列值筛选器中,我必须将列限定符字段保留为空。在这里,cf就像hbase shell中的columntry一样放置“Projectdata”、“50”、“name:”和“kumar”,我想这会让您清楚地知道cf中的值是如何存在的