Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
MapReduce >> mail # user >> Re: Want to Sort the values in one line using map reduce


Copy link to this message
-
Re: Want to Sort the values in one line using map reduce
    *"Thanks a lot Devraj!!!!!!!!"*
On Sat, Jul 27, 2013 at 10:25 AM, Devaraj k <[EMAIL PROTECTED]> wrote:

>  You are almost done to get the desired output. You need to change little
> in the reduce function like this, ****
>
> ** **
>
> *public* *static* *class* ReduceClass *extends* *MapReduceBase* *
> implements*****
>
>       *Reducer*<Text, Text, Text, Text> {****
>
>     Text v = *new* Text();****
>
> ** **
>
>     *public* *void* reduce(Text key, *Iterator*<Text> values,****
>
>         *OutputCollector*<Text, Text> output, *Reporter* reporter)****
>
>         *throws* IOException {****
>
>       StringBuffer value = *new* StringBuffer();****
>
>       *while* (values.hasNext()){****
>
>         value.append(values.next().toString());****
>
>         value.append(",");****
>
>       }****
>
>       v.set(value.toString());****
>
>       output.collect(key, v);****
>
>     }****
>
>   }****
>
> In the above reduce function you can add logical condition to avoid extra
> ‘,’ at end of each value line.****
>
> ** **
>
> Thanks****
>
> Devaraj k****
>
> ** **
>
> *From:* manish dunani [mailto:[EMAIL PROTECTED]]
> *Sent:* 27 July 2013 10:02
> *To:* [EMAIL PROTECTED]
> *Subject:* Want to Sort the values in one line using map reduce****
>
> ** **
>
> Hi,****
>
> ** **
>
> *I have input file and my data looks like:*****
>
> ** **
>
>    date ****
>
> country****
>
>  city****
>
> pagePath****
>
> visits****
>
> 20120301 ****
>
> India****
>
> Ahmedabad****
>
> /****
>
> 1****
>
> 20120302 ****
>
> India****
>
> Ahmedabad****
>
> /gtuadmissionhelpline-team****
>
> 1****
>
> 20120302 ****
>
> India****
>
> Mumbai****
>
> /****
>
> 1****
>
> 20120302 ****
>
> India****
>
> Mumbai****
>
> /merit-calculator****
>
> 1****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> * I wrote the map and reduce application to convert it into page_url by
> city:*****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> package data.ga;****
>
> ** **
>
> import java.io.IOException;****
>
> import java.util.Iterator;****
>
> import org.apache.hadoop.fs.Path;****
>
> import org.apache.hadoop.io.LongWritable;****
>
> import org.apache.hadoop.io.Text;****
>
> import org.apache.hadoop.mapred.FileInputFormat;****
>
> import org.apache.hadoop.mapred.FileOutputFormat;****
>
> import org.apache.hadoop.mapred.JobClient;****
>
> import org.apache.hadoop.mapred.JobConf;****
>
> import org.apache.hadoop.mapred.MapReduceBase;****
>
> import org.apache.hadoop.mapred.Mapper;****
>
> import org.apache.hadoop.mapred.OutputCollector;****
>
> import org.apache.hadoop.mapred.Reducer;****
>
> import org.apache.hadoop.mapred.Reporter;****
>
> import org.apache.hadoop.mapred.TextInputFormat;****
>
> import org.apache.hadoop.mapred.TextOutputFormat;****
>
> ** **
>
> ** **
>
> public class pharmecy ****
>
> {****
>
>             public static class MapClass extends MapReduceBase implements
> Mapper<LongWritable,Text,Text,Text>****
>
>             {****
>
>                         Text k = new Text();****
>
>                         Text v = new Text();****
>
>                         ****
>
>                         public void map(LongWritable key,Text
> value,OutputCollector<Text,Text>output,Reporter reporter) throws IOException
> ****
>
>                         {****
>
>                                     try****
>
>                                     {****
>
>                                     String[] line > value.toString().split(",",5);****
>
>                                     ****
>
>                                     String city = String.valueOf(line[2]);
> ****
>
>                                     String url = String.valueOf(line[3]);*
> ***
>
>                                     ****
>
>                                     k.set(city);****
>
>                                     v.set(url);****
>
>                                     ****
>
>                                     output.collect(k, v);****
>
>                                     }****

MANISH DUNANI
-THANX
+91 9426881954,+91 8460656443
[EMAIL PROTECTED]
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB