[
https://issues.apache.org/jira/browse/HIVE-14146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15400036#comment-15400036
]
Peter Vary commented on HIVE-14146:
-----------------------------------
[~aihuaxu] Checked, and found the following:
- Beeline - when using "describe pretty" the \n is padded and displayed - this
is as intended - the original behavior is not changed
- Cli - when using "describe pretty" the \n is padded and displayed - this is
as intended - the original behavior is not changed
What I have missed, that in Cli when using "describe formatted" the following
code sets the output to padded:
{noformat}
package org.apache.hadoop.hive.ql.exec;
[..]
public class DDLTask extends Task<DDLWork> implements Serializable {
[..]
private int describeTable(Hive db, DescTableDesc descTbl) throws
HiveException {
[..]
// In case the query is served by HiveServer2, don't pad it with spaces,
// as HiveServer2 output is consumed by JDBC/ODBC clients.
boolean isOutputPadded = !SessionState.get().isHiveServerQuery();
{noformat}
So the column comments are printed as a formatted strings with new lines - but
not the table comment. (same as in pretty mode)
What do you think we should do here?
I personally would prefer to remove this code below (pretty comment
formatting), so every comment should be handled in the same way (printing \n
instead of newline):
{noformat}
package org.apache.hadoop.hive.ql.metadata.formatting;
[..]
public final class MetaDataFormatUtils {
[..]
private static void formatWithIndentation(String colName, String colType,
String colComment,
[..]
// 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
String[] commentSegments = colComment.split("\n|\r|\r\n");
tableInfo.append(String.format("%-" + ALIGNMENT + "s",
commentSegments[0])).append(LINE_DELIM);
int colNameLength = ALIGNMENT > colName.length() ? ALIGNMENT :
colName.length();
int colTypeLength = ALIGNMENT > colType.length() ? ALIGNMENT :
colType.length();
for (int i = 1; i < commentSegments.length; i++) {
tableInfo.append(String.format("%" + colNameLength + "s" + FIELD_DELIM +
"%"
+ colTypeLength + "s" + FIELD_DELIM + "%s", "", "",
commentSegments[i])).append(LINE_DELIM);
}
{noformat}
> Column comments with "\n" character "corrupts" table metadata
> -------------------------------------------------------------
>
> Key: HIVE-14146
> URL: https://issues.apache.org/jira/browse/HIVE-14146
> Project: Hive
> Issue Type: Bug
> Components: Beeline
> Affects Versions: 2.2.0
> Reporter: Peter Vary
> Assignee: Peter Vary
> Attachments: HIVE-14146.2.patch, HIVE-14146.3.patch,
> HIVE-14146.4.patch, HIVE-14146.5.patch, HIVE-14146.6.patch, HIVE-14146.patch
>
>
> Create a table with the following(noting the \n in the COMMENT):
> {noformat}
> CREATE TABLE commtest(first_nm string COMMENT 'Indicates First name\nof an
> individual’);
> {noformat}
> Describe shows that now the metadata is messed up:
> {noformat}
> beeline> describe commtest;
> +-------------------+------------+-----------------------+--+
> | col_name | data_type | comment |
> +-------------------+------------+-----------------------+--+
> | first_nm | string | Indicates First name |
> | of an individual | NULL | NULL |
> +-------------------+------------+-----------------------+--+
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)