MapReduce and Design Patterns - Counting with Counters Example
1K 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 and this video will be
0:06
assisted with one practical demonstration to give you the idea how to write the
0:11
course run and implement. So counting with counters example. So in this example
0:18
we will be using batches.xm. So we are having one xm that is a batches dot XML on which
0:23
our program will be working which will count the number of different batches. The
0:29
batches are having different categories and there are three types of batches are
0:33
there one is gold next one is silver and the last one is the brooch so after
0:38
completing the task it will return the count of each batch type so that's
0:43
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 under the
0:52
summarization design pattern we are going to implement counting with counters it is a
0:58
map only job we're having the input file batches dot XML which is under the folder slash input slash
1:04
batch so these batches dot XML is having multiple tags are there and multiple attributes
1:11
are there so let us go for the the content of this batches dot XML so batches is
1:18
one tag under this tag we're having multiple number of rows are there we're having
1:22
ID which we are also having the user ID then name then date then class
1:29
and then tag based this class is having multiple values and three values are
1:33
mainly there three two and one it is a map only job so we are having only one
1:40
class in this case and that is a class is counting MR task and as it is a
1:46
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 a 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 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 objects 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 branch 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 reduced 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 writable and here you are going to take the completion there is a
4:43
status of the completion so whether it is true whether it is zero or one
4:47
depending upon that we can put the respective message and then the system dot exit
4:53
code so in this way the main function the main method has been written here
5:00
the respective number of types we are printing that is how many types of
5:07
this gold this bronze and silver so their respective count will be also printed
5:14
using this for loop so at first we shall go for the creating the jar so we shall go for this
5:23
and then then the respective path name and the file name has to be given already we have
5:28
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
5:43
existing so that is a map produced design pattern jar files so this is a path
5:48
in which the summarization pattern dot jar this jar file will be existing then
5:53
counting counter is the respective the respective package name and under that
6:00
we'll be having counting a M.R. task. So there is a class name. Input slash input slash badge
6:06
is the input file path name and slash output will be the output file path name. So in this way
6:12
we are going to execute our command. So let us execute the comment. We can find here that is
6:22
the bytes written is equal to zero. The bytes written is equal to zero means it is only
6:28
it is a map only job so nothing will be written by the reducer but you'll be getting the
6:33
output in the last three lines there is a number of gold batches 5-2-3-7 number of silver
6:39
batches are given number of bronze batches are given here so you can find that the
6:45
respective batch count we have also got it and we have printed that one because we had
6:50
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
6:59
so here is the output folder and you can find that we are having two part files
7:04
but both of them are having the size of zero bytes two part files are there
7:09
having got the size of zero bytes because nothing has been written onto the
7:12
part files so let us delete them let us delete them so DFS S DFS DFS
7:20
DFS minus R and this is the output path is getting deleted. Thanks for watching
#Programming