Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
HBase, mail # user - Hbase: Is possible to filter by integer value if the value is saved as string?


+
Frank Luo 2013-07-18, 20:20
+
Ted Yu 2013-07-18, 20:24
+
Frank Luo 2013-07-18, 20:28
+
Kevin 2013-07-19, 00:55
+
Ted Yu 2013-07-19, 01:03
Copy link to this message
-
Re: Hbase: Is possible to filter by integer value if the value is saved as string?
anil gupta 2013-07-19, 05:58
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 <[EMAIL PROTECTED]> wrote:

> What would happen to this ?
>
>         System.out.println(c.compareTo(Bytes.toBytes("30")));
>
> On Thu, Jul 18, 2013 at 5:55 PM, Kevin <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED]]
> > > Sent: Thursday, July 18, 2013 3:25 PM
> > > To: [EMAIL PROTECTED]
> > > 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 <[EMAIL PROTECTED]> 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
+
Jean-Marc Spaggiari 2013-07-19, 10:07
+
Frank Luo 2013-07-19, 14:44
+
Kevin 2013-07-19, 14:53