You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Rajeshkumar J <ra...@gmail.com> on 2016/01/22 06:01:25 UTC

Getting all the columns of row-key at once

Hi,

  I have already posted this in mailing list but with changes in my use
case.  Is there any options to retrieve all the columns of row-key at once.

ResultScanner resultScanner = table.getScanner(scan);
        Iterator<Result> iterator = resultScanner.iterator();
        while (iterator.hasNext()) {
         Result next = iterator.next();
for (KeyValue key : next.list()) {

         System.out.println(Bytes.toString(key.getValue()));
}



This  is how I am doing scan using java api. Using this I can get only one
columns in each iteration. So is there any option to get all the column
values of row-key at once.

Thanks

Re: Getting all the columns of row-key at once

Posted by Anoop John <an...@gmail.com>.
This second loop will work for you right?  You want to have simple code?

U know all the column names? (cf:qual)

In Result there is a method getValue(byte [] family, byte [] qualifier)
 which will return the value of the latest version cell with given
cf:qual.  As u have only one version always it will work.

But better to go with 2 loop way as u said above

-Anoop-

On Fri, Jan 22, 2016 at 12:48 PM, Rajeshkumar J <rajeshkumarit8292@gmail.com
> wrote:

> yes In Rdms suppose I am concatenating my result in one string
> for(;index<ResultSet.length;)
> {
>
> String data = result(resultset instance).getindex(0) + "," +
> result.getindex(1)+","+...;//returns all the columns of the row
>
> }
>
> if result set have 2 rows then it will be iterated 2 times
>
> same i want to achieve in Hbase
>
> since I stored my data in flat-wide manner there will be only one row for
> row-key but with numerous columns.
>
> But in hbase now i am doing like
>
> for()
> {
> data += result.getvalue()+",";     //returns only one column need to
> iterate again for second column unlike RDBMS
> }
>
> Thanks
>
> On Fri, Jan 22, 2016 at 11:27 AM, ramkrishna vasudevan <
> ramkrishna.s.vasudevan@gmail.com> wrote:
>
> > No it is not possible. Even in RDBMS if you want to do select * from
> table
> > where row=100, you need to do rs.getXXX(i) with suitable index to get the
> > expected row right?
> >
> > If you want specific rows you specify that in the select query - similar
> > case here. When you say you don't want to iterate you mean that the
> Result
> > object should just have all the values of all the columns appended to it
> > and currently there is no such way possible.
> >
> > Regards
> > Ram
> >
> > On Fri, Jan 22, 2016 at 11:11 AM, Rajeshkumar J <
> > rajeshkumarit8292@gmail.com
> > > wrote:
> >
> > > If that is the case if I do maintain only one versions of my data is
> this
> > > retrieval is possible?
> > >
> > > Thanks
> > >
> > > On Fri, Jan 22, 2016 at 11:01 AM, ramkrishna vasudevan <
> > > ramkrishna.s.vasudevan@gmail.com> wrote:
> > >
> > > > Currently that is not possible. The reason being that the columns are
> > not
> > > > fixed in HBase.
> > > > There could be another row or may another version of this row 100
> where
> > > > there are only col2 and col4 populated and there is no col1 and col3.
> > > > So as per your schema you should be knowing with which column the
> value
> > > is
> > > > associated.
> > > > In other words
> > > >
> > > > Row-key         col1            col2             col3            col4
> > > >
> > > > 100               xxx                yyy             zzz
> aaa
> > > > 100                                   xxx
> > > yyy
> > > >
> > > > Now how do you know xxx is associated with col2 or col1 when you try
> to
> > > > retrieve the latest version of row key 100?
> > > >
> > > > Regards
> > > > Ram
> > > >
> > > >
> > > > On Fri, Jan 22, 2016 at 10:55 AM, Rajeshkumar J <
> > > > rajeshkumarit8292@gmail.com
> > > > > wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > >   For instance
> > > > >
> > > > > Row-key         col1            col2             col3
> col4
> > > > >
> > > > > 100               xxx                yyy             zzz
> > aaa
> > > > >
> > > > > I am scanning this row-key(100) and I want to get the value as
> > > > > xxx,yyy,zzz,aaa from Result instance. Not using iterator to get
> xxxx
> > > then
> > > > > yyyy then zzzz then aaaa.
> > > > >
> > > > > Thanks
> > > > >
> > > > > On Fri, Jan 22, 2016 at 10:47 AM, ramkrishna vasudevan <
> > > > > ramkrishna.s.vasudevan@gmail.com> wrote:
> > > > >
> > > > > > Once you retrieve a result it will have all the columns that were
> > > > > scanned.
> > > > > > If suppose you had 5 columns and you specifically wanted only 2
> > > columns
> > > > > out
> > > > > > of it you can add the required columns using scan.addColumn() API
> > > then
> > > > > the
> > > > > > result will have only those 2 columns.
> > > > > > If nothing is specified your result will have entire set of
> columns
> > > > that
> > > > > > comprises that row (including multiple Column families).
> > > > > >
> > > > > > But every column's result is an individual KeyValue which you may
> > > have
> > > > to
> > > > > > iterate and get it.
> > > > > > >> So is there any option to get all the column
> > > > > > values of row-key at once.
> > > > > > So this is already happening for you.  Am I missing something
> here?
> > > > > >
> > > > > > On Fri, Jan 22, 2016 at 10:31 AM, Rajeshkumar J <
> > > > > > rajeshkumarit8292@gmail.com
> > > > > > > wrote:
> > > > > >
> > > > > > > Hi,
> > > > > > >
> > > > > > >   I have already posted this in mailing list but with changes
> in
> > my
> > > > use
> > > > > > > case.  Is there any options to retrieve all the columns of
> > row-key
> > > at
> > > > > > once.
> > > > > > >
> > > > > > > ResultScanner resultScanner = table.getScanner(scan);
> > > > > > >         Iterator<Result> iterator = resultScanner.iterator();
> > > > > > >         while (iterator.hasNext()) {
> > > > > > >          Result next = iterator.next();
> > > > > > > for (KeyValue key : next.list()) {
> > > > > > >
> > > > > > >          System.out.println(Bytes.toString(key.getValue()));
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > This  is how I am doing scan using java api. Using this I can
> get
> > > > only
> > > > > > one
> > > > > > > columns in each iteration. So is there any option to get all
> the
> > > > column
> > > > > > > values of row-key at once.
> > > > > > >
> > > > > > > Thanks
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: Getting all the columns of row-key at once

Posted by Rajeshkumar J <ra...@gmail.com>.
yes In Rdms suppose I am concatenating my result in one string
for(;index<ResultSet.length;)
{

String data = result(resultset instance).getindex(0) + "," +
result.getindex(1)+","+...;//returns all the columns of the row

}

if result set have 2 rows then it will be iterated 2 times

same i want to achieve in Hbase

since I stored my data in flat-wide manner there will be only one row for
row-key but with numerous columns.

But in hbase now i am doing like

for()
{
data += result.getvalue()+",";     //returns only one column need to
iterate again for second column unlike RDBMS
}

Thanks

On Fri, Jan 22, 2016 at 11:27 AM, ramkrishna vasudevan <
ramkrishna.s.vasudevan@gmail.com> wrote:

> No it is not possible. Even in RDBMS if you want to do select * from table
> where row=100, you need to do rs.getXXX(i) with suitable index to get the
> expected row right?
>
> If you want specific rows you specify that in the select query - similar
> case here. When you say you don't want to iterate you mean that the Result
> object should just have all the values of all the columns appended to it
> and currently there is no such way possible.
>
> Regards
> Ram
>
> On Fri, Jan 22, 2016 at 11:11 AM, Rajeshkumar J <
> rajeshkumarit8292@gmail.com
> > wrote:
>
> > If that is the case if I do maintain only one versions of my data is this
> > retrieval is possible?
> >
> > Thanks
> >
> > On Fri, Jan 22, 2016 at 11:01 AM, ramkrishna vasudevan <
> > ramkrishna.s.vasudevan@gmail.com> wrote:
> >
> > > Currently that is not possible. The reason being that the columns are
> not
> > > fixed in HBase.
> > > There could be another row or may another version of this row 100 where
> > > there are only col2 and col4 populated and there is no col1 and col3.
> > > So as per your schema you should be knowing with which column the value
> > is
> > > associated.
> > > In other words
> > >
> > > Row-key         col1            col2             col3            col4
> > >
> > > 100               xxx                yyy             zzz            aaa
> > > 100                                   xxx
> > yyy
> > >
> > > Now how do you know xxx is associated with col2 or col1 when you try to
> > > retrieve the latest version of row key 100?
> > >
> > > Regards
> > > Ram
> > >
> > >
> > > On Fri, Jan 22, 2016 at 10:55 AM, Rajeshkumar J <
> > > rajeshkumarit8292@gmail.com
> > > > wrote:
> > >
> > > > Hi,
> > > >
> > > >   For instance
> > > >
> > > > Row-key         col1            col2             col3            col4
> > > >
> > > > 100               xxx                yyy             zzz
> aaa
> > > >
> > > > I am scanning this row-key(100) and I want to get the value as
> > > > xxx,yyy,zzz,aaa from Result instance. Not using iterator to get xxxx
> > then
> > > > yyyy then zzzz then aaaa.
> > > >
> > > > Thanks
> > > >
> > > > On Fri, Jan 22, 2016 at 10:47 AM, ramkrishna vasudevan <
> > > > ramkrishna.s.vasudevan@gmail.com> wrote:
> > > >
> > > > > Once you retrieve a result it will have all the columns that were
> > > > scanned.
> > > > > If suppose you had 5 columns and you specifically wanted only 2
> > columns
> > > > out
> > > > > of it you can add the required columns using scan.addColumn() API
> > then
> > > > the
> > > > > result will have only those 2 columns.
> > > > > If nothing is specified your result will have entire set of columns
> > > that
> > > > > comprises that row (including multiple Column families).
> > > > >
> > > > > But every column's result is an individual KeyValue which you may
> > have
> > > to
> > > > > iterate and get it.
> > > > > >> So is there any option to get all the column
> > > > > values of row-key at once.
> > > > > So this is already happening for you.  Am I missing something here?
> > > > >
> > > > > On Fri, Jan 22, 2016 at 10:31 AM, Rajeshkumar J <
> > > > > rajeshkumarit8292@gmail.com
> > > > > > wrote:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > >   I have already posted this in mailing list but with changes in
> my
> > > use
> > > > > > case.  Is there any options to retrieve all the columns of
> row-key
> > at
> > > > > once.
> > > > > >
> > > > > > ResultScanner resultScanner = table.getScanner(scan);
> > > > > >         Iterator<Result> iterator = resultScanner.iterator();
> > > > > >         while (iterator.hasNext()) {
> > > > > >          Result next = iterator.next();
> > > > > > for (KeyValue key : next.list()) {
> > > > > >
> > > > > >          System.out.println(Bytes.toString(key.getValue()));
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > > This  is how I am doing scan using java api. Using this I can get
> > > only
> > > > > one
> > > > > > columns in each iteration. So is there any option to get all the
> > > column
> > > > > > values of row-key at once.
> > > > > >
> > > > > > Thanks
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: Getting all the columns of row-key at once

Posted by ramkrishna vasudevan <ra...@gmail.com>.
No it is not possible. Even in RDBMS if you want to do select * from table
where row=100, you need to do rs.getXXX(i) with suitable index to get the
expected row right?

If you want specific rows you specify that in the select query - similar
case here. When you say you don't want to iterate you mean that the Result
object should just have all the values of all the columns appended to it
and currently there is no such way possible.

Regards
Ram

On Fri, Jan 22, 2016 at 11:11 AM, Rajeshkumar J <rajeshkumarit8292@gmail.com
> wrote:

> If that is the case if I do maintain only one versions of my data is this
> retrieval is possible?
>
> Thanks
>
> On Fri, Jan 22, 2016 at 11:01 AM, ramkrishna vasudevan <
> ramkrishna.s.vasudevan@gmail.com> wrote:
>
> > Currently that is not possible. The reason being that the columns are not
> > fixed in HBase.
> > There could be another row or may another version of this row 100 where
> > there are only col2 and col4 populated and there is no col1 and col3.
> > So as per your schema you should be knowing with which column the value
> is
> > associated.
> > In other words
> >
> > Row-key         col1            col2             col3            col4
> >
> > 100               xxx                yyy             zzz            aaa
> > 100                                   xxx
> yyy
> >
> > Now how do you know xxx is associated with col2 or col1 when you try to
> > retrieve the latest version of row key 100?
> >
> > Regards
> > Ram
> >
> >
> > On Fri, Jan 22, 2016 at 10:55 AM, Rajeshkumar J <
> > rajeshkumarit8292@gmail.com
> > > wrote:
> >
> > > Hi,
> > >
> > >   For instance
> > >
> > > Row-key         col1            col2             col3            col4
> > >
> > > 100               xxx                yyy             zzz            aaa
> > >
> > > I am scanning this row-key(100) and I want to get the value as
> > > xxx,yyy,zzz,aaa from Result instance. Not using iterator to get xxxx
> then
> > > yyyy then zzzz then aaaa.
> > >
> > > Thanks
> > >
> > > On Fri, Jan 22, 2016 at 10:47 AM, ramkrishna vasudevan <
> > > ramkrishna.s.vasudevan@gmail.com> wrote:
> > >
> > > > Once you retrieve a result it will have all the columns that were
> > > scanned.
> > > > If suppose you had 5 columns and you specifically wanted only 2
> columns
> > > out
> > > > of it you can add the required columns using scan.addColumn() API
> then
> > > the
> > > > result will have only those 2 columns.
> > > > If nothing is specified your result will have entire set of columns
> > that
> > > > comprises that row (including multiple Column families).
> > > >
> > > > But every column's result is an individual KeyValue which you may
> have
> > to
> > > > iterate and get it.
> > > > >> So is there any option to get all the column
> > > > values of row-key at once.
> > > > So this is already happening for you.  Am I missing something here?
> > > >
> > > > On Fri, Jan 22, 2016 at 10:31 AM, Rajeshkumar J <
> > > > rajeshkumarit8292@gmail.com
> > > > > wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > >   I have already posted this in mailing list but with changes in my
> > use
> > > > > case.  Is there any options to retrieve all the columns of row-key
> at
> > > > once.
> > > > >
> > > > > ResultScanner resultScanner = table.getScanner(scan);
> > > > >         Iterator<Result> iterator = resultScanner.iterator();
> > > > >         while (iterator.hasNext()) {
> > > > >          Result next = iterator.next();
> > > > > for (KeyValue key : next.list()) {
> > > > >
> > > > >          System.out.println(Bytes.toString(key.getValue()));
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > > This  is how I am doing scan using java api. Using this I can get
> > only
> > > > one
> > > > > columns in each iteration. So is there any option to get all the
> > column
> > > > > values of row-key at once.
> > > > >
> > > > > Thanks
> > > > >
> > > >
> > >
> >
>

Re: Getting all the columns of row-key at once

Posted by Rajeshkumar J <ra...@gmail.com>.
If that is the case if I do maintain only one versions of my data is this
retrieval is possible?

Thanks

On Fri, Jan 22, 2016 at 11:01 AM, ramkrishna vasudevan <
ramkrishna.s.vasudevan@gmail.com> wrote:

> Currently that is not possible. The reason being that the columns are not
> fixed in HBase.
> There could be another row or may another version of this row 100 where
> there are only col2 and col4 populated and there is no col1 and col3.
> So as per your schema you should be knowing with which column the value is
> associated.
> In other words
>
> Row-key         col1            col2             col3            col4
>
> 100               xxx                yyy             zzz            aaa
> 100                                   xxx                              yyy
>
> Now how do you know xxx is associated with col2 or col1 when you try to
> retrieve the latest version of row key 100?
>
> Regards
> Ram
>
>
> On Fri, Jan 22, 2016 at 10:55 AM, Rajeshkumar J <
> rajeshkumarit8292@gmail.com
> > wrote:
>
> > Hi,
> >
> >   For instance
> >
> > Row-key         col1            col2             col3            col4
> >
> > 100               xxx                yyy             zzz            aaa
> >
> > I am scanning this row-key(100) and I want to get the value as
> > xxx,yyy,zzz,aaa from Result instance. Not using iterator to get xxxx then
> > yyyy then zzzz then aaaa.
> >
> > Thanks
> >
> > On Fri, Jan 22, 2016 at 10:47 AM, ramkrishna vasudevan <
> > ramkrishna.s.vasudevan@gmail.com> wrote:
> >
> > > Once you retrieve a result it will have all the columns that were
> > scanned.
> > > If suppose you had 5 columns and you specifically wanted only 2 columns
> > out
> > > of it you can add the required columns using scan.addColumn() API then
> > the
> > > result will have only those 2 columns.
> > > If nothing is specified your result will have entire set of columns
> that
> > > comprises that row (including multiple Column families).
> > >
> > > But every column's result is an individual KeyValue which you may have
> to
> > > iterate and get it.
> > > >> So is there any option to get all the column
> > > values of row-key at once.
> > > So this is already happening for you.  Am I missing something here?
> > >
> > > On Fri, Jan 22, 2016 at 10:31 AM, Rajeshkumar J <
> > > rajeshkumarit8292@gmail.com
> > > > wrote:
> > >
> > > > Hi,
> > > >
> > > >   I have already posted this in mailing list but with changes in my
> use
> > > > case.  Is there any options to retrieve all the columns of row-key at
> > > once.
> > > >
> > > > ResultScanner resultScanner = table.getScanner(scan);
> > > >         Iterator<Result> iterator = resultScanner.iterator();
> > > >         while (iterator.hasNext()) {
> > > >          Result next = iterator.next();
> > > > for (KeyValue key : next.list()) {
> > > >
> > > >          System.out.println(Bytes.toString(key.getValue()));
> > > > }
> > > >
> > > >
> > > >
> > > > This  is how I am doing scan using java api. Using this I can get
> only
> > > one
> > > > columns in each iteration. So is there any option to get all the
> column
> > > > values of row-key at once.
> > > >
> > > > Thanks
> > > >
> > >
> >
>

Re: Getting all the columns of row-key at once

Posted by ramkrishna vasudevan <ra...@gmail.com>.
Currently that is not possible. The reason being that the columns are not
fixed in HBase.
There could be another row or may another version of this row 100 where
there are only col2 and col4 populated and there is no col1 and col3.
So as per your schema you should be knowing with which column the value is
associated.
In other words

Row-key         col1            col2             col3            col4

100               xxx                yyy             zzz            aaa
100                                   xxx                              yyy

Now how do you know xxx is associated with col2 or col1 when you try to
retrieve the latest version of row key 100?

Regards
Ram


On Fri, Jan 22, 2016 at 10:55 AM, Rajeshkumar J <rajeshkumarit8292@gmail.com
> wrote:

> Hi,
>
>   For instance
>
> Row-key         col1            col2             col3            col4
>
> 100               xxx                yyy             zzz            aaa
>
> I am scanning this row-key(100) and I want to get the value as
> xxx,yyy,zzz,aaa from Result instance. Not using iterator to get xxxx then
> yyyy then zzzz then aaaa.
>
> Thanks
>
> On Fri, Jan 22, 2016 at 10:47 AM, ramkrishna vasudevan <
> ramkrishna.s.vasudevan@gmail.com> wrote:
>
> > Once you retrieve a result it will have all the columns that were
> scanned.
> > If suppose you had 5 columns and you specifically wanted only 2 columns
> out
> > of it you can add the required columns using scan.addColumn() API then
> the
> > result will have only those 2 columns.
> > If nothing is specified your result will have entire set of columns that
> > comprises that row (including multiple Column families).
> >
> > But every column's result is an individual KeyValue which you may have to
> > iterate and get it.
> > >> So is there any option to get all the column
> > values of row-key at once.
> > So this is already happening for you.  Am I missing something here?
> >
> > On Fri, Jan 22, 2016 at 10:31 AM, Rajeshkumar J <
> > rajeshkumarit8292@gmail.com
> > > wrote:
> >
> > > Hi,
> > >
> > >   I have already posted this in mailing list but with changes in my use
> > > case.  Is there any options to retrieve all the columns of row-key at
> > once.
> > >
> > > ResultScanner resultScanner = table.getScanner(scan);
> > >         Iterator<Result> iterator = resultScanner.iterator();
> > >         while (iterator.hasNext()) {
> > >          Result next = iterator.next();
> > > for (KeyValue key : next.list()) {
> > >
> > >          System.out.println(Bytes.toString(key.getValue()));
> > > }
> > >
> > >
> > >
> > > This  is how I am doing scan using java api. Using this I can get only
> > one
> > > columns in each iteration. So is there any option to get all the column
> > > values of row-key at once.
> > >
> > > Thanks
> > >
> >
>

Re: Getting all the columns of row-key at once

Posted by Rajeshkumar J <ra...@gmail.com>.
Hi,

  For instance

Row-key         col1            col2             col3            col4

100               xxx                yyy             zzz            aaa

I am scanning this row-key(100) and I want to get the value as
xxx,yyy,zzz,aaa from Result instance. Not using iterator to get xxxx then
yyyy then zzzz then aaaa.

Thanks

On Fri, Jan 22, 2016 at 10:47 AM, ramkrishna vasudevan <
ramkrishna.s.vasudevan@gmail.com> wrote:

> Once you retrieve a result it will have all the columns that were scanned.
> If suppose you had 5 columns and you specifically wanted only 2 columns out
> of it you can add the required columns using scan.addColumn() API then the
> result will have only those 2 columns.
> If nothing is specified your result will have entire set of columns that
> comprises that row (including multiple Column families).
>
> But every column's result is an individual KeyValue which you may have to
> iterate and get it.
> >> So is there any option to get all the column
> values of row-key at once.
> So this is already happening for you.  Am I missing something here?
>
> On Fri, Jan 22, 2016 at 10:31 AM, Rajeshkumar J <
> rajeshkumarit8292@gmail.com
> > wrote:
>
> > Hi,
> >
> >   I have already posted this in mailing list but with changes in my use
> > case.  Is there any options to retrieve all the columns of row-key at
> once.
> >
> > ResultScanner resultScanner = table.getScanner(scan);
> >         Iterator<Result> iterator = resultScanner.iterator();
> >         while (iterator.hasNext()) {
> >          Result next = iterator.next();
> > for (KeyValue key : next.list()) {
> >
> >          System.out.println(Bytes.toString(key.getValue()));
> > }
> >
> >
> >
> > This  is how I am doing scan using java api. Using this I can get only
> one
> > columns in each iteration. So is there any option to get all the column
> > values of row-key at once.
> >
> > Thanks
> >
>

Re: Getting all the columns of row-key at once

Posted by ramkrishna vasudevan <ra...@gmail.com>.
Once you retrieve a result it will have all the columns that were scanned.
If suppose you had 5 columns and you specifically wanted only 2 columns out
of it you can add the required columns using scan.addColumn() API then the
result will have only those 2 columns.
If nothing is specified your result will have entire set of columns that
comprises that row (including multiple Column families).

But every column's result is an individual KeyValue which you may have to
iterate and get it.
>> So is there any option to get all the column
values of row-key at once.
So this is already happening for you.  Am I missing something here?

On Fri, Jan 22, 2016 at 10:31 AM, Rajeshkumar J <rajeshkumarit8292@gmail.com
> wrote:

> Hi,
>
>   I have already posted this in mailing list but with changes in my use
> case.  Is there any options to retrieve all the columns of row-key at once.
>
> ResultScanner resultScanner = table.getScanner(scan);
>         Iterator<Result> iterator = resultScanner.iterator();
>         while (iterator.hasNext()) {
>          Result next = iterator.next();
> for (KeyValue key : next.list()) {
>
>          System.out.println(Bytes.toString(key.getValue()));
> }
>
>
>
> This  is how I am doing scan using java api. Using this I can get only one
> columns in each iteration. So is there any option to get all the column
> values of row-key at once.
>
> Thanks
>