Reputation: 341
I use describe formatted table_name
to get the description of the table. I get following result. I want to convert this to json somehow. Any good approach for this? In other words, I want to get my sql table description as json. Not as a table like the one shown in following output.
The output which I want to get should look like :
{
"columns" : {
"id" : "int",
"name": "string"
},
"partition_information": {
"columns" : {
"dt_temp" : "string"
}
},
"Detailed table information" : {
"Database" : "d1",
"owner" : "root",
.
.
.
.
.
}
}
Is there any function or library that will do this for me? Right now, I'm doing this manually using python script, but it is very difficult and messy. I don't expect the exact same output that I mentioned, I'm looking for a way to parse this easily and meaningfully from some python script. Any suggestions?
Upvotes: 2
Views: 1760
Reputation: 38290
DESCRIBE EXTENDED can produce JSON (checked it works fine on Hive 2.1.1):
set hive.ddl.output.format=json;
desc extended table_name;
It produces output like this:
{"columns":[{"name":"id","type":"bigint","comment":"from deserializer"},
{"name":"col1","type":"string","comment":"from deserializer"},
...
Upvotes: 3