Is there any way to convert the Hive query result in JSON format?
To directly save the file in HDFS, use the below command: hive> insert overwrite directory '/user/cloudera/Sample' row format delimited fields terminated by '\t' stored as textfile select * from table where id >100; This will put the contents in the folder /user/cloudera/Sample in HDFS. Show activity on this post.
JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa).
Hive provides three different mechanisms to run queries on JSON documents, or you can write your own: Use the get_json_object user-defined function (UDF). Use the json_tuple UDF. Use the custom Serializer/Deserializer (SerDe).
This seems to come up quite often. Use the to_json UDFs' from Brickhouse (http://github.com/klout/brickhouse ). If you convert your results to a named_struct, it will interpret it as a JSON map, and output accordingly.
SELECT to_json( named_struct( "field1", field1 , "field2", field2, "field3", field3 ) ) FROM mytable;
The to_json will also interpret arrays and maps accordingly.
I was using a tool called Apache Nifi. It has AvrotoJSON processor. The hive output which is in Avro format can be easily converted to JSON. The below link will be helpful: https://nifi.apache.org/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With