diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/MetaDataPrettyFormatUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/MetaDataPrettyFormatUtils.java index 8f939e6..c43b648 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/MetaDataPrettyFormatUtils.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/MetaDataPrettyFormatUtils.java @@ -53,7 +53,6 @@ public static String getAllColumnsInformation(List cols, StringBuilder columnInformation = new StringBuilder( MetaDataFormatUtils.DEFAULT_STRINGBUILDER_SIZE); int maxColNameLen = findMaxColumnNameLen(cols); - formatColumnsHeaderPretty(columnInformation, maxColNameLen, prettyOutputNumCols); formatAllFieldsPretty(columnInformation, cols, maxColNameLen, prettyOutputNumCols); if ((partCols != null) && (!partCols.isEmpty())) { @@ -89,7 +88,7 @@ private static void formatColumnsHeaderPretty(StringBuilder columnInformation, String columnHeaders[] = MetaDataFormatUtils.getColumnsHeader(null); formatOutputPretty(columnHeaders[0], columnHeaders[1], columnHeaders[2], columnInformation, maxColNameLen, prettyOutputNumCols); - columnInformation.append(MetaDataFormatUtils.LINE_DELIM); + columnInformation.append(MetaDataFormatUtils.FIELD_DELIM ).append( MetaDataFormatUtils.FIELD_DELIM ).append(MetaDataFormatUtils.LINE_DELIM); } private static void formatAllFieldsPretty(StringBuilder tableInfo, @@ -202,6 +201,7 @@ private static int appendFormattedColumn(StringBuilder sb, String text, String delim = StringUtils.repeat(" ", delimCount); sb.append(paddedText); sb.append(delim); + sb.append(MetaDataFormatUtils.FIELD_DELIM); return paddedText.length() + delim.length(); } @@ -210,8 +210,8 @@ private static void formatOutputPretty(String colName, String colType, String colComment, StringBuilder tableInfo, int maxColNameLength, int prettyOutputNumCols) { int colsConsumed = 0; - colsConsumed += appendFormattedColumn(tableInfo, colName, maxColNameLength + 1); - colsConsumed += appendFormattedColumn(tableInfo, colType, PRETTY_ALIGNMENT); + int colsNameConsumed = appendFormattedColumn(tableInfo, colName, maxColNameLength + 1); + int colsTypeConsumed =appendFormattedColumn(tableInfo, colType, PRETTY_ALIGNMENT); colComment = breakCommentIntoMultipleLines(colComment, colsConsumed, prettyOutputNumCols); @@ -224,9 +224,8 @@ private static void formatOutputPretty(String colName, String colType, tableInfo.append(trimTrailingWS(commentSegments[0])); tableInfo.append(MetaDataFormatUtils.LINE_DELIM); for (int i = 1; i < commentSegments.length; i++) { - tableInfo.append(StringUtils.repeat(" ", colsConsumed)); - tableInfo.append(trimTrailingWS(commentSegments[i])); - tableInfo.append(MetaDataFormatUtils.LINE_DELIM); + tableInfo.append(String.format("%" + colsNameConsumed + "s" + MetaDataFormatUtils.FIELD_DELIM + "%" + + colsTypeConsumed + "s" + MetaDataFormatUtils.FIELD_DELIM + "%s", "", "", commentSegments[i])).append(MetaDataFormatUtils.LINE_DELIM); } } diff --git a/ql/src/test/queries/clientnegative/describe_pretty.q b/ql/src/test/queries/clientnegative/describe_pretty.q new file mode 100644 index 0000000..8d125a0 --- /dev/null +++ b/ql/src/test/queries/clientnegative/describe_pretty.q @@ -0,0 +1,7 @@ +create table pokes(foo int comment 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',bar string comment 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'); + +describe pretty pokes; + +set hive.cli.pretty.output.num.cols=20; + +describe pretty pokes; \ No newline at end of file diff --git a/ql/src/test/results/clientpositive/describe_pretty.q.out b/ql/src/test/results/clientpositive/describe_pretty.q.out index 1c05e0d..f1b097e 100644 --- a/ql/src/test/results/clientpositive/describe_pretty.q.out +++ b/ql/src/test/results/clientpositive/describe_pretty.q.out @@ -72,136 +72,89 @@ POSTHOOK: query: -- There will be an extra tab at the end of each comment line i DESCRIBE PRETTY test_table POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@test_table -col_name data_type comment - -col1 int col1 one line comment -col2 string col2 - two lines comment -col3 string col3 - three lines - comment -col4 string col4 very long comment that is greater than 80 - chars and is likely to spill into multiple - lines -col5 string col5 very long multi-line comment where each - line is very long by itself and is likely to - spill - into multiple lines. Lorem ipsum dolor sit - amet, consectetur adipiscing elit. Proin in - dolor nisl, sodales - adipiscing tortor. Integer venenatis -col6 string This comment has a very long single word ABCDEF - GHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvzxyz12 - 3 which will not fit in a line by itself for - small column widths. -col7_nocomment string +col1 int col1 one line comment +col2 string col2 + two lines comment +col3 string col3 + three lines + comment +col4 string col4 very long comment that is greater than 80 chars and is likely to spill into + multiple lines +col5 string col5 very long multi-line comment where each line is very long by itself and is + likely to spill + into multiple lines. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Proin in dolor nisl, sodales + adipiscing tortor. Integer venenatis +col6 string This comment has a very long single word + ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvzxyz123 which will not fit in a + line by itself for small column widths. +col7_nocomment string PREHOOK: query: DESCRIBE PRETTY test_table PREHOOK: type: DESCTABLE PREHOOK: Input: default@test_table POSTHOOK: query: DESCRIBE PRETTY test_table POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@test_table -col_name data_type comment - -col1 int col1 one line comment -col2 string col2 - two lines comment -col3 string col3 - three lines - comment -col4 string col4 very long comment that is greater than 80 chars and is likely to spill into multiple lines -col5 string col5 very long multi-line comment where each line is very long by itself and is likely to spill - into multiple lines. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin in dolor nisl, sodales - adipiscing tortor. Integer venenatis -col6 string This comment has a very long single word ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvzxyz123 which will not fit in a line by itself for small column widths. -col7_nocomment string +col1 int col1 one line comment +col2 string col2 + two lines comment +col3 string col3 + three lines + comment +col4 string col4 very long comment that is greater than 80 chars and is likely to spill into multiple lines +col5 string col5 very long multi-line comment where each line is very long by itself and is likely to spill + into multiple lines. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin in dolor nisl, sodales + adipiscing tortor. Integer venenatis +col6 string This comment has a very long single word ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvzxyz123 which will not fit in a line by itself for small column widths. +col7_nocomment string PREHOOK: query: DESCRIBE PRETTY test_table PREHOOK: type: DESCTABLE PREHOOK: Input: default@test_table POSTHOOK: query: DESCRIBE PRETTY test_table POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@test_table -col_name data_type comment - -col1 int col1 one line - comment -col2 string col2 - two lines comment -col3 string col3 - three lines - comment -col4 string col4 very long - comment that is - greater than 80 - chars and is - likely to spill - into multiple - lines -col5 string col5 very long - multi-line - comment where - each line is very - long by itself - and is likely to - spill - into multiple - lines. Lorem - ipsum dolor sit - amet, consectetur - adipiscing elit. - Proin in dolor - nisl, sodales - adipiscing - tortor. Integer - venenatis -col6 string This comment has - a very long - single word ABCDE - FGHIJKLMNOPQRSTUV - XYZabcdefghijklmn - opqrstuvzxyz123 - which will not - fit in a line by - itself for small - column widths. -col7_nocomment string +col1 int col1 one line comment +col2 string col2 + two lines comment +col3 string col3 + three lines + comment +col4 string col4 very long comment that is greater than 80 + chars and is likely to spill into multiple lines +col5 string col5 very long multi-line comment where each line + is very long by itself and is likely to spill + into multiple lines. Lorem ipsum dolor sit amet, + consectetur adipiscing elit. Proin in dolor nisl, + sodales + adipiscing tortor. Integer venenatis +col6 string This comment has a very long single word ABCDEFGHI + JKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvzxyz123 + which will not fit in a line by itself for small + column widths. +col7_nocomment string PREHOOK: query: DESCRIBE PRETTY test_table PREHOOK: type: DESCTABLE PREHOOK: Input: default@test_table POSTHOOK: query: DESCRIBE PRETTY test_table POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@test_table -col_name data_type comment - -col1 int col1 one line comment -col2 string col2 - two lines comment -col3 string col3 - three lines - comment -col4 string col4 very long comment that - is greater than 80 chars - and is likely to spill into - multiple lines -col5 string col5 very long multi-line - comment where each line is - very long by itself and is - likely to spill - into multiple lines. Lorem - ipsum dolor sit amet, - consectetur adipiscing - elit. Proin in dolor nisl, - sodales - adipiscing tortor. Integer - venenatis -col6 string This comment has a very - long single word ABCDEFGHIJ - KLMNOPQRSTUVXYZabcdefghijkl - mnopqrstuvzxyz123 which - will not fit in a line by - itself for small column - widths. -col7_nocomment string +col1 int col1 one line comment +col2 string col2 + two lines comment +col3 string col3 + three lines + comment +col4 string col4 very long comment that is greater than 80 chars and is + likely to spill into multiple lines +col5 string col5 very long multi-line comment where each line is very + long by itself and is likely to spill + into multiple lines. Lorem ipsum dolor sit amet, + consectetur adipiscing elit. Proin in dolor nisl, sodales + adipiscing tortor. Integer venenatis +col6 string This comment has a very long single word + ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvzxyz123 which + will not fit in a line by itself for small column widths. +col7_nocomment string PREHOOK: query: CREATE TABLE test_table_very_long_column_name( col1 INT COMMENT 'col1 one line comment', col2_abcdefghiklmnopqrstuvxyz STRING COMMENT 'col2 @@ -230,48 +183,33 @@ PREHOOK: Input: default@test_table_very_long_column_name POSTHOOK: query: DESCRIBE PRETTY test_table_very_long_column_name POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@test_table_very_long_column_name -col_name data_type comment - -col1 int col1 one line comment -col2_abcdefghiklmnopqrstuvxyz string col2 - two lines comment -col3 string col3 - three lines - comment -col4 string col4 very long comment that is - greater than 80 chars and is - likely to spill into multiple - lines +col1 int col1 one line comment +col2_abcdefghiklmnopqrstuvxyz string col2 + two lines comment +col3 string col3 + three lines + comment +col4 string col4 very long comment that is greater than 80 chars and is likely to spill into + multiple lines PREHOOK: query: DESCRIBE PRETTY test_table_very_long_column_name PREHOOK: type: DESCTABLE PREHOOK: Input: default@test_table_very_long_column_name POSTHOOK: query: DESCRIBE PRETTY test_table_very_long_column_name POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@test_table_very_long_column_name -col_name data_type comment - -col1 int col1 one - line - comment -col2_abcdefghiklmnopqrstuvxyz string col2 - two lines - comment -col3 string col3 - three - lines - comment -col4 string col4 very - long - comment - that is - greater - than 80 - chars and - is likely - to spill - into - multiple - lines +col1 int col1 one line + comment +col2_abcdefghiklmnopqrstuvxyz string col2 + two lines comment +col3 string col3 + three lines + comment +col4 string col4 very long + comment that is + greater than 80 + chars and is likely + to spill into + multiple lines PREHOOK: query: CREATE TABLE test_table_partitioned( col1 INT COMMENT 'col1 one line comment', col2 STRING COMMENT 'col2 @@ -316,40 +254,26 @@ PREHOOK: Input: default@test_table_partitioned POSTHOOK: query: DESCRIBE PRETTY test_table_partitioned POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@test_table_partitioned -col_name data_type comment - -col1 int col1 one line comment -col2 string col2 - two lines comment -col3 string col3 - three lines - comment -col4 string col4 very long comment that - is greater than 80 chars - and is likely to spill into - multiple lines -col5 string col5 very long multi-line - comment where each line is - very long by itself and is - likely to spill - into multiple lines. Lorem - ipsum dolor sit amet, - consectetur adipiscing - elit. Proin in dolor nisl, - sodales - adipiscing tortor. Integer - venenatis -col6 string This comment has a very - long single word ABCDEFGHIJ - KLMNOPQRSTUVXYZabcdefghijkl - mnopqrstuvzxyz123 which - will not fit in a line by - itself for small column - widths. -col7_nocomment string -ds string +col1 int col1 one line comment +col2 string col2 + two lines comment +col3 string col3 + three lines + comment +col4 string col4 very long comment that is greater than 80 chars and is + likely to spill into multiple lines +col5 string col5 very long multi-line comment where each line is very + long by itself and is likely to spill + into multiple lines. Lorem ipsum dolor sit amet, + consectetur adipiscing elit. Proin in dolor nisl, sodales + adipiscing tortor. Integer venenatis +col6 string This comment has a very long single word + ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvzxyz123 which + will not fit in a line by itself for small column widths. +col7_nocomment string +ds string # Partition Information -col_name data_type comment - -ds string +col_name data_type comment + +ds string