Skip to content

Instantly share code, notes, and snippets.

@milindjagre
Created May 9, 2016 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milindjagre/6e6991a141ac0b52b13e5dc26405a53a to your computer and use it in GitHub Desktop.
Save milindjagre/6e6991a141ac0b52b13e5dc26405a53a to your computer and use it in GitHub Desktop.
STEP 1 : CREATING INPUT XML FILE WHICH WE WILL LOAD IN HIVE TABLE
nano student.xml
<student> <id>1</id> <name>Milind</name> <age>25</age> </student>
<student> <id>2</id> <name>Ramesh</name> <age>Testing</age> </student>
STEP 2 : LOG IN TO HIVE
hive
STEP 3 : CREATING HIVE TABLE
create table student_xml( studinfo string) ;
STEP 4 : LOADING DATA INTO HIVE TABLE
load data local inpath '/home/hduser/student.xml' into table student_xml;
STEP 5 : QUERYING THE LOADED DATA
select * from student_xml;
STEP 6 : CREATING A VIEW ON TOP OF NEWLY CREATED HIVE TABLE FOR GETTING NEWLY ADDED RECORDS
create view student_xml_view as SELECT xpath_int(studinfo ,'student/id'),xpath_string(studinfo ,'student/name'),xpath_string(studinfo ,'student/age') FROM student_xml;
STEP 7 : QUERYING THE CREATED VIEW
select * from student_xml_view;
STEP 8 : ADDING ONE MORE FILE TO CHECK VIEW FUNCTIONALITY
load data local inpath '/home/hduser/student.xml' into table student_xml;
STEP 9 : QUERYING VIEW FOR INCREMENTAL RECORDS
select * from student_xml_view;
@milindjagre
Copy link
Author

This is a text file which contains all the commands that I ran while loading XML file into Hive Table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment