3
votes

Is there any way to run "describe extended table" in Hive and have the results returned in JSON, XML, or some easily parsed format? Or is there an existing parse in Java that can parse this type of format?

Table(tableName:test3, dbName:testdatabase, owner:johnsmith, createTime:1481135997, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:string, comment:""a,m)], location:hdfs://testcluster/apps/hive/warehouse/testdatabase/test3, inputFormat:org.apache.hadoop.hive.ql.io.orc.OrcInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.ql.io.orc.OrcSerde, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}, skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[], skewedColValueLocationMaps:{}), storedAsSubDirectories:false), partitionKeys:[], parameters:{totalSize=0, numRows=0, rawDataSize=0, COLUMN_STATS_ACCURATE={"BASIC_STATS":"true"}, numFiles=0, transient_lastDdlTime=1481135997}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE)

2
For humans, SHOW CREATE TABLE is way more readable (IMHHO - in my humble human opinion) - Samson Scharfrichter
And if you really want to access the raw information in Java, try the Metastore API -- poorly documented but taps into the real thing hive.apache.org/javadocs/r1.1.1/api/org/apache/hadoop/hive/… (adjust to the actual Hive version you are using) - Samson Scharfrichter
Another option is to access the Metastore (!) that is also SQL... But it is possible with beeline? - Peter Krauss

2 Answers

2
votes

DESCRIBE FORMATTED my_table; is more friendly
not json or xml.. but more readable than DESCRIBE EXTENDED my_table;

2
votes

Maybe you can use hive.ddl.output.format to format output

set hive.ddl.output.format=json;
desc extended table;