Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将单元格值与字符串进行比较并计算hbase中的频率?_Java_String_Hbase - Fatal编程技术网

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

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:

我对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);