Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Querying JSON Data in Hive - returning null

avatar
Expert Contributor

Content of stock2.json file

{"myid":"0001","mytype":"donut"}

stock2.json file is in the path of '/warehouse/tablespace/external/hive/haijintest.db/stock2';

Below is the table creation script.

CREATE EXTERNAL TABLE stock4_json (myjson struct<myid:string, mytype:string>)ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe' LOCATION '/warehouse/tablespace/external/hive/haijintest.db/stock2';

Below is the query that returned null value.

0: jdbc:hive2://> select myjson.myid from stock4_json;
19/05/27 20:20:18 [103d2343-eb59-4072-8a07-5469b2112093 main]: WARN optimizer.SimpleFetchOptimizer: Table haijintest@stock4_json is external table, falling back to filesystem scan.
OK
+-------+
| myid  |
+-------+
| NULL  |
+-------+
1 row selected (0.232 seconds)
0: jdbc:hive2://> select * from stock4_json;
OK
+---------------------+
| stock4_json.myjson  |
+---------------------+
| NULL                |
+---------------------+
1 row selected (0.242 seconds)

Any suggestions?

1 ACCEPTED SOLUTION

avatar
Rising Star

Hi @Haijin Li

The input file you are using is incorrect stock2.json

{"myid":"0001","mytype":"donut"}

command is correct

CREATE EXTERNAL TABLE stock4_json (myjson struct<myid:string, mytype:string>)ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe' LOCATION '/warehouse/tablespace/external/hive/haijintest.db/stock2';

myjson struct define it is having further list and map.

You have to place correct input file stock3.json

{"myjson":{"myid":"0001","mytype":"donut"}}

and create table with same command and check.

Let me know if still you are facing issue.


Regards,

Vinay K

View solution in original post

2 REPLIES 2

avatar
Rising Star

Hi @Haijin Li

The input file you are using is incorrect stock2.json

{"myid":"0001","mytype":"donut"}

command is correct

CREATE EXTERNAL TABLE stock4_json (myjson struct<myid:string, mytype:string>)ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe' LOCATION '/warehouse/tablespace/external/hive/haijintest.db/stock2';

myjson struct define it is having further list and map.

You have to place correct input file stock3.json

{"myjson":{"myid":"0001","mytype":"donut"}}

and create table with same command and check.

Let me know if still you are facing issue.


Regards,

Vinay K

avatar
Expert Contributor

@Vinay

Your are right. The issue is resolved.

Thank you!