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
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
> >> >         {
> >> >
> >> >             byte[]
> >> > val=(value.getValue("stocks".getBytes(),"open".getBytes()));
> >> >             //byte[]
> >> > val1=(value.getValue("stocks".getBytes(),"symbol".getBytes()));
> >> >
> >> >
> >> >             ImmutableBytesWritable stock_symbol=new
> >> > ImmutableBytesWritable("symbol".getBytes());
> >> >
> >> >
> >> >             try
> >> >             {
> >> >                 context.write(stock_symbol,new
> >> > FloatWritable(Bytes.toFloat(val)));
> >> >             }
> >> >             catch(InterruptedException e)
> >> >
> >> >             {
> >> >                  throw new IOException(e);

Regards

*Manish Dunani*
*Contact No* : +91 9408329137
*skype id* : manish.dunani*
*