我想在应用单列值过滤器后从HBase获取所选列族的行。
在我的表格' Projectdata'我有像
这样的列族<template>
<div>
<p v-for="post in posts(this.widget._id)" >{{ post.id }} - {{ post.score }}</p>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'reddit',
props: ['widget'],
computed: {
...mapGetters({
posts: 'getPostsByWidgetId'
})
}
}
</script>
<style scoped>
</style>
。我想获得一个名字&#39;当他们的关键词&#39;很开心 这是我的代码。
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
在hbase中有可能吗?我的错在哪里?
答案 0 :(得分:1)
使用
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)
,""
为您提供特定列的值{{1}}。