Step 1 :-
Json file
{
"Foo": "ABC",
"Bar": "20090101100000",
"Quux": {
"QuuxId": 1234,
"QuuxName": "Sam"
}
}
Step 2 :-
Create Table
CREATE TABLE json_table ( json string
);
Step 3 :-
Upload data into hive table
LOAD DATA LOCAL INPATH '/tmp/example.json' INTO TABLE `json_table`;
Step 4 :-
Retrieve data
select
get_json_object(json_table.json,
'$'
)
from
json_table;
Step 5 :-
Retrieve Nested data
select
get_json_object(json_table.json,
'$.Foo'
)
as
foo,
get_json_object(json_table.json,
'$.Bar'
)
as
bar,
get_json_object(json_table.json,
'$.Quux.QuuxId'
)
as
qid,
get_json_object(json_table.json,
'$.Quux.QuuxName'
)
as
qname
from
json_table;
No comments:
Post a Comment