You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Ramasubramanian Narayanan <ra...@gmail.com> on 2012/12/27 10:54:06 UTC

How to use substring in Rowkey

Hi,

Suppose a rowkey contains some 5 fields delimited by "|", then how to use
the same in the where clause?

For example, I have some 4 customer records who is having different number
address .. for simplicity, I had for customer number 1,he has only one
address, for customer number 2, he has two addresses, like wise till 4
customer..

So totally there will be 10 records in my table...

Customer Number   Number of address
Customer 1                          - 1
Customer 2                          - 2
Customer 3                          - 3
Customer 4                          - 4
                                               -----
                                                 10

*Here is my rowkey: (Customer number | Type of address)*
10000000001|OFFICE
10000000002|HOME
10000000002|OFFICE
10000000003|HOME
10000000003|OFFICE
10000000003|OTHERS
10000000004|HOME
10000000004|OFFICE1
10000000004|OFFICE2
10000000004|OTHERS


Now question is, how to select all the details of customer 4 (customer
number 10000000004)?
Is it possible to use substring of rowkey in the where clause? I don't know
whether he may have home/office or any type of address..

Please help in providing query for the same..

regards,
Rams

Re: How to use substring in Rowkey

Posted by ramkrishna vasudevan <ra...@gmail.com>.
There is also something called FuzzyRowFilter. It should help you out.

Regards
Ram

On Thu, Dec 27, 2012 at 4:13 PM, Mohammad Tariq <do...@gmail.com> wrote:

> Try RowFilter with RegexStringComparator
>
> Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL,new
> RegexStringComparator("YOUR-REGEX"));
>
> Best Regards,
> Tariq
> +91-9741563634
> https://mtariq.jux.com/
>
>
> On Thu, Dec 27, 2012 at 4:08 PM, Ramasubramanian Narayanan <
> ramasubramanian.narayanan@gmail.com> wrote:
>
> > Thanks a lot Tariq!!!
> >
> > Prefix is working fine...
> >
> > One more question.. in the above rowkey, if I want to select all the rows
> > which has "|home", how to do that...
> >
> > Like wise if there is a rowkey in the middle "A|B|C', how to select the
> > rows matching the "|B|" (middle column)...
> >
> > regards,
> > Rams
> >
> > On Thu, Dec 27, 2012 at 3:46 PM, Mohammad Tariq <do...@gmail.com>
> > wrote:
> >
> > > Hello Ram,
> > >
> > >     You can use PrefixFilter to do that.
> > > Filter filter = new PrefixFilter(Bytes.toBytes("10000000004"));
> > >
> > > Is it possible to use substring of rowkey in the where clause? I don't
> > know
> > > whether he may have home/office or any type of address..
> > > >>We don't have any 'where' clause in HBase. Also, you could end up
> with
> > RS
> > > Hotspotting with this kind of key design.
> > >
> > > Best Regards,
> > > Tariq
> > > +91-9741563634
> > > https://mtariq.jux.com/
> > >
> > >
> > > On Thu, Dec 27, 2012 at 3:37 PM, Asaf Mesika <as...@gmail.com>
> > > wrote:
> > >
> > > > You can define the StartKey of your scan object to be the customer
> > > > number (i.e. the prefix of your rowkey)
> > > > Define the end key to be the same but append a zero byte at the end
> to
> > > > signify include of the rowkey.
> > > > This should retrieve all rows starting with that customer number.
> > > >
> > > >
> > > > Sent from my iPhone
> > > >
> > > > On 27 בדצמ 2012, at 11:54, Ramasubramanian Narayanan
> > > > <ra...@gmail.com> wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > Suppose a rowkey contains some 5 fields delimited by "|", then how
> to
> > > use
> > > > > the same in the where clause?
> > > > >
> > > > > For example, I have some 4 customer records who is having different
> > > > number
> > > > > address .. for simplicity, I had for customer number 1,he has only
> > one
> > > > > address, for customer number 2, he has two addresses, like wise
> till
> > 4
> > > > > customer..
> > > > >
> > > > > So totally there will be 10 records in my table...
> > > > >
> > > > > Customer Number   Number of address
> > > > > Customer 1                          - 1
> > > > > Customer 2                          - 2
> > > > > Customer 3                          - 3
> > > > > Customer 4                          - 4
> > > > >                                               -----
> > > > >                                                 10
> > > > >
> > > > > *Here is my rowkey: (Customer number | Type of address)*
> > > > > 10000000001|OFFICE
> > > > > 10000000002|HOME
> > > > > 10000000002|OFFICE
> > > > > 10000000003|HOME
> > > > > 10000000003|OFFICE
> > > > > 10000000003|OTHERS
> > > > > 10000000004|HOME
> > > > > 10000000004|OFFICE1
> > > > > 10000000004|OFFICE2
> > > > > 10000000004|OTHERS
> > > > >
> > > > >
> > > > > Now question is, how to select all the details of customer 4
> > (customer
> > > > > number 10000000004)?
> > > > > Is it possible to use substring of rowkey in the where clause? I
> > don't
> > > > know
> > > > > whether he may have home/office or any type of address..
> > > > >
> > > > > Please help in providing query for the same..
> > > > >
> > > > > regards,
> > > > > Rams
> > > >
> > >
> >
>

Re: How to use substring in Rowkey

Posted by Ramasubramanian Narayanan <ra...@gmail.com>.
Hi,

Thanks!!
How to use/query inside HBASE shell with this filter..

regards,
Rams

On Thu, Dec 27, 2012 at 4:13 PM, Mohammad Tariq <do...@gmail.com> wrote:

> Try RowFilter with RegexStringComparator
>
> Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL,new
> RegexStringComparator("YOUR-REGEX"));
>
> Best Regards,
> Tariq
> +91-9741563634
> https://mtariq.jux.com/
>
>
> On Thu, Dec 27, 2012 at 4:08 PM, Ramasubramanian Narayanan <
> ramasubramanian.narayanan@gmail.com> wrote:
>
> > Thanks a lot Tariq!!!
> >
> > Prefix is working fine...
> >
> > One more question.. in the above rowkey, if I want to select all the rows
> > which has "|home", how to do that...
> >
> > Like wise if there is a rowkey in the middle "A|B|C', how to select the
> > rows matching the "|B|" (middle column)...
> >
> > regards,
> > Rams
> >
> > On Thu, Dec 27, 2012 at 3:46 PM, Mohammad Tariq <do...@gmail.com>
> > wrote:
> >
> > > Hello Ram,
> > >
> > >     You can use PrefixFilter to do that.
> > > Filter filter = new PrefixFilter(Bytes.toBytes("10000000004"));
> > >
> > > Is it possible to use substring of rowkey in the where clause? I don't
> > know
> > > whether he may have home/office or any type of address..
> > > >>We don't have any 'where' clause in HBase. Also, you could end up
> with
> > RS
> > > Hotspotting with this kind of key design.
> > >
> > > Best Regards,
> > > Tariq
> > > +91-9741563634
> > > https://mtariq.jux.com/
> > >
> > >
> > > On Thu, Dec 27, 2012 at 3:37 PM, Asaf Mesika <as...@gmail.com>
> > > wrote:
> > >
> > > > You can define the StartKey of your scan object to be the customer
> > > > number (i.e. the prefix of your rowkey)
> > > > Define the end key to be the same but append a zero byte at the end
> to
> > > > signify include of the rowkey.
> > > > This should retrieve all rows starting with that customer number.
> > > >
> > > >
> > > > Sent from my iPhone
> > > >
> > > > On 27 בדצמ 2012, at 11:54, Ramasubramanian Narayanan
> > > > <ra...@gmail.com> wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > Suppose a rowkey contains some 5 fields delimited by "|", then how
> to
> > > use
> > > > > the same in the where clause?
> > > > >
> > > > > For example, I have some 4 customer records who is having different
> > > > number
> > > > > address .. for simplicity, I had for customer number 1,he has only
> > one
> > > > > address, for customer number 2, he has two addresses, like wise
> till
> > 4
> > > > > customer..
> > > > >
> > > > > So totally there will be 10 records in my table...
> > > > >
> > > > > Customer Number   Number of address
> > > > > Customer 1                          - 1
> > > > > Customer 2                          - 2
> > > > > Customer 3                          - 3
> > > > > Customer 4                          - 4
> > > > >                                               -----
> > > > >                                                 10
> > > > >
> > > > > *Here is my rowkey: (Customer number | Type of address)*
> > > > > 10000000001|OFFICE
> > > > > 10000000002|HOME
> > > > > 10000000002|OFFICE
> > > > > 10000000003|HOME
> > > > > 10000000003|OFFICE
> > > > > 10000000003|OTHERS
> > > > > 10000000004|HOME
> > > > > 10000000004|OFFICE1
> > > > > 10000000004|OFFICE2
> > > > > 10000000004|OTHERS
> > > > >
> > > > >
> > > > > Now question is, how to select all the details of customer 4
> > (customer
> > > > > number 10000000004)?
> > > > > Is it possible to use substring of rowkey in the where clause? I
> > don't
> > > > know
> > > > > whether he may have home/office or any type of address..
> > > > >
> > > > > Please help in providing query for the same..
> > > > >
> > > > > regards,
> > > > > Rams
> > > >
> > >
> >
>

Re: How to use substring in Rowkey

Posted by Mohammad Tariq <do...@gmail.com>.
Try RowFilter with RegexStringComparator

Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL,new
RegexStringComparator("YOUR-REGEX"));

Best Regards,
Tariq
+91-9741563634
https://mtariq.jux.com/


On Thu, Dec 27, 2012 at 4:08 PM, Ramasubramanian Narayanan <
ramasubramanian.narayanan@gmail.com> wrote:

> Thanks a lot Tariq!!!
>
> Prefix is working fine...
>
> One more question.. in the above rowkey, if I want to select all the rows
> which has "|home", how to do that...
>
> Like wise if there is a rowkey in the middle "A|B|C', how to select the
> rows matching the "|B|" (middle column)...
>
> regards,
> Rams
>
> On Thu, Dec 27, 2012 at 3:46 PM, Mohammad Tariq <do...@gmail.com>
> wrote:
>
> > Hello Ram,
> >
> >     You can use PrefixFilter to do that.
> > Filter filter = new PrefixFilter(Bytes.toBytes("10000000004"));
> >
> > Is it possible to use substring of rowkey in the where clause? I don't
> know
> > whether he may have home/office or any type of address..
> > >>We don't have any 'where' clause in HBase. Also, you could end up with
> RS
> > Hotspotting with this kind of key design.
> >
> > Best Regards,
> > Tariq
> > +91-9741563634
> > https://mtariq.jux.com/
> >
> >
> > On Thu, Dec 27, 2012 at 3:37 PM, Asaf Mesika <as...@gmail.com>
> > wrote:
> >
> > > You can define the StartKey of your scan object to be the customer
> > > number (i.e. the prefix of your rowkey)
> > > Define the end key to be the same but append a zero byte at the end to
> > > signify include of the rowkey.
> > > This should retrieve all rows starting with that customer number.
> > >
> > >
> > > Sent from my iPhone
> > >
> > > On 27 בדצמ 2012, at 11:54, Ramasubramanian Narayanan
> > > <ra...@gmail.com> wrote:
> > >
> > > > Hi,
> > > >
> > > > Suppose a rowkey contains some 5 fields delimited by "|", then how to
> > use
> > > > the same in the where clause?
> > > >
> > > > For example, I have some 4 customer records who is having different
> > > number
> > > > address .. for simplicity, I had for customer number 1,he has only
> one
> > > > address, for customer number 2, he has two addresses, like wise till
> 4
> > > > customer..
> > > >
> > > > So totally there will be 10 records in my table...
> > > >
> > > > Customer Number   Number of address
> > > > Customer 1                          - 1
> > > > Customer 2                          - 2
> > > > Customer 3                          - 3
> > > > Customer 4                          - 4
> > > >                                               -----
> > > >                                                 10
> > > >
> > > > *Here is my rowkey: (Customer number | Type of address)*
> > > > 10000000001|OFFICE
> > > > 10000000002|HOME
> > > > 10000000002|OFFICE
> > > > 10000000003|HOME
> > > > 10000000003|OFFICE
> > > > 10000000003|OTHERS
> > > > 10000000004|HOME
> > > > 10000000004|OFFICE1
> > > > 10000000004|OFFICE2
> > > > 10000000004|OTHERS
> > > >
> > > >
> > > > Now question is, how to select all the details of customer 4
> (customer
> > > > number 10000000004)?
> > > > Is it possible to use substring of rowkey in the where clause? I
> don't
> > > know
> > > > whether he may have home/office or any type of address..
> > > >
> > > > Please help in providing query for the same..
> > > >
> > > > regards,
> > > > Rams
> > >
> >
>

Re: How to use substring in Rowkey

Posted by Ramasubramanian Narayanan <ra...@gmail.com>.
Thanks a lot Tariq!!!

Prefix is working fine...

One more question.. in the above rowkey, if I want to select all the rows
which has "|home", how to do that...

Like wise if there is a rowkey in the middle "A|B|C', how to select the
rows matching the "|B|" (middle column)...

regards,
Rams

On Thu, Dec 27, 2012 at 3:46 PM, Mohammad Tariq <do...@gmail.com> wrote:

> Hello Ram,
>
>     You can use PrefixFilter to do that.
> Filter filter = new PrefixFilter(Bytes.toBytes("10000000004"));
>
> Is it possible to use substring of rowkey in the where clause? I don't know
> whether he may have home/office or any type of address..
> >>We don't have any 'where' clause in HBase. Also, you could end up with RS
> Hotspotting with this kind of key design.
>
> Best Regards,
> Tariq
> +91-9741563634
> https://mtariq.jux.com/
>
>
> On Thu, Dec 27, 2012 at 3:37 PM, Asaf Mesika <as...@gmail.com>
> wrote:
>
> > You can define the StartKey of your scan object to be the customer
> > number (i.e. the prefix of your rowkey)
> > Define the end key to be the same but append a zero byte at the end to
> > signify include of the rowkey.
> > This should retrieve all rows starting with that customer number.
> >
> >
> > Sent from my iPhone
> >
> > On 27 בדצמ 2012, at 11:54, Ramasubramanian Narayanan
> > <ra...@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > Suppose a rowkey contains some 5 fields delimited by "|", then how to
> use
> > > the same in the where clause?
> > >
> > > For example, I have some 4 customer records who is having different
> > number
> > > address .. for simplicity, I had for customer number 1,he has only one
> > > address, for customer number 2, he has two addresses, like wise till 4
> > > customer..
> > >
> > > So totally there will be 10 records in my table...
> > >
> > > Customer Number   Number of address
> > > Customer 1                          - 1
> > > Customer 2                          - 2
> > > Customer 3                          - 3
> > > Customer 4                          - 4
> > >                                               -----
> > >                                                 10
> > >
> > > *Here is my rowkey: (Customer number | Type of address)*
> > > 10000000001|OFFICE
> > > 10000000002|HOME
> > > 10000000002|OFFICE
> > > 10000000003|HOME
> > > 10000000003|OFFICE
> > > 10000000003|OTHERS
> > > 10000000004|HOME
> > > 10000000004|OFFICE1
> > > 10000000004|OFFICE2
> > > 10000000004|OTHERS
> > >
> > >
> > > Now question is, how to select all the details of customer 4 (customer
> > > number 10000000004)?
> > > Is it possible to use substring of rowkey in the where clause? I don't
> > know
> > > whether he may have home/office or any type of address..
> > >
> > > Please help in providing query for the same..
> > >
> > > regards,
> > > Rams
> >
>

Re: How to use substring in Rowkey

Posted by Mohammad Tariq <do...@gmail.com>.
Hello Ram,

    You can use PrefixFilter to do that.
Filter filter = new PrefixFilter(Bytes.toBytes("10000000004"));

Is it possible to use substring of rowkey in the where clause? I don't know
whether he may have home/office or any type of address..
>>We don't have any 'where' clause in HBase. Also, you could end up with RS
Hotspotting with this kind of key design.

Best Regards,
Tariq
+91-9741563634
https://mtariq.jux.com/


On Thu, Dec 27, 2012 at 3:37 PM, Asaf Mesika <as...@gmail.com> wrote:

> You can define the StartKey of your scan object to be the customer
> number (i.e. the prefix of your rowkey)
> Define the end key to be the same but append a zero byte at the end to
> signify include of the rowkey.
> This should retrieve all rows starting with that customer number.
>
>
> Sent from my iPhone
>
> On 27 בדצמ 2012, at 11:54, Ramasubramanian Narayanan
> <ra...@gmail.com> wrote:
>
> > Hi,
> >
> > Suppose a rowkey contains some 5 fields delimited by "|", then how to use
> > the same in the where clause?
> >
> > For example, I have some 4 customer records who is having different
> number
> > address .. for simplicity, I had for customer number 1,he has only one
> > address, for customer number 2, he has two addresses, like wise till 4
> > customer..
> >
> > So totally there will be 10 records in my table...
> >
> > Customer Number   Number of address
> > Customer 1                          - 1
> > Customer 2                          - 2
> > Customer 3                          - 3
> > Customer 4                          - 4
> >                                               -----
> >                                                 10
> >
> > *Here is my rowkey: (Customer number | Type of address)*
> > 10000000001|OFFICE
> > 10000000002|HOME
> > 10000000002|OFFICE
> > 10000000003|HOME
> > 10000000003|OFFICE
> > 10000000003|OTHERS
> > 10000000004|HOME
> > 10000000004|OFFICE1
> > 10000000004|OFFICE2
> > 10000000004|OTHERS
> >
> >
> > Now question is, how to select all the details of customer 4 (customer
> > number 10000000004)?
> > Is it possible to use substring of rowkey in the where clause? I don't
> know
> > whether he may have home/office or any type of address..
> >
> > Please help in providing query for the same..
> >
> > regards,
> > Rams
>

Re: How to use substring in Rowkey

Posted by Asaf Mesika <as...@gmail.com>.
You can define the StartKey of your scan object to be the customer
number (i.e. the prefix of your rowkey)
Define the end key to be the same but append a zero byte at the end to
signify include of the rowkey.
This should retrieve all rows starting with that customer number.


Sent from my iPhone

On 27 בדצמ 2012, at 11:54, Ramasubramanian Narayanan
<ra...@gmail.com> wrote:

> Hi,
>
> Suppose a rowkey contains some 5 fields delimited by "|", then how to use
> the same in the where clause?
>
> For example, I have some 4 customer records who is having different number
> address .. for simplicity, I had for customer number 1,he has only one
> address, for customer number 2, he has two addresses, like wise till 4
> customer..
>
> So totally there will be 10 records in my table...
>
> Customer Number   Number of address
> Customer 1                          - 1
> Customer 2                          - 2
> Customer 3                          - 3
> Customer 4                          - 4
>                                               -----
>                                                 10
>
> *Here is my rowkey: (Customer number | Type of address)*
> 10000000001|OFFICE
> 10000000002|HOME
> 10000000002|OFFICE
> 10000000003|HOME
> 10000000003|OFFICE
> 10000000003|OTHERS
> 10000000004|HOME
> 10000000004|OFFICE1
> 10000000004|OFFICE2
> 10000000004|OTHERS
>
>
> Now question is, how to select all the details of customer 4 (customer
> number 10000000004)?
> Is it possible to use substring of rowkey in the where clause? I don't know
> whether he may have home/office or any type of address..
>
> Please help in providing query for the same..
>
> regards,
> Rams