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

Switch to Threaded View
HBase >> mail # user >> [Error]Finding average using hbase hadoop


Copy link to this message
-
Re: [Error]Finding average using hbase hadoop
Hi Manish.

Looking a bit more at this, I think the issue is because you "floats" are
written in you table as strings and not as floats....

Can you try something link:
context.write(stock_symbol,new FloatWritable(
Float.parseFloat(Bytes.toString(val)))));

Also, as asked previously,  " can you please paste you code on pastbin?
Same for the exception."?

Thanks,

JM

2013/8/17 manish dunani <[EMAIL PROTECTED]>

> Hey jean,
> I did it according to you.
> I convert as u told..But still face the same error.
>
> And ted I am new to this don't get an idea how can i use this method..Can
> You please show me..?
>
> Your Help will be appreciated..
>
>
>
> On Fri, Aug 16, 2013 at 10:04 PM, Ted Yu <[EMAIL PROTECTED]> wrote:
>
> > Here is javadoc for toFloat():
> >
> >    * Presumes float encoded as IEEE 754 floating-point "single format"
> >
> >    * @param bytes byte array
> >
> >    * @return Float made from passed byte array.
> >
> >    */
> >
> >   public static float toFloat(byte [] bytes) {
> >
> > So for values of '2.5', toFloat() is not the proper method.
> >
> > You can float conversion provided by Java.
> >
> >
> > Cheers
> >
> >
> > On Fri, Aug 16, 2013 at 6:57 AM, Ted Yu <[EMAIL PROTECTED]> wrote:
> >
> > > Here is code from Bytes:
> > >
> > >   public static float toFloat(byte [] bytes, int offset) {
> > >
> > >     return Float.intBitsToFloat(toInt(bytes, offset, SIZEOF_INT));
> > >
> > > Looking at your sample data:
> > >
> > >  2010-02-04           column=stocks:open, timestamp=1376567559424,
> > > value=*2.5*
> > >
> > > The length of value didn't match SIZEOF_INT.
> > >
> > > It seems you need to validate the values first.
> > >
> > >
> > > Cheers
> > >
> > >
> > > On Fri, Aug 16, 2013 at 3:42 AM, manish dunani <[EMAIL PROTECTED]
> > >wrote:
> > >
> > >> hello,
> > >>
> > >> I am using apache hadoop 1.1.2 and hbase 0.94.9 on pseudo distibuted
> > mode.
> > >>
> > >> I am trying to find Average open stocks values.
> > >>
> > >> *sample dataset in hbase::**(table name:nyse4)*
> > >>
> > >>
> > >>  2010-02-04           column=stocks:open, timestamp=1376567559424,
> > >> value=2.5
> > >>  2010-02-04           column=stocks:symbol, timestamp=1376567559424,
> > >> value=QXM
> > >>  2010-02-05           column=stocks:open, timestamp=1376567559429,
> > >> value=2.42
> > >>  2010-02-05           column=stocks:symbol, timestamp=1376567559429,
> > >> value=QXM
> > >>  2010-02-08           column=stocks:open, timestamp=1376567559431,
> > >> value=2.33
> > >>  2010-02-08           column=stocks:symbol, timestamp=1376567559431,
> > >> value=QXM
> > >>
> > >> *code:*(please ignores the lines that are commenting)
> > >>
> > >>
> > >> > package com.maddy;
> > >> >
> > >> > import java.io.IOException;
> > >> >
> > >> > import org.apache.hadoop.conf.Configuration;
> > >> > import org.apache.hadoop.fs.Path;
> > >> > import org.apache.hadoop.hbase.HBaseConfiguration;
> > >> > import org.apache.hadoop.hbase.client.Put;
> > >> > import org.apache.hadoop.hbase.client.Result;
> > >> > import org.apache.hadoop.hbase.client.Scan;
> > >> > import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter;
> > >> > import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
> > >> > import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
> > >> > import org.apache.hadoop.hbase.mapreduce.TableMapper;
> > >> > import org.apache.hadoop.hbase.mapreduce.TableReducer;
> > >> > import org.apache.hadoop.hbase.util.Bytes;
> > >> > //import org.apache.hadoop.io.DoubleWritable;
> > >> > import org.apache.hadoop.io.FloatWritable;
> > >> > import org.apache.hadoop.mapreduce.Job;
> > >> > import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
> > >> >
> > >> >
> > >> > public class openaveragestock
> > >> > {
> > >> >     public static class map extends
> > >> > TableMapper<ImmutableBytesWritable,FloatWritable>
> > >> >     {
> > >> >         @Override
> > >> >
> > >> >         public void map(ImmutableBytesWritable row,Result
> > value,Context
> > >> > context) throws IOException