You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hbase.apache.org by ventlam <ve...@gmail.com> on 2011/01/05 12:55:55 UTC
how to get cell value from the hbase table via the key word?
hey,guy!
I would like to get the cell value via the key word like"viki" . I used
ValueFilter to implement it ,but i got nothing. Is there any other ideas?
My code as follow:
try
{
HTable htable = new
HTable(hconf,Bytes.toBytes(tablename));
ValueFilter vfilter = new
ValueFilter(CompareOp.EQUAL,new BinaryComparator(Bytes.toBytes(value)));
Scan s =new Scan();
s.setFilter(vfilter);
ResultScanner rscanner = htable.getScanner(s);
for(Result rs : rscanner)
{
byte [] by =
rs.getValue(Bytes.toBytes(tablename));
String vt= Bytes.toString(by);
System.out.println("The value is "+
vt);
}
}
catch(IOException e)
{
e.printStackTrace();
}
Re: how to get cell value from the hbase table via the key word?
Posted by Lars George <la...@gmail.com>.
Hi Ventlam,
You need to make sure the values truly are comparable. In other words,
that you store the values using the same serialization mechanism as
used by the filter. Do a test and read a row that you know that has
that value and print it in hex representation, then do the same for
Bytes.toBytes(value) and compare on a byte level to check. Often the
stored value is slightly different and therefore does not match. The
TestFilter.java has a test for the ValueFilter and it passes, so this
seems to be something with your data?
Lars
On Wed, Jan 5, 2011 at 12:55 PM, ventlam <ve...@gmail.com> wrote:
> hey,guy!
> I would like to get the cell value via the key word like"viki" . I used
> ValueFilter to implement it ,but i got nothing. Is there any other ideas?
> My code as follow:
> try
> {
> HTable htable = new
> HTable(hconf,Bytes.toBytes(tablename));
>
> ValueFilter vfilter = new
> ValueFilter(CompareOp.EQUAL,new BinaryComparator(Bytes.toBytes(value)));
>
> Scan s =new Scan();
> s.setFilter(vfilter);
> ResultScanner rscanner = htable.getScanner(s);
>
> for(Result rs : rscanner)
> {
> byte [] by =
> rs.getValue(Bytes.toBytes(tablename));
>
> String vt= Bytes.toString(by);
> System.out.println("The value is "+
> vt);
> }
>
> }
> catch(IOException e)
> {
> e.printStackTrace();
> }
>
>