gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 06:35:18 24 4
gpt4 key购买 nike

我对 hbase 很陌生。

我有一个名为“名称”、“故事类型”的两列族,其值分别类似于 {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);

希望这能解决您的问题。

关于java - 如何将单元格值与字符串进行比较并计算hbase中的频率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45286806/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com