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));