Step 1: Add the resources
ADD JAR /home/hadoop/work/hive-0.10.0/lib/hive-contrib-0.10.0.jar;
ADD JAR /home/hadoop/work/hive-0.10.0/lib/hive-metastore-0.10.0.jar;
ADD JAR /home/hadoop/work/JSON-Serde.jar;
Step 2: Create the table
CREATE TABLE record (
id INT,
city_code ARRAY<INT>,
email STRING,
contact STRUCT<Mobile_no:STRING, Telephone_no:STRING>
) ROW FORMAT SERDE 'org.JSONSerDe';
Step 3: Load the data
@Data looks like
{ "id": 1, "city_code": [ 1, 2, 3 ], "email": "joseph@gmail.com", "contact": { "Mobile_no": "val1", "Telephone_no": "val2" } }
{ "id": 2, "city_code": [ 4, 5, 6 ], "email": "james@gmail.com", "contact": { "Mobile_no": "val3", "Telephone_no": "val4" } }
{ "id": 3, "city_code": [ 7, 8, 9 ], "email": "rony@gmail.com", "contact": { "Mobile_no": "val5", "Telephone_no": "val6" } }
Load data local inpath '/home/hadoop/work/record_data.txt' OVERWRITE INTO TABLE record;
Step 4 Retrieve the data
select * from record;
select contact.Mobile_no from record where id = 1;
Note: You can find the JsonSeDe jar from here https://github.com/cloudera/cdh-twitter-example/blob/master/hive-serdes/src/main/java/com/cloudera/hive/serde/JSONSerDe.java
This article provides a practical example of processing JSON data in Apache Hive using a custom SerDe, complex data types, and HiveQL queries. The demonstration of handling arrays and nested structures, such as contact details, is particularly useful for understanding how semi-structured data can be stored and queried in a Hadoop environment.
ReplyDeleteWorking with JSON files in Hive helps learners understand data ingestion, schema definition, and querying techniques used in big data applications. Exploring Big Data Projects can provide opportunities to apply these concepts to practical data processing challenges.
JSON processing is also relevant to data science workflows, where structured and semi-structured datasets are prepared for analysis and machine learning. Students looking for hands-on experience can explore Data Science Projects for Final Year to understand how data engineering and analytical techniques work together.
ReplyDelete