如何将单元格值与字符串进行比较并计算hbase中的频率?

How to compare a cell value with a string and count the frequency in hbase?

我是 hbase 的新手。

我有一个名为 "name"、"story type" 的两列族,其值分别类似于 {Rajib,Clarke}、{photo,status,gif}

我想在 'name' 列的值为 "Rajib" 时扫描 'story type' 的行,并计算相对于 "Rajib" 找到 'gif' 的频率

我试过如下所示,但这不起作用。我怎样才能做到这一点?? 提前致谢..

    String columnfamily1="story type";
   int countgif=0;
    for (Result res: scanner)
    {

    if(Bytes.toString(res.getValue(Bytes.toBytes(columnfamily),null))=="Clarke"){   
 if(Bytes.toString(res.getValue(Bytes.toBytes(columnfamily1),null))=="gif"){
                countgif=countgif+1;
                }
            }
        }
  system.out.printf("%d",countgif);
Can you put some sample data so it will be clear about your requirement.
As I understood from your question you need to filter those rows which has name as 'clarke' and story-type as 'gif'.
This can be implemented using Scan class with additional filters as

SingleColumnValueFilter filter_by_name = new SingleColumnValueFilter( 
                   Bytes.toBytes("name" ),
                   Bytes.toBytes("name"),
                   CompareOp.EQUAL,
                   Bytes.toBytes("clarke"));
SingleColumnValueFilter filter_by_story = new SingleColumnValueFilter( 
                   Bytes.toBytes("story_type" ),
                   Bytes.toBytes("type"),
                   CompareOp.EQUAL,
                   Bytes.toBytes("gif"));

FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
filterList.addFilter(filter_by_name);
filterList.addFilter(filter_by_story);

Scan scan = new Scan();
scan.setFilter(filterList);

ResultScanner scanner = table.getScanner(scan);
Result result = scanner.next;

// now use iteration to print the complete value.. if you are interested only in count then just iterate and increment count
int gifCount =0;
while(result != null)
{
  gifCount ++;
result =scanner.next;
}
println(gifCount);

希望这能解决您的问题。