You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Frank Luo <jl...@merkleinc.com> on 2013/07/18 22:20:49 UTC
Hbase: Is possible to filter by integer value if the value is saved
as string?
I don't think it is possible, but would like to confirm with smart folks out there.
Supposing I have a cell storing an integer but in string presentation. For example, here is how I put a value of 200:
put.add(family, qualifier, Bytes.toBytes("200"));
Now, I want to scan with a filter that only return if the value is larger than 250. Is that possible?
Thanks in advance
Frank
Re: Hbase: Is possible to filter by integer value if the value is
saved as string?
Posted by Kevin <ke...@gmail.com>.
The only way I was able to do negative numbers was to create a new
WritableComparable that took signed-ness into account, but that involved
deploying the class to the cluster.
On Fri, Jul 19, 2013 at 10:44 AM, Frank Luo <jl...@merkleinc.com> wrote:
> OK, let's say it is stored as an integer, how to compare then?
>
> As Jean-Marc pointed out, negative numbers is greater than positive ones
> using ByteArrayComparable.
>
> -----Original Message-----
> From: Jean-Marc Spaggiari [mailto:jean-marc@spaggiari.org]
> Sent: Friday, July 19, 2013 5:08 AM
> To: user@hbase.apache.org
> Subject: Re: Hbase: Is possible to filter by integer value if the value is
> saved as string?
>
> I agree with Anil... Store it as an integer, not as as String. That will
> help for the comparison (be carreful with negative values comparisons.).
>
> Worst case, run a MR job to convert them.
>
> 2013/7/19 anil gupta <an...@gmail.com>
>
> > Only way to achieve this is to write your own ByteArrayComparable.
> > BinaryComparator wont work for your case.
> > But, I am wondering why you would store an Integer as String when you
> > want to do numerical comparison?
> >
> >
> > On Thu, Jul 18, 2013 at 6:03 PM, Ted Yu <yu...@gmail.com> wrote:
> >
> > > What would happen to this ?
> > >
> > > System.out.println(c.compareTo(Bytes.toBytes("30")));
> > >
> > > On Thu, Jul 18, 2013 at 5:55 PM, Kevin <ke...@gmail.com>
> > wrote:
> > >
> > > > Sure, try using the BinaryComparator. For example,
> > > >
> > > > BinaryComparator c = new
> > BinaryComparator(Bytes.toBytes("200"));
> > > > System.out.println(c.compareTo(Bytes.toBytes("201"))); //
> > returns
> > > > -1
> > > >
> > > >
> > > > On Thu, Jul 18, 2013 at 4:28 PM, Frank Luo <jl...@merkleinc.com>
> wrote:
> > > >
> > > > > That requires creating my own ByteArrayComparable class and
> > > > > deploy to
> > > all
> > > > > servers, right?
> > > > >
> > > > > My company doesn't want to "customize" hbase, hence is not an
> > > > > option
> > to
> > > > me.
> > > > >
> > > > > -----Original Message-----
> > > > > From: Ted Yu [mailto:yuzhihong@gmail.com]
> > > > > Sent: Thursday, July 18, 2013 3:25 PM
> > > > > To: user@hbase.apache.org
> > > > > Subject: Re: Hbase: Is possible to filter by integer value if
> > > > > the
> > value
> > > > is
> > > > > saved as string?
> > > > >
> > > > > Looks like you should be able to do so by passing your own
> > > > > comparator
> > > to:
> > > > >
> > > > > public SingleColumnValueFilter(final byte [] family, final
> > > > > byte [] qualifier,
> > > > >
> > > > > final CompareOp compareOp, final ByteArrayComparable
> > comparator)
> > > {
> > > > > Cheers
> > > > >
> > > > > On Thu, Jul 18, 2013 at 1:20 PM, Frank Luo <jl...@merkleinc.com>
> > wrote:
> > > > >
> > > > > > I don't think it is possible, but would like to confirm with
> > > > > > smart folks out there.
> > > > > >
> > > > > > Supposing I have a cell storing an integer but in string
> > > presentation.
> > > > > > For example, here is how I put a value of 200:
> > > > > >
> > > > > > put.add(family, qualifier, Bytes.toBytes("200"));
> > > > > >
> > > > > > Now, I want to scan with a filter that only return if the
> > > > > > value is larger than 250. Is that possible?
> > > > > >
> > > > > > Thanks in advance
> > > > > >
> > > > > > Frank
> > > > > >
> > > > >
> > > > >
> > > >
> > >
> >
> >
> >
> > --
> > Thanks & Regards,
> > Anil Gupta
> >
>
RE: Hbase: Is possible to filter by integer value if the value is
saved as string?
Posted by Frank Luo <jl...@merkleinc.com>.
OK, let's say it is stored as an integer, how to compare then?
As Jean-Marc pointed out, negative numbers is greater than positive ones using ByteArrayComparable.
-----Original Message-----
From: Jean-Marc Spaggiari [mailto:jean-marc@spaggiari.org]
Sent: Friday, July 19, 2013 5:08 AM
To: user@hbase.apache.org
Subject: Re: Hbase: Is possible to filter by integer value if the value is saved as string?
I agree with Anil... Store it as an integer, not as as String. That will help for the comparison (be carreful with negative values comparisons.).
Worst case, run a MR job to convert them.
2013/7/19 anil gupta <an...@gmail.com>
> Only way to achieve this is to write your own ByteArrayComparable.
> BinaryComparator wont work for your case.
> But, I am wondering why you would store an Integer as String when you
> want to do numerical comparison?
>
>
> On Thu, Jul 18, 2013 at 6:03 PM, Ted Yu <yu...@gmail.com> wrote:
>
> > What would happen to this ?
> >
> > System.out.println(c.compareTo(Bytes.toBytes("30")));
> >
> > On Thu, Jul 18, 2013 at 5:55 PM, Kevin <ke...@gmail.com>
> wrote:
> >
> > > Sure, try using the BinaryComparator. For example,
> > >
> > > BinaryComparator c = new
> BinaryComparator(Bytes.toBytes("200"));
> > > System.out.println(c.compareTo(Bytes.toBytes("201"))); //
> returns
> > > -1
> > >
> > >
> > > On Thu, Jul 18, 2013 at 4:28 PM, Frank Luo <jl...@merkleinc.com> wrote:
> > >
> > > > That requires creating my own ByteArrayComparable class and
> > > > deploy to
> > all
> > > > servers, right?
> > > >
> > > > My company doesn't want to "customize" hbase, hence is not an
> > > > option
> to
> > > me.
> > > >
> > > > -----Original Message-----
> > > > From: Ted Yu [mailto:yuzhihong@gmail.com]
> > > > Sent: Thursday, July 18, 2013 3:25 PM
> > > > To: user@hbase.apache.org
> > > > Subject: Re: Hbase: Is possible to filter by integer value if
> > > > the
> value
> > > is
> > > > saved as string?
> > > >
> > > > Looks like you should be able to do so by passing your own
> > > > comparator
> > to:
> > > >
> > > > public SingleColumnValueFilter(final byte [] family, final
> > > > byte [] qualifier,
> > > >
> > > > final CompareOp compareOp, final ByteArrayComparable
> comparator)
> > {
> > > > Cheers
> > > >
> > > > On Thu, Jul 18, 2013 at 1:20 PM, Frank Luo <jl...@merkleinc.com>
> wrote:
> > > >
> > > > > I don't think it is possible, but would like to confirm with
> > > > > smart folks out there.
> > > > >
> > > > > Supposing I have a cell storing an integer but in string
> > presentation.
> > > > > For example, here is how I put a value of 200:
> > > > >
> > > > > put.add(family, qualifier, Bytes.toBytes("200"));
> > > > >
> > > > > Now, I want to scan with a filter that only return if the
> > > > > value is larger than 250. Is that possible?
> > > > >
> > > > > Thanks in advance
> > > > >
> > > > > Frank
> > > > >
> > > >
> > > >
> > >
> >
>
>
>
> --
> Thanks & Regards,
> Anil Gupta
>
Re: Hbase: Is possible to filter by integer value if the value is
saved as string?
Posted by Jean-Marc Spaggiari <je...@spaggiari.org>.
I agree with Anil... Store it as an integer, not as as String. That will
help for the comparison (be carreful with negative values comparisons.).
Worst case, run a MR job to convert them.
2013/7/19 anil gupta <an...@gmail.com>
> Only way to achieve this is to write your own ByteArrayComparable.
> BinaryComparator wont work for your case.
> But, I am wondering why you would store an Integer as String when you want
> to do numerical comparison?
>
>
> On Thu, Jul 18, 2013 at 6:03 PM, Ted Yu <yu...@gmail.com> wrote:
>
> > What would happen to this ?
> >
> > System.out.println(c.compareTo(Bytes.toBytes("30")));
> >
> > On Thu, Jul 18, 2013 at 5:55 PM, Kevin <ke...@gmail.com>
> wrote:
> >
> > > Sure, try using the BinaryComparator. For example,
> > >
> > > BinaryComparator c = new
> BinaryComparator(Bytes.toBytes("200"));
> > > System.out.println(c.compareTo(Bytes.toBytes("201"))); //
> returns
> > > -1
> > >
> > >
> > > On Thu, Jul 18, 2013 at 4:28 PM, Frank Luo <jl...@merkleinc.com> wrote:
> > >
> > > > That requires creating my own ByteArrayComparable class and deploy to
> > all
> > > > servers, right?
> > > >
> > > > My company doesn't want to "customize" hbase, hence is not an option
> to
> > > me.
> > > >
> > > > -----Original Message-----
> > > > From: Ted Yu [mailto:yuzhihong@gmail.com]
> > > > Sent: Thursday, July 18, 2013 3:25 PM
> > > > To: user@hbase.apache.org
> > > > Subject: Re: Hbase: Is possible to filter by integer value if the
> value
> > > is
> > > > saved as string?
> > > >
> > > > Looks like you should be able to do so by passing your own comparator
> > to:
> > > >
> > > > public SingleColumnValueFilter(final byte [] family, final byte []
> > > > qualifier,
> > > >
> > > > final CompareOp compareOp, final ByteArrayComparable
> comparator)
> > {
> > > > Cheers
> > > >
> > > > On Thu, Jul 18, 2013 at 1:20 PM, Frank Luo <jl...@merkleinc.com>
> wrote:
> > > >
> > > > > I don't think it is possible, but would like to confirm with smart
> > > > > folks out there.
> > > > >
> > > > > Supposing I have a cell storing an integer but in string
> > presentation.
> > > > > For example, here is how I put a value of 200:
> > > > >
> > > > > put.add(family, qualifier, Bytes.toBytes("200"));
> > > > >
> > > > > Now, I want to scan with a filter that only return if the value is
> > > > > larger than 250. Is that possible?
> > > > >
> > > > > Thanks in advance
> > > > >
> > > > > Frank
> > > > >
> > > >
> > > >
> > >
> >
>
>
>
> --
> Thanks & Regards,
> Anil Gupta
>
Re: Hbase: Is possible to filter by integer value if the value is
saved as string?
Posted by anil gupta <an...@gmail.com>.
Only way to achieve this is to write your own ByteArrayComparable.
BinaryComparator wont work for your case.
But, I am wondering why you would store an Integer as String when you want
to do numerical comparison?
On Thu, Jul 18, 2013 at 6:03 PM, Ted Yu <yu...@gmail.com> wrote:
> What would happen to this ?
>
> System.out.println(c.compareTo(Bytes.toBytes("30")));
>
> On Thu, Jul 18, 2013 at 5:55 PM, Kevin <ke...@gmail.com> wrote:
>
> > Sure, try using the BinaryComparator. For example,
> >
> > BinaryComparator c = new BinaryComparator(Bytes.toBytes("200"));
> > System.out.println(c.compareTo(Bytes.toBytes("201"))); // returns
> > -1
> >
> >
> > On Thu, Jul 18, 2013 at 4:28 PM, Frank Luo <jl...@merkleinc.com> wrote:
> >
> > > That requires creating my own ByteArrayComparable class and deploy to
> all
> > > servers, right?
> > >
> > > My company doesn't want to "customize" hbase, hence is not an option to
> > me.
> > >
> > > -----Original Message-----
> > > From: Ted Yu [mailto:yuzhihong@gmail.com]
> > > Sent: Thursday, July 18, 2013 3:25 PM
> > > To: user@hbase.apache.org
> > > Subject: Re: Hbase: Is possible to filter by integer value if the value
> > is
> > > saved as string?
> > >
> > > Looks like you should be able to do so by passing your own comparator
> to:
> > >
> > > public SingleColumnValueFilter(final byte [] family, final byte []
> > > qualifier,
> > >
> > > final CompareOp compareOp, final ByteArrayComparable comparator)
> {
> > > Cheers
> > >
> > > On Thu, Jul 18, 2013 at 1:20 PM, Frank Luo <jl...@merkleinc.com> wrote:
> > >
> > > > I don't think it is possible, but would like to confirm with smart
> > > > folks out there.
> > > >
> > > > Supposing I have a cell storing an integer but in string
> presentation.
> > > > For example, here is how I put a value of 200:
> > > >
> > > > put.add(family, qualifier, Bytes.toBytes("200"));
> > > >
> > > > Now, I want to scan with a filter that only return if the value is
> > > > larger than 250. Is that possible?
> > > >
> > > > Thanks in advance
> > > >
> > > > Frank
> > > >
> > >
> > >
> >
>
--
Thanks & Regards,
Anil Gupta
Re: Hbase: Is possible to filter by integer value if the value is
saved as string?
Posted by Ted Yu <yu...@gmail.com>.
What would happen to this ?
System.out.println(c.compareTo(Bytes.toBytes("30")));
On Thu, Jul 18, 2013 at 5:55 PM, Kevin <ke...@gmail.com> wrote:
> Sure, try using the BinaryComparator. For example,
>
> BinaryComparator c = new BinaryComparator(Bytes.toBytes("200"));
> System.out.println(c.compareTo(Bytes.toBytes("201"))); // returns
> -1
>
>
> On Thu, Jul 18, 2013 at 4:28 PM, Frank Luo <jl...@merkleinc.com> wrote:
>
> > That requires creating my own ByteArrayComparable class and deploy to all
> > servers, right?
> >
> > My company doesn't want to "customize" hbase, hence is not an option to
> me.
> >
> > -----Original Message-----
> > From: Ted Yu [mailto:yuzhihong@gmail.com]
> > Sent: Thursday, July 18, 2013 3:25 PM
> > To: user@hbase.apache.org
> > Subject: Re: Hbase: Is possible to filter by integer value if the value
> is
> > saved as string?
> >
> > Looks like you should be able to do so by passing your own comparator to:
> >
> > public SingleColumnValueFilter(final byte [] family, final byte []
> > qualifier,
> >
> > final CompareOp compareOp, final ByteArrayComparable comparator) {
> > Cheers
> >
> > On Thu, Jul 18, 2013 at 1:20 PM, Frank Luo <jl...@merkleinc.com> wrote:
> >
> > > I don't think it is possible, but would like to confirm with smart
> > > folks out there.
> > >
> > > Supposing I have a cell storing an integer but in string presentation.
> > > For example, here is how I put a value of 200:
> > >
> > > put.add(family, qualifier, Bytes.toBytes("200"));
> > >
> > > Now, I want to scan with a filter that only return if the value is
> > > larger than 250. Is that possible?
> > >
> > > Thanks in advance
> > >
> > > Frank
> > >
> >
> >
>
Re: Hbase: Is possible to filter by integer value if the value is
saved as string?
Posted by Kevin <ke...@gmail.com>.
Sure, try using the BinaryComparator. For example,
BinaryComparator c = new BinaryComparator(Bytes.toBytes("200"));
System.out.println(c.compareTo(Bytes.toBytes("201"))); // returns -1
On Thu, Jul 18, 2013 at 4:28 PM, Frank Luo <jl...@merkleinc.com> wrote:
> That requires creating my own ByteArrayComparable class and deploy to all
> servers, right?
>
> My company doesn't want to "customize" hbase, hence is not an option to me.
>
> -----Original Message-----
> From: Ted Yu [mailto:yuzhihong@gmail.com]
> Sent: Thursday, July 18, 2013 3:25 PM
> To: user@hbase.apache.org
> Subject: Re: Hbase: Is possible to filter by integer value if the value is
> saved as string?
>
> Looks like you should be able to do so by passing your own comparator to:
>
> public SingleColumnValueFilter(final byte [] family, final byte []
> qualifier,
>
> final CompareOp compareOp, final ByteArrayComparable comparator) {
> Cheers
>
> On Thu, Jul 18, 2013 at 1:20 PM, Frank Luo <jl...@merkleinc.com> wrote:
>
> > I don't think it is possible, but would like to confirm with smart
> > folks out there.
> >
> > Supposing I have a cell storing an integer but in string presentation.
> > For example, here is how I put a value of 200:
> >
> > put.add(family, qualifier, Bytes.toBytes("200"));
> >
> > Now, I want to scan with a filter that only return if the value is
> > larger than 250. Is that possible?
> >
> > Thanks in advance
> >
> > Frank
> >
>
>
RE: Hbase: Is possible to filter by integer value if the value is
saved as string?
Posted by Frank Luo <jl...@merkleinc.com>.
That requires creating my own ByteArrayComparable class and deploy to all servers, right?
My company doesn't want to "customize" hbase, hence is not an option to me.
-----Original Message-----
From: Ted Yu [mailto:yuzhihong@gmail.com]
Sent: Thursday, July 18, 2013 3:25 PM
To: user@hbase.apache.org
Subject: Re: Hbase: Is possible to filter by integer value if the value is saved as string?
Looks like you should be able to do so by passing your own comparator to:
public SingleColumnValueFilter(final byte [] family, final byte [] qualifier,
final CompareOp compareOp, final ByteArrayComparable comparator) { Cheers
On Thu, Jul 18, 2013 at 1:20 PM, Frank Luo <jl...@merkleinc.com> wrote:
> I don't think it is possible, but would like to confirm with smart
> folks out there.
>
> Supposing I have a cell storing an integer but in string presentation.
> For example, here is how I put a value of 200:
>
> put.add(family, qualifier, Bytes.toBytes("200"));
>
> Now, I want to scan with a filter that only return if the value is
> larger than 250. Is that possible?
>
> Thanks in advance
>
> Frank
>
Re: Hbase: Is possible to filter by integer value if the value is
saved as string?
Posted by Ted Yu <yu...@gmail.com>.
Looks like you should be able to do so by passing your own comparator to:
public SingleColumnValueFilter(final byte [] family, final byte []
qualifier,
final CompareOp compareOp, final ByteArrayComparable comparator) {
Cheers
On Thu, Jul 18, 2013 at 1:20 PM, Frank Luo <jl...@merkleinc.com> wrote:
> I don't think it is possible, but would like to confirm with smart folks
> out there.
>
> Supposing I have a cell storing an integer but in string presentation. For
> example, here is how I put a value of 200:
>
> put.add(family, qualifier, Bytes.toBytes("200"));
>
> Now, I want to scan with a filter that only return if the value is larger
> than 250. Is that possible?
>
> Thanks in advance
>
> Frank
>