MapReduce and Design Patterns - Structured to Hierarchical Pattern Example
2K views
Oct 18, 2024
MapReduce and Design Patterns - Structured to Hierarchical Pattern 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 Structure to Hierarchical Pattern Example
0:05
So, this video will be assisted one practical demonstration for the easy understanding of this concept
0:12
So, this task takes the Posts.xml and also the Comments.xml to create a hierarchical dataset
0:20
So here we are using two XML files. One is the Posts.xml and Comments.coml
0:24
XML and they will be considered and then the output will be in the hierarchical
0:29
data set format so let us go for the practical demonstration for the easy
0:34
understanding of this under data organization pattern we are going to discuss
0:39
structured to hierarchical pattern example in this particular example we are having two XML files users dot XML under the path slash input slash user and
0:50
comments dot XML under the path slash input slash comment and we are finding out that which user has made which comment on certain post so
1:00
slash input slash user we're having users dot XML so this XML file is containing
1:05
user details and if you go for slash input slash comments comments dot XML here
1:11
this XML file is containing comment details so let us show the current content of
1:17
this there are so many records are there but we have just taken some of them for
1:21
your understanding at first we're discussing users dot XML within the user's tag
1:31
we're having multiple row tags are there with multiple attributes so attributes
1:36
are something like your here for each and be row ID reputation we're having
1:41
the creation date display name last access date website URL we're going to
1:47
have location about me views upvotes down votes account ID so these are the attributes are there under the
1:59
row in case of comments dot XML we're having the ID post ID score text creation date
2:06
and also the user ID under each and every row and whole thing is under the comments
2:11
tag so we have discussed what is the users dot XML and comments dot XML let me go
2:17
for the Java program here we're having only one class that is user comment
2:21
higher m r tux dot java it is having the inner class that is our user comment mapper which extends
2:30
mapper so user comments mapper is the inner class which extends mapper and also we are having
2:35
another reducer class here so within that we are having two variables one is the there is the output
2:40
key which is of the type of text and output value which is of the type of text so output key and
2:46
output value we are overriding the map method we're overheading the map method we're overheading the map
2:51
method here so here we having the XML pass that is a hash map object and we are having XML to map one method that method will take one XML as input and returns the hash map object as output which will be instantiating this XML
3:06
parts but defining one variable that is a ID here and from the XML parts from
3:15
the hash map we are trying to get the ID that is a respective tag so ID we are
3:19
putting the value in string ID so if ID is equal to is equal to null then return
3:24
we are not going for the rest part otherwise the output key will be set with xml parts
3:29
dot get ID so the respective ID value will be put in the output key and then the output
3:35
value will be set with the ID value but along with that u plus conceding u as a
3:40
first letter with this ID and we're writing that one temporarily on the context
3:45
that is the output key and output value so key value pair will be written on the
3:49
context dot right so user for user this respective you will be the first character for user the output
4:01
value will have the first character that is you capital u in case of comment
4:05
mapper which is also extending the mapper class we're having two variables
4:10
there that is the output key and output value both of the type text again we're
4:15
having the XML parts that is a hash map object and XML to map is instantiating
4:21
that one so here we're taking this user ID from the hash map we are taking this user ID and that is getting assigned onto the
4:27
string user ID if user ID is equal to null then we're returning the controls
4:33
so this part will remain unexecuted output key dot set XML parse dot get owner user ID
4:39
so that will be kept as a key and in case of value here we are conceding with
4:45
the capital C as a first letter and then value to string to be converted to string
4:49
and that will be kept so add letter C with the comment
4:53
So there we had the user with the later capital you here with the capital C
4:58
We kept everything within the tri-catch block. But having the reduce, that is the way are having the reduce, reducer class has been extended
5:07
We're having one user ID and the comment list. There is an array list there
5:12
User ID has been initialized with null and comment list which is the array list has been made clear at first
5:18
Now we shall go for this this text value values is nothing but one iterative
5:23
object you can find that one will be taking one at a time so if the value dot
5:28
carrot is zero that means if the first character when a user ID is found that
5:32
we remove the letter you and take the ID so we'll be taking the substring from
5:37
position number one to the last during the t and that will initialize
5:41
this user ID and in case of in case of comment the first character is C so
5:47
comment dot list dot add we are taking the first character onwards how fast
5:51
character at the character at the 0th index will be discarded and we'll be doing the
5:55
t and that will that will be added with a comment list So if user ID is not equal to now then we are creating one JSON object and we are putting that one user user ID into
6:07
the JSON object and in case of JSON array we are creating one instance of JSON
6:12
array and JSON array dot put comment list and JSON object dot put comments JSON array and
6:20
then we are again writing onto the context dot write there is a new text
6:24
Jason object to string and null writable.get. So there is a key value will be written on the context
6:32
And here you also have put within the try catch block. So here is the main function
6:41
So just see the usage here. There is a user comment hierarchical MR tax. So that is a class name and then user input
6:50
then comment input the respective to folders user input folder where the XML will
6:56
be deciding comment input folder whether comment will be deciding and also the
7:00
output folder so these three parameters are to be passed so if the argument
7:05
counts is not equal to three that means the wrong argument so we shall not go otherwise we shall go for creating a job instance and job name is get user ID and
7:15
comment in JSON format so job dot set jar by class where mentioned
7:20
the respective class here we're having the multiple inputs so add input path
7:25
job comma there is an argument zero that is a first argument whatever you are passing
7:30
a text input format class and user comment mapper class so these two class we are
7:35
mentioning for the multiple inputs will be taken there and then multiple inputs will be going
7:40
for add input path for the next now going for the set reducer class so reducer class is
7:46
user comment reducer class which you defined earlier so there is arc 0 and arcs 1 will initialize the respective add input path in both cases
8:02
because i'm just marking that one to show you that what are the classes we're using that one
8:06
then we'll be going for job dot set output format we'll be going for job dot set output format class
8:14
there is our text output format class and text text output format dot set output path
8:20
will be job and new path argument too. So that is a third argument, whatever you're passing
8:25
there is an output path we are passing. So job. dot set output key, there is a output key class is text
8:31
dot class and also output value class will be text. Dot class
8:34
Depending upon the system exit, the current condition of the completion, that value will be returned
8:39
either 0 or 1, 0 means success, 1 means failure. Now after creating this Java file
8:45
we shall go for the jar file creation. So we'll be going for the package
8:49
and then we shall go for export then we shall go for the jar file we shall click on the next we shall find out the jar file part and the jar file name then we shall go for next and finish but already we have created such jar file earlier so we are not going to create it once again I just keeping this particular step here so let me go for the command so how do
9:11
jar we're writing hadup then jar then map produce design pattern so there is a
9:19
path jar files is a path and then we're having the data organized pattern
9:25
dot jar so there is a jar file name we mentioned then struct to hire is the
9:30
respective package name then user com hired dot m r tux is a class name so this
9:37
a package and rest one is a class I'm just marking that one for the better
9:41
visualization then input path will be the where the user XML will be there
9:48
users XML there is a slash input slash user and then input XML input XML that is a
9:55
the comments XML so that will be under slash input slash comment and output will be the folder
10:00
I'm executing the command see the outputs it will create the part files and I shall show show you
10:09
the display of the part file content against user ID the comments will be displayed if the comments
10:14
are there so it will display the user ID and the respective comment in the form of a list in the
10:20
part file so part file will be created under the output folder so let me go for the
10:25
cat of that folder that means the content of the folder will be going to display
10:29
so HDFS dFS minus cat and then slash output slash part star so here you can find
10:45
that we're having the list of all user IDs and the respective comments are
10:50
there all user IDs and respective comments where the comments are not there it
10:55
is showing the blank and whenever comments are there it will be showing the respective comment you can find that so many user IDs and the respective
11:01
comments he or she has made on multiple different posts so this is the actual
11:08
the basic theme behind the structure to hierarchical pattern example we have shown
11:13
that one into detail step by step so that you can follow we can pause the video
11:16
and we can get it done so it is our common practice to also to show you that
11:22
this is the user ID and the respective comments will be printed. So each and every row will be user ID and the respect to comments
11:28
Most of the comments are null, some of the comments are also existing
11:32
So let us go for the deletion of the output folder and then you shall conclude
11:41
So the command which will be going to execute is that because the deletion of the output
11:47
command output folder is a common practice in this way. We'll be going for DFS, SDFS, DFS minus R minus R, slash output
11:55
slash yes that is okay now the output folder has got deleted thanks for watching
#Computer Education
#Programming