You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Ted Yu <yu...@gmail.com> on 2016/08/01 10:49:56 UTC
Re: get first row of every region
You can issue Scan with each of the start keys and setBatch(1).
Close each scan after next() is called.
On Mon, Aug 1, 2016 at 1:55 AM, jinhong lu <lu...@gmail.com> wrote:
> Hi, I want to get first row of every region in a table, Any API for that?
> getStartKey() will return the rowkey not existed, but just the prefix.
>
>
>
> Thanks,
> lujinhong
>
>
Re: get first row of every region
Posted by Jean-Marc Spaggiari <je...@spaggiari.org>.
Well, then it should return the row from the next region.
So it might means that the last region is empty or the last X regions, no?
Le 2016-08-01 7:52 PM, "Vladimir Rodionov" <vl...@gmail.com> a
écrit :
> it means that for some regions you do not have any data.
>
> -Vlad
>
> On Mon, Aug 1, 2016 at 7:21 PM, jinhong lu <lu...@gmail.com> wrote:
>
> > Thanks. Here is my code, but in most case, r is null? why this happened?
> >
> > byte[] startRowkey =
> > regionInfo.getStartKey();
> > Scan sc = new Scan();
> > sc.setBatch(1);
> > sc.setRowPrefixFilter(startRowkey);
> > try {
> > scanner = table.getScanner(sc);
> > r = scanner.next();
> > scanner.close();
> > }
> > Thanks,
> > lujinhong
> >
> > > 在 2016年8月1日,18:49,Ted Yu <yuzhihong@gmail.com <mailto:
> > yuzhihong@gmail.com>> 写道:
> > >
> > > .
> >
> >
>
Re: get first row of every region
Posted by Vladimir Rodionov <vl...@gmail.com>.
it means that for some regions you do not have any data.
-Vlad
On Mon, Aug 1, 2016 at 7:21 PM, jinhong lu <lu...@gmail.com> wrote:
> Thanks. Here is my code, but in most case, r is null? why this happened?
>
> byte[] startRowkey =
> regionInfo.getStartKey();
> Scan sc = new Scan();
> sc.setBatch(1);
> sc.setRowPrefixFilter(startRowkey);
> try {
> scanner = table.getScanner(sc);
> r = scanner.next();
> scanner.close();
> }
> Thanks,
> lujinhong
>
> > 在 2016年8月1日,18:49,Ted Yu <yuzhihong@gmail.com <mailto:
> yuzhihong@gmail.com>> 写道:
> >
> > .
>
>
Re: get first row of every region
Posted by Anoop John <an...@gmail.com>.
You will have to set the stop row also (As Phil Yang suggested) .
Otherwise the scan might return row from next region (if this region
is empty)
-Anoop-
On Wed, Aug 3, 2016 at 12:23 PM, jinhong lu <lu...@gmail.com> wrote:
> Thanks a lot. I make a mistake in my code, it should be:
> sc.setStartRow(startRowkey),
> not:
> sc.setRowPrefixFilter(startRowkey);
> After fix that, it works.
>
>
> Thanks,
> lujinhong
>
>> 在 2016年8月2日,11:12,Phil Yang <ud...@gmail.com> 写道:
>>
>> If you pre-split this table with some split points when you create the
>> table, the start key may not be the prefix of the first row key. So you
>> should use setStartRow(regionInfo.getStartKey())
>> and setStopRow(nextRegionInfo.getStartKey()) and setBatch(1), if the result
>> is still null, this region is indeed empty.
>>
>> Thanks,
>> Phil
>>
>>
>> 2016-08-02 10:21 GMT+08:00 jinhong lu <lu...@gmail.com>:
>>
>>> Thanks. Here is my code, but in most case, r is null? why this happened?
>>>
>>> byte[] startRowkey =
>>> regionInfo.getStartKey();
>>> Scan sc = new Scan();
>>> sc.setBatch(1);
>>> sc.setRowPrefixFilter(startRowkey);
>>> try {
>>> scanner = table.getScanner(sc);
>>> r = scanner.next();
>>> scanner.close();
>>> }
>>> Thanks,
>>> lujinhong
>>>
>>>> 在 2016年8月1日,18:49,Ted Yu <yuzhihong@gmail.com <mailto:
>>> yuzhihong@gmail.com>> 写道:
>>>>
>>>> .
>>>
>>>
>
Re: get first row of every region
Posted by jinhong lu <lu...@gmail.com>.
Thanks a lot. I make a mistake in my code, it should be:
sc.setStartRow(startRowkey),
not:
sc.setRowPrefixFilter(startRowkey);
After fix that, it works.
Thanks,
lujinhong
> 在 2016年8月2日,11:12,Phil Yang <ud...@gmail.com> 写道:
>
> If you pre-split this table with some split points when you create the
> table, the start key may not be the prefix of the first row key. So you
> should use setStartRow(regionInfo.getStartKey())
> and setStopRow(nextRegionInfo.getStartKey()) and setBatch(1), if the result
> is still null, this region is indeed empty.
>
> Thanks,
> Phil
>
>
> 2016-08-02 10:21 GMT+08:00 jinhong lu <lu...@gmail.com>:
>
>> Thanks. Here is my code, but in most case, r is null? why this happened?
>>
>> byte[] startRowkey =
>> regionInfo.getStartKey();
>> Scan sc = new Scan();
>> sc.setBatch(1);
>> sc.setRowPrefixFilter(startRowkey);
>> try {
>> scanner = table.getScanner(sc);
>> r = scanner.next();
>> scanner.close();
>> }
>> Thanks,
>> lujinhong
>>
>>> 在 2016年8月1日,18:49,Ted Yu <yuzhihong@gmail.com <mailto:
>> yuzhihong@gmail.com>> 写道:
>>>
>>> .
>>
>>
Re: get first row of every region
Posted by Phil Yang <ud...@gmail.com>.
If you pre-split this table with some split points when you create the
table, the start key may not be the prefix of the first row key. So you
should use setStartRow(regionInfo.getStartKey())
and setStopRow(nextRegionInfo.getStartKey()) and setBatch(1), if the result
is still null, this region is indeed empty.
Thanks,
Phil
2016-08-02 10:21 GMT+08:00 jinhong lu <lu...@gmail.com>:
> Thanks. Here is my code, but in most case, r is null? why this happened?
>
> byte[] startRowkey =
> regionInfo.getStartKey();
> Scan sc = new Scan();
> sc.setBatch(1);
> sc.setRowPrefixFilter(startRowkey);
> try {
> scanner = table.getScanner(sc);
> r = scanner.next();
> scanner.close();
> }
> Thanks,
> lujinhong
>
> > 在 2016年8月1日,18:49,Ted Yu <yuzhihong@gmail.com <mailto:
> yuzhihong@gmail.com>> 写道:
> >
> > .
>
>
Re: get first row of every region
Posted by jinhong lu <lu...@gmail.com>.
Thanks. Here is my code, but in most case, r is null? why this happened?
byte[] startRowkey = regionInfo.getStartKey();
Scan sc = new Scan();
sc.setBatch(1);
sc.setRowPrefixFilter(startRowkey);
try {
scanner = table.getScanner(sc);
r = scanner.next();
scanner.close();
}
Thanks,
lujinhong
> 在 2016年8月1日,18:49,Ted Yu <yuzhihong@gmail.com <ma...@gmail.com>> 写道:
>
> .