Repository: hive Updated Branches: refs/heads/beeline-cli 6e3b17368 -> 4a91efc3c
HIVE-11779 Beeline-cli: Format the output of describe pretty table command in new CLI[beeline-cli branch](Ke Jia, reviewed by Ferdinand Xu) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/4a91efc3 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/4a91efc3 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/4a91efc3 Branch: refs/heads/beeline-cli Commit: 4a91efc3c4b0d05b8f333049e0b0e0c1a5517bc3 Parents: 6e3b173 Author: Jia Ke <ke.a....@intel.com> Authored: Thu Sep 17 01:50:13 2015 -0400 Committer: Ferdinand Xu <cheng.a...@intel.com> Committed: Thu Sep 17 01:50:13 2015 -0400 ---------------------------------------------------------------------- .../formatting/MetaDataPrettyFormatUtils.java | 24 +- .../clientpositive/describe_pretty.q.out | 366 +++++++++---------- 2 files changed, 199 insertions(+), 191 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/4a91efc3/ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/MetaDataPrettyFormatUtils.java ---------------------------------------------------------------------- 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..c653252 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 @@ -89,7 +89,8 @@ public final class MetaDataPrettyFormatUtils { 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 +203,7 @@ public final class MetaDataPrettyFormatUtils { String delim = StringUtils.repeat(" ", delimCount); sb.append(paddedText); sb.append(delim); + sb.append(MetaDataFormatUtils.FIELD_DELIM); return paddedText.length() + delim.length(); } @@ -209,23 +211,29 @@ public final class MetaDataPrettyFormatUtils { 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); + colComment = breakCommentIntoMultipleLines(colComment, colsNameConsumed + colsTypeConsumed, + prettyOutputNumCols); /* Comment indent processing for multi-line comments. * Comments should be indented the same amount on each line * if the first line comment starts indented by k, - * the following line comments should also be indented by k. + * the following line comments should also be indented by k + * The following line comments will as a new line,so we need to + * add colsNameConsumed spaces as the first column and + * colsTypeConsumed spaces as the second column and the + * comment as the last column.we use two FIELD_DELIM to + * split them. */ String[] commentSegments = colComment.split("\n|\r|\r\n"); 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(String.format( + "%" + colsNameConsumed + "s" + MetaDataFormatUtils.FIELD_DELIM + "%" + colsTypeConsumed + + "s" + MetaDataFormatUtils.FIELD_DELIM + "%s", "", "", commentSegments[i])); tableInfo.append(MetaDataFormatUtils.LINE_DELIM); } } http://git-wip-us.apache.org/repos/asf/hive/blob/4a91efc3/ql/src/test/results/clientpositive/describe_pretty.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientpositive/describe_pretty.q.out b/ql/src/test/results/clientpositive/describe_pretty.q.out index 1c05e0d..279f567 100644 --- a/ql/src/test/results/clientpositive/describe_pretty.q.out +++ b/ql/src/test/results/clientpositive/describe_pretty.q.out @@ -72,136 +72,136 @@ 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 +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 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 +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 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 +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 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 +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 PREHOOK: query: CREATE TABLE test_table_very_long_column_name( col1 INT COMMENT 'col1 one line comment', col2_abcdefghiklmnopqrstuvxyz STRING COMMENT 'col2 @@ -230,48 +230,48 @@ 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 +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 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 +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 PREHOOK: query: CREATE TABLE test_table_partitioned( col1 INT COMMENT 'col1 one line comment', col2 STRING COMMENT 'col2 @@ -316,40 +316,40 @@ 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 +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 # Partition Information -col_name data_type comment - -ds string +col_name data_type comment + +ds string