Index: ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (revision 1000539) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (revision ) @@ -1613,26 +1613,74 @@ DataOutput outStream = fs.create(resFile); if (colPath.equals(tableName)) { + if (!descTbl.isFormatted()) { + Iterator iterCols = tbl.getCols().iterator(); + while (iterCols.hasNext()) { + // create a row per column + FieldSchema col = iterCols.next(); + outStream.writeBytes(col.getName()); + outStream.write(separator); + outStream.writeBytes(col.getType()); + outStream.write(separator); + outStream.writeBytes(col.getComment() == null ? "" : col.getComment()); + outStream.write(terminator); + } + } else { - outStream.writeBytes(MetaDataFormatUtils.getAllColumnsInformation(tbl)); + outStream.writeBytes(MetaDataFormatUtils.getAllColumnsInformation(tbl)); + } } else { - List cols = null; + List cols = null; cols = Hive.getFieldsFromDeserializer(colPath, tbl.getDeserializer()); + if (descTbl.isFormatted()) { - outStream.writeBytes(MetaDataFormatUtils.getAllColumnsInformation(cols)); + outStream.writeBytes(MetaDataFormatUtils.getAllColumnsInformation(cols)); + } else { + Iterator iterCols = cols.iterator(); + while (iterCols.hasNext()) { + // create a row per column + FieldSchema col = iterCols.next(); + outStream.writeBytes(col.getName()); + outStream.write(separator); + outStream.writeBytes(col.getType()); + outStream.write(separator); + outStream.writeBytes(col.getComment() == null ? "" : col.getComment()); + outStream.write(terminator); - } + } + } + } if (tableName.equals(colPath)) { + + if (descTbl.isFormatted()) { + // add empty line + outStream.write(terminator); + if (part != null) { + outStream.writeBytes(MetaDataFormatUtils.getPartitionInformation(part)); + outStream.write(terminator); + } else { + // show table information + outStream.writeBytes(MetaDataFormatUtils.getTableInformation(tbl)); + outStream.write(terminator); + } + } + // if extended desc table then show the complete details of the table if (descTbl.isExt()) { // add empty line outStream.write(terminator); if (part != null) { // show partition information - outStream.writeBytes(MetaDataFormatUtils.getPartitionInformation(part)); + outStream.writeBytes("Detailed Partition Information"); + outStream.write(separator); + outStream.writeBytes(part.getTPartition().toString()); + outStream.write(separator); // comment column is empty outStream.write(terminator); } else { // show table information - outStream.writeBytes(MetaDataFormatUtils.getTableInformation(tbl)); + outStream.writeBytes("Detailed Table Information"); + outStream.write(separator); + outStream.writeBytes(tbl.getTTable().toString()); + outStream.write(separator); outStream.write(terminator); } } Index: ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (revision 999101) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (revision ) @@ -787,9 +787,15 @@ partSpec = getPartSpec(partspec); } - boolean isExt = ast.getChildCount() > 1; - DescTableDesc descTblDesc = new DescTableDesc(ctx.getResFile(), tableName, - partSpec, isExt); + DescTableDesc descTblDesc = new DescTableDesc(ctx.getResFile(), tableName, partSpec); + if (ast.getChildCount() > 1) { + int descOptions = ast.getChild(1).getType(); + if (descOptions == HiveParser.KW_FORMATTED) { + descTblDesc.setFormatted(true); + } else { + descTblDesc.setExt(true); + } + } rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), descTblDesc), conf)); setFetchTask(createFetchTask(DescTableDesc.getSchema())); Index: ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (revision 1001825) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (revision ) @@ -620,7 +620,7 @@ descStatement @init { msgs.push("describe statement"); } @after { msgs.pop(); } - : (KW_DESCRIBE|KW_DESC) (isExtended=KW_EXTENDED)? (parttype=partTypeExpr) -> ^(TOK_DESCTABLE $parttype $isExtended?) + : (KW_DESCRIBE|KW_DESC) (isExtended=KW_FORMATTED|isExtended=KW_EXTENDED)? (parttype=partTypeExpr) -> ^(TOK_DESCTABLE $parttype $isExtended?) | (KW_DESCRIBE|KW_DESC) KW_FUNCTION KW_EXTENDED? (name=descFuncNames) -> ^(TOK_DESCFUNCTION $name KW_EXTENDED?) ; @@ -1813,6 +1813,7 @@ KW_FUNCTION: 'FUNCTION'; KW_EXPLAIN: 'EXPLAIN'; KW_EXTENDED: 'EXTENDED'; +KW_FORMATTED: 'FORMATTED'; KW_SERDE: 'SERDE'; KW_WITH: 'WITH'; KW_DEFERRED: 'DEFERRED'; Index: ql/src/java/org/apache/hadoop/hive/ql/plan/DescTableDesc.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/plan/DescTableDesc.java (revision 999101) +++ ql/src/java/org/apache/hadoop/hive/ql/plan/DescTableDesc.java (revision ) @@ -39,6 +39,7 @@ HashMap partSpec; String resFile; boolean isExt; + boolean isFormatted; /** * table name for the result of describe table. */ @@ -52,14 +53,14 @@ } /** - * @param isExt * @param partSpec * @param resFile * @param tableName */ public DescTableDesc(Path resFile, String tableName, - HashMap partSpec, boolean isExt) { - this.isExt = isExt; + HashMap partSpec) { + this.isExt = false; + this.isFormatted = false; this.partSpec = partSpec; this.resFile = resFile.toString(); this.tableName = tableName; @@ -88,7 +89,22 @@ this.isExt = isExt; } - /** + /** + * @return the isFormatted + */ + public boolean isFormatted() { + return isFormatted; + } + + /** + * @param isFormatted + * the isFormat to set + */ + public void setFormatted(boolean isFormat) { + this.isFormatted = isFormat; + } + + /** * @return the tableName */ @Explain(displayName = "table")