diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java index d36d24d090..41ab5c1f48 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java @@ -903,6 +903,19 @@ private static void checkColumnName(String columnName) throws SemanticException } /** + * The comment of field or table should not contain tab character, + * or the output result of command desc formatted/extended is not normal! + * @param comment + * @throws SemanticException + */ + public static void checkComment(String comment) throws SemanticException { + if (comment != null && comment.contains("\t")) { + throw new SemanticException(ErrorMsg.GENERIC_ERROR.getMsg( + "The comment string of field or table should not contain tab character.")); + } + } + + /** * Get the list of FieldSchema out of the ASTNode. * Additionally, populate the primaryKeys and foreignKeys if any. */ @@ -955,10 +968,12 @@ private static void checkColumnName(String columnName) throws SemanticException ASTNode constraintChild = null; if (child.getChildCount() == 4) { col.setComment(unescapeSQLString(child.getChild(2).getText())); + checkComment(col.getComment()); constraintChild = (ASTNode) child.getChild(3); } else if (child.getChildCount() == 3 && ((ASTNode) child.getChild(2)).getToken().getType() == HiveParser.StringLiteral) { col.setComment(unescapeSQLString(child.getChild(2).getText())); + checkComment(col.getComment()); } else if (child.getChildCount() == 3) { constraintChild = (ASTNode) child.getChild(2); } diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java index a09b7961c2..5e6970e924 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java @@ -3186,6 +3186,7 @@ private void analyzeAlterTableRenameCol(String[] qualified, ASTNode ast, switch (child.getToken().getType()) { case HiveParser.StringLiteral: newComment = unescapeSQLString(child.getText()); + checkComment(newComment); break; case HiveParser.TOK_ALTERTABLE_CHANGECOL_AFTER_POSITION: flagCol = unescapeIdentifier(child.getChild(0).getText()); diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 28e3621d32..00aba046e4 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -12380,6 +12380,7 @@ ASTNode analyzeCreateTable( break; case HiveParser.TOK_TABLECOMMENT: comment = unescapeSQLString(child.getChild(0).getText()); + checkComment(comment); break; case HiveParser.TOK_TABLEPARTCOLS: partCols = getColumns(child, false, primaryKeys, foreignKeys, @@ -12663,6 +12664,7 @@ protected ASTNode analyzeCreateView(ASTNode ast, QB qb, PlannerContext plannerCt break; case HiveParser.TOK_TABLECOMMENT: comment = unescapeSQLString(child.getChild(0).getText()); + checkComment(comment); break; case HiveParser.TOK_TABLEPROPERTIES: tblProps = DDLSemanticAnalyzer.getProps((ASTNode) child.getChild(0)); diff --git ql/src/test/queries/clientnegative/column_rename6.q ql/src/test/queries/clientnegative/column_rename6.q new file mode 100644 index 0000000000..73b88578c8 --- /dev/null +++ ql/src/test/queries/clientnegative/column_rename6.q @@ -0,0 +1,2 @@ +create table testsrc like src; +alter table testsrc change key key string comment 'full\tname'; \ No newline at end of file diff --git ql/src/test/queries/clientnegative/create_table_failure5.q ql/src/test/queries/clientnegative/create_table_failure5.q new file mode 100644 index 0000000000..895379c5e3 --- /dev/null +++ ql/src/test/queries/clientnegative/create_table_failure5.q @@ -0,0 +1,4 @@ +create table test_comment( + id1 int comment 'full\tname_id1', + id2 int comment 'full\tname_id2', + id3 int comment 'full\tname_id3'); \ No newline at end of file diff --git ql/src/test/queries/clientnegative/create_table_failure6.q ql/src/test/queries/clientnegative/create_table_failure6.q new file mode 100644 index 0000000000..6334000554 --- /dev/null +++ ql/src/test/queries/clientnegative/create_table_failure6.q @@ -0,0 +1 @@ +create table test_comment(id1 int, id2 int, id3 int) comment 'full\tname_test_comment'; \ No newline at end of file diff --git ql/src/test/queries/clientnegative/create_table_failure7.q ql/src/test/queries/clientnegative/create_table_failure7.q new file mode 100644 index 0000000000..5facc0c99a --- /dev/null +++ ql/src/test/queries/clientnegative/create_table_failure7.q @@ -0,0 +1 @@ +create table test_comment(id int) partitioned by(dt string comment 'partition\tstring'); \ No newline at end of file diff --git ql/src/test/results/clientnegative/column_rename6.q.out ql/src/test/results/clientnegative/column_rename6.q.out new file mode 100644 index 0000000000..a8898fa758 --- /dev/null +++ ql/src/test/results/clientnegative/column_rename6.q.out @@ -0,0 +1,9 @@ +PREHOOK: query: create table testsrc like src +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@testsrc +POSTHOOK: query: create table testsrc like src +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@testsrc +FAILED: SemanticException Exception while processing The comment string of field or table should not contain tab character. diff --git ql/src/test/results/clientnegative/create_table_failure5.q.out ql/src/test/results/clientnegative/create_table_failure5.q.out new file mode 100644 index 0000000000..8716479b97 --- /dev/null +++ ql/src/test/results/clientnegative/create_table_failure5.q.out @@ -0,0 +1 @@ +FAILED: SemanticException Exception while processing The comment string of field or table should not contain tab character. diff --git ql/src/test/results/clientnegative/create_table_failure6.q.out ql/src/test/results/clientnegative/create_table_failure6.q.out new file mode 100644 index 0000000000..8716479b97 --- /dev/null +++ ql/src/test/results/clientnegative/create_table_failure6.q.out @@ -0,0 +1 @@ +FAILED: SemanticException Exception while processing The comment string of field or table should not contain tab character. diff --git ql/src/test/results/clientnegative/create_table_failure7.q.out ql/src/test/results/clientnegative/create_table_failure7.q.out new file mode 100644 index 0000000000..8716479b97 --- /dev/null +++ ql/src/test/results/clientnegative/create_table_failure7.q.out @@ -0,0 +1 @@ +FAILED: SemanticException Exception while processing The comment string of field or table should not contain tab character.