MapReduce and Design Patterns - Counting with Counters Example
2K views
Oct 18, 2024
MapReduce and Design Patterns - Counting with Counters Example https://www.tutorialspoint.com/market/index.asp Get Extra 10% OFF on all courses, Ebooks, and prime packs, USE CODE: YOUTUBE10
View Video Transcript
0:00
In this video we are discussing Counting with Counters example
0:05
And this video will be assisted with one practical demonstration to give you the idea how to
0:10
write the course, run and implement. So counting with counters example. So in this example we will be using batches.xm
0:20
So we are having one XML that is a batches dot XML on which our program will be working, which
0:26
will count the number of different batches. The batches are having different categories and there are three types of batches are there
0:34
One is gold, next one is silver and the last one is the brooch
0:38
So after completing the task, it will return the count of each batch type
0:43
So that's the problem we are going to implement now. So let us go for one practical demonstration for the easy understanding of this concept
0:52
Under the summarization design pattern, we are going to implement counting with counters
0:57
is a map only job we're having the input file batches dot XML which is under the
1:03
folder slash input slash batch so these batches dot XML is having multiple
1:08
tags are there and multiple attributes are there so let us go for the the
1:14
content of this batches dot XML so batches is one tag under this tag we're
1:19
having multiple number of rows are there we're having ID which we are also
1:25
having the user ID then name then date then class and then tag based this class is having multiple values and
1:33
three values are mainly there three two and one it is a map only job so we are
1:39
having only one class in this case and that is a class is counting MR task
1:44
and as it is a map only so that why we only extending one inner class from the mapper we having one enumerator here so there is a protected static enum containing gold silver and
1:58
bronze so now this is the inner class there is a static class there and this
2:04
inner class that is a counting mapper extends mapper so we are not having any
2:08
kind of reducer here so we are having only class inner class that is a
2:12
counting mapper which is extending mapper and which is overriding the method
2:17
that is a map so in this particular map we're having one hash map object
2:21
XML parsed and this particular object is getting instantiated with the method
2:26
that is XML to map which takes one XML as input and produces the hash map object
2:32
as output and that will be put onto this XML parsed now with the method XML parsed
2:40
we're reading the class value we're reading the class tag value we have
2:46
shown you that we're having one field one attribute that is a class in our batches dot XML see this class is
2:53
there it is having three values one two and three so here we're checking that
2:59
with if the type dot equals one then from the context object ct x we are
3:06
getting the gate counter and the batches batch type countered gold will be incremented by one so here the gold count will be
3:13
incremented by one and we know that we're having this type of three values are there one two and three classes are there so for for the
3:22
silver we're incrementing the value if the type is two for bronze if the type
3:26
dot equals is three then the value will be incremented by one so this is my
3:33
respective main function here we are checking that how many arguments were
3:38
passing the argument should be passed as to if the arguments are not passing as two so then the respective error message will be displayed so this is the error message we having an a system dot exit 2 we are defining one job object and this job
3:54
object will have the name count number of batches of different types so we are
4:00
creating one job object and job object will have the name count number of
4:04
batches of different type we're having the file input format and file output
4:08
format so they will be initialized with argument zero and argument one we're
4:13
having only mapper so that's why we're just this is a mapper extended class
4:18
so that is accounting mapper dot class and set num reduce task zero so
4:23
because that is no reducer will work here set output key so output key and output
4:30
value so both are initialized with this null writable so both are initialized with
4:37
this null writeable and here you are going to take the completion there is a status of the completion
4:44
so whether it is true whether it is zero or one depending upon that we can put
4:49
the respective message and then the system dot exit code so in this way the main
4:56
function the main method has been written here the respective number of
5:03
types we are printing that is how many types of this gold
5:08
this bronze and silver so the respective count will be also printed using this
5:15
fordook so at first we shall go for the creating the jar so we shall go for
5:22
this and then then the respective path name and the file name has to be given
5:27
already we have created the jar file so we are leaving the scale steps but after that we will be going for next and finish now let me execute my command So command is Hadoop jar and the path in which the jar file will be existing
5:44
So that is a map produced design pattern jar files. So this is a path in which the summarization pattern.jar, this jar file will be existing
5:53
Then counting counter is the respective package name. And under that we'll be having counting a mart task
6:02
so there is a class name input slash input slash badge is the input file path name and slash
6:09
output will be the output file path name so in this way we are going to execute our command so
6:14
let us execute the command we can find here that is the bytes written is equal to
6:24
zero the bytes written is equal to zero means it is all it is a map only job so nothing
6:30
will be written by the reducer but you'll be getting the output in the last three
6:34
lines there is a number of gold batches 5-2-3-7 number of silver batches are
6:39
given number of bronze batches are given here so you can find that the
6:44
respective batch count we have also got it and we have printed that one because
6:50
we had that fall loop at the end of the Java code so from there the batch counts
6:55
respective three classes have got printed so now let me come to the output folder
7:00
So here is the output folder and you can find that we are having two part files, but both of them are having the size of 0 bytes
7:08
Two part files are there having got the size of 0 bytes because nothing has been written onto the part files
7:13
So let us delete them. Let us delete them. So DFS, SDFS, DFS minus R and this output path is getting deleted
7:28
Thanks for watching
#Computer Education
#Educational Software
#Programming
#Training & Certification