Java 如何将单元格值与字符串进行比较并计算hbase中的频率?
我对hbase非常陌生 我有一个名为“name”、“story type”的两列族,其值分别为{Rajib、Clarke}、{photo、status、gif} 当“name”列的值为“Rajib”时,我想扫描“story type”的行,并计算相对于“Rajib”查找“gif”的频率 我试过下面的方法,但不起作用。我该怎么做?? 提前谢谢Java 如何将单元格值与字符串进行比较并计算hbase中的频率?,java,string,hbase,Java,String,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:
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);