Working with Semi structured data using Hive (XML, JSON)
Hive performs ETL functionalities in Hadoop ecosystem by acting as ETL tool. It can be difficult to perform map reduce in some type of applications, Hive can reduce the complexity and provides the best solution to the IT applications in terms of data warehousing sector.
Semi structured data such as XML and JSON can be processed with less complexity using Hive. First we will see how we can use Hive for XML.
XML TO HIVE TABLE
In this, we are going to load XML data into Hive tables, and we will fetch the values stored inside the XML tags.
Step 1) Creation of Table "xmlsample_manma" with str column with string data type.
create table xmlsample_manma(str string);
Loading data from test.xml into table xmlsample_manma
load data local inpath '/path_address/test.xml' into table xmlsample_manma;
Step 2) UsingXPath() method we will be able to fetch the data stored inside XML tags
We can observe the following
Using XPATH( ) method we are fetching the values stored under /emp/esal/ and /emp/ename/
Values present Inside XML tags. In this step, we are displaying actual values stored under XML tags in table "xmlsample_manma"
select xpath(str,'/emp/esal/text()'), xpath(str,'/emp/ename/text()') from xmlsample_manma;
Step 3) In this step, we will fetch and display the Raw XML of table "xmlsample_manma."
select * from xmlsample_manma;
ok
<emp><ename>Ram</ename><esal>340000</esal></emp>
<emp><ename>Kiran</ename><esal>510000</esal></emp>
<emp><ename>Rajesh</ename><esal>440000</esal></emp>
<emp><ename>Varun</ename><esal>540000</esal></emp>
<emp><ename>Santosh</ename><esal>350000</esal></emp>
<emp><ename>Ramya</ename><esal>420000</esal></emp>
<emp><ename>Sravani</ename><esal>398000</esal></emp>
<emp><ename>Pramod</ename><esal>480000</esal></emp>
JSON (JavaScript Object Notation)
Some websites data is stored in JSON format. Whenever we try to fetch data from online servers it will return JSON files. Using Hive as data store we can able to load JSON data into Hive tables by creating schemas.
JSON TO HIVE TABLE
In this, we are going to load JSON data into Hive tables, and we will fetch the values stored in JSON schema.
Step 1) In this step, we are going to create JSON table name "complexjson_manma". Once created loading and displaying contents of the actual schema.
create table complexjson_manma(str string);
Loading data from test.json into table complexjson_manma
load data local inpath '/path_address/test.json' into table complexjson_manma;
Step 2) Using get_json_object() Method we can able to fetch the Data values stored in JSON hierarchy
We can observe the following
Using get_json_object(str,'$.ecode) it can fetch ecode values from table json_guru. Similarly using get_json_object(str,'$.b) ,get_json_object(str,'$.c) it will fetch b, c values from table json_guru
Values stored inside of JSON Hierarchy in complexjson_manma
select get_json_object(str,'$.ecode) as ecode, get_json_object(str,'$.b) as code, get_json_object(str,'$.c) as salary from complexjson_manma;
100 {"x":10,"y":20} 200
200 {"x":20,"y":30} 300
400 {"x":50,"y":40} 400
Step 3) In this step, we will fetch and display the Raw XML of table "xmlsample_manma."
select * from complexjson_manma;
ok
{"ecode":100,"b":{"x":10,"y":20},"c":200}
{"ecode":200,"b":{"x":20,"y":30},"c":300}
{"ecode":400,"b":{"x":50,"y":40},"c":400}
Hive performs ETL functionalities in Hadoop ecosystem by acting as ETL tool. It can be difficult to perform map reduce in some type of applications, Hive can reduce the complexity and provides the best solution to the IT applications in terms of data warehousing sector.
Semi structured data such as XML and JSON can be processed with less complexity using Hive. First we will see how we can use Hive for XML.
XML TO HIVE TABLE
In this, we are going to load XML data into Hive tables, and we will fetch the values stored inside the XML tags.
Step 1) Creation of Table "xmlsample_manma" with str column with string data type.
create table xmlsample_manma(str string);
Loading data from test.xml into table xmlsample_manma
load data local inpath '/path_address/test.xml' into table xmlsample_manma;
Step 2) UsingXPath() method we will be able to fetch the data stored inside XML tags
We can observe the following
Using XPATH( ) method we are fetching the values stored under /emp/esal/ and /emp/ename/
Values present Inside XML tags. In this step, we are displaying actual values stored under XML tags in table "xmlsample_manma"
select xpath(str,'/emp/esal/text()'), xpath(str,'/emp/ename/text()') from xmlsample_manma;
Step 3) In this step, we will fetch and display the Raw XML of table "xmlsample_manma."
select * from xmlsample_manma;
ok
<emp><ename>Ram</ename><esal>340000</esal></emp>
<emp><ename>Kiran</ename><esal>510000</esal></emp>
<emp><ename>Rajesh</ename><esal>440000</esal></emp>
<emp><ename>Varun</ename><esal>540000</esal></emp>
<emp><ename>Santosh</ename><esal>350000</esal></emp>
<emp><ename>Ramya</ename><esal>420000</esal></emp>
<emp><ename>Sravani</ename><esal>398000</esal></emp>
<emp><ename>Pramod</ename><esal>480000</esal></emp>
JSON (JavaScript Object Notation)
Some websites data is stored in JSON format. Whenever we try to fetch data from online servers it will return JSON files. Using Hive as data store we can able to load JSON data into Hive tables by creating schemas.
JSON TO HIVE TABLE
In this, we are going to load JSON data into Hive tables, and we will fetch the values stored in JSON schema.
Step 1) In this step, we are going to create JSON table name "complexjson_manma". Once created loading and displaying contents of the actual schema.
create table complexjson_manma(str string);
Loading data from test.json into table complexjson_manma
load data local inpath '/path_address/test.json' into table complexjson_manma;
Step 2) Using get_json_object() Method we can able to fetch the Data values stored in JSON hierarchy
We can observe the following
Using get_json_object(str,'$.ecode) it can fetch ecode values from table json_guru. Similarly using get_json_object(str,'$.b) ,get_json_object(str,'$.c) it will fetch b, c values from table json_guru
Values stored inside of JSON Hierarchy in complexjson_manma
select get_json_object(str,'$.ecode) as ecode, get_json_object(str,'$.b) as code, get_json_object(str,'$.c) as salary from complexjson_manma;
100 {"x":10,"y":20} 200
200 {"x":20,"y":30} 300
400 {"x":50,"y":40} 400
Step 3) In this step, we will fetch and display the Raw XML of table "xmlsample_manma."
select * from complexjson_manma;
ok
{"ecode":100,"b":{"x":10,"y":20},"c":200}
{"ecode":200,"b":{"x":20,"y":30},"c":300}
{"ecode":400,"b":{"x":50,"y":40},"c":400}
There are some natural remedies that can be used in the prevention and elimination of diabetes totally. However, the single most important aspect of a diabetes control plan is adopting a wholesome lifestyle Inner Peace, Nutritious and Healthy Diet, and Regular Physical Exercise. A state of inner peace and self-contentment is essential to enjoying a good physical health and overall well-being. The inner peace and self contentment is a just a state of mind.People with diabetes diseases often use complementary and alternative medicine. I was diagnosed with diabetes .It was at work and feeling unusually tired and sleepy. I borrowed a cyclometer from a co-worker and tested at 760. Went immediately to my doctor and he gave me prescriptions like: Insulin ,Sulfonamides,Thiazolidinediones but Could not get the cure rather to reduce the pain but bring back the pain again. i found a woman testimony name Comfort online how Dr Akhigbe cure her HIV and I also contacted the doctor and after I took his medication as instructed, I am now completely free from diabetes by doctor Akhigbe herbal medicine.So diabetes patients reading this testimony to contact his email drrealakhigbe@gmail.com or his Number +234 802 501 2866 He also use his herbal herbs to diseases like:SPIDER BITE, SCHIZOPHRENIA, LUPUS,EXTERNAL INFECTION, COMMON COLD, JOINT PAIN, EPILEPSY,STROKE,TUBERCULOSIS ,STOMACH DISEASE. ECZEMA, GOUT, PROGENITOR, EATING DISORDER, LOWER RESPIRATORY INFECTION, DIABETICS,HERPES,HIV/AIDS, ;ALS, CANCER , TUMOR, HEART HEALTH, MENINGITIS,HEPATITIS A AND B,ASTHMA, HEART DISEASE, CHRONIC DISEASE. NAUSEA VOMITING OR DIARRHEA,KIDNEY DISEASE. HEARING LOSSDr Akhigbe is a good man and he heal anybody that comes to him. here is email drrealakhigbe@gmail.com and his Number +234 901 075 4824
ReplyDelete