1
単一列値フィルタを適用した後、HBaseから選択した列ファミリの行を取得したいとします。私のテーブルでHBaseで出力をフォーマットする
'Projectdata' 私は
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
のような出力をgetingですが、私は名前だけを取得したいです。私は取得しようとしています
Key: 102bob
Key: 109aritra
hbaseで可能ですか?実際に私のせいはどこですか?
あなたの質問は乱雑で不明です。あなたは 'name'列に{aritra、nill、bob、jakob}のような値を持ち、 'キーワード'列{happy、sad、emotional}などに 'scanh.addFamily(Bytes.toBytes( "これらのカラムファミリーやカラムはそうですか? –
申し訳ありません。私は自分の質問を編集しました。これらはすべて列ファミリです。 – Yonex
まだわかりにくいですが、列名のない列ファミリーの値はどのようにできますか?それは行キーか列名ですか? –