You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by how to get the cell value <ve...@gmail.com> on 2011/01/05 09:45:39 UTC

hbase

 I would like to get specified value from the table which don't mind its family 
and column.
   I used ValueFilter to make it ,but i get nothing .
   My code is :
 
		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: hbase

Posted by Lars George <la...@gmail.com>.
I never got that reverse logic, who came up with that?

On Wed, Jan 5, 2011 at 6:59 PM, Jean-Daniel Cryans <jd...@apache.org> wrote:
> What you are doing is filtering out the rows with the value you are looking for.
>
> J-D
>
> On Wed, Jan 5, 2011 at 12:45 AM, how to get the  cell value
> <ve...@gmail.com> wrote:
>>  I would like to get specified value from the table which don't mind its family
>> and column.
>>   I used ValueFilter to make it ,but i get nothing .
>>   My code is :
>>
>>                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: hbase

Posted by Jean-Daniel Cryans <jd...@apache.org>.
What you are doing is filtering out the rows with the value you are looking for.

J-D

On Wed, Jan 5, 2011 at 12:45 AM, how to get the  cell value
<ve...@gmail.com> wrote:
>  I would like to get specified value from the table which don't mind its family
> and column.
>   I used ValueFilter to make it ,but i get nothing .
>   My code is :
>
>                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: hbase

Posted by Lars George <la...@gmail.com>.
Oh, well spotted Tatsuya, didn't even see his use of "tablename" there!

On Thu, Jan 6, 2011 at 4:22 AM, Tatsuya Kawano <ta...@gmail.com> wrote:
>
> Hi,
>
>>  byte [] by = rs.getValue(Bytes.toBytes(tablename));
>
> Result#getValue() doesn't take a table name but a column name in "family:qualifier" format, so you shouldn't give it the table name here. Also be aware that single result object represents a row and it will have multiple columns, so you might want to use Result#row() or Result#list() to iterate them. (a KeyValue represents a column.)
>
> for (Result result : rscanner) {
>    for (KeyValue kv : result.row()) {
>        String vt = Bytes.toString(kv.getValue());
>        System.out.println("The value is "+ vt);
>    }
> }
>
> Thanks,
>
> --
> Tatsuya Kawano (Mr.)
> Tokyo, Japan
>
> http://twitter.com/#!/tatsuya6502
>
>
>
> On 01/05/2011, at 5:45 PM, how to get the cell value wrote:
>
>> I would like to get specified value from the table which don't mind its family
>> and column.
>>   I used ValueFilter to make it ,but i get nothing .
>>   My code is :
>>
>>               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: hbase

Posted by Tatsuya Kawano <ta...@gmail.com>.
Hi, 

>  byte [] by = rs.getValue(Bytes.toBytes(tablename));

Result#getValue() doesn't take a table name but a column name in "family:qualifier" format, so you shouldn't give it the table name here. Also be aware that single result object represents a row and it will have multiple columns, so you might want to use Result#row() or Result#list() to iterate them. (a KeyValue represents a column.)

for (Result result : rscanner) {
    for (KeyValue kv : result.row()) {
        String vt = Bytes.toString(kv.getValue());
        System.out.println("The value is "+ vt);
    }
} 

Thanks, 

--
Tatsuya Kawano (Mr.)
Tokyo, Japan

http://twitter.com/#!/tatsuya6502



On 01/05/2011, at 5:45 PM, how to get the cell value wrote:

> I would like to get specified value from the table which don't mind its family 
> and column.
>   I used ValueFilter to make it ,but i get nothing .
>   My code is :
> 
> 		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();
> 		}
>