Repository: hive Updated Branches: refs/heads/master b6e39c9e8 -> 445b79153
HIVE-16163: Remove unnecessary parentheses in HiveParser (Pengcheng Xiong, reviewed by Ashutosh Chauhan) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/445b7915 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/445b7915 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/445b7915 Branch: refs/heads/master Commit: 445b79153c7b927c2f46f962512a5dc775689ec8 Parents: b6e39c9 Author: Pengcheng Xiong <[email protected]> Authored: Tue Mar 14 10:41:40 2017 -0700 Committer: Pengcheng Xiong <[email protected]> Committed: Tue Mar 14 10:41:40 2017 -0700 ---------------------------------------------------------------------- .../hive/ql/parse/BaseSemanticAnalyzer.java | 38 ++++++++++---------- .../apache/hadoop/hive/ql/parse/HiveParser.g | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/445b7915/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java index 36009bf..f762fee 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java @@ -651,22 +651,22 @@ public abstract class BaseSemanticAnalyzer { */ private static void processPrimaryKeyInfos( ASTNode child, List<PKInfo> pkInfos) throws SemanticException { - if (child.getChildCount() < 6) { + if (child.getChildCount() < 4) { throw new SemanticException(ErrorMsg.INVALID_PK_SYNTAX.getMsg()); } // The ANTLR grammar looks like : // 1. KW_CONSTRAINT idfr=identifier KW_PRIMARY KW_KEY pkCols=columnParenthesesList // enableSpec=enableSpecification validateSpec=validateSpecification relySpec=relySpecification // -> ^(TOK_PRIMARY_KEY $pkCols $idfr $relySpec $enableSpec $validateSpec) - // when the user specifies the constraint name (i.e. child.getChildCount() == 7) + // when the user specifies the constraint name (i.e. child.getChildCount() == 5) // 2. KW_PRIMARY KW_KEY columnParenthesesList // enableSpec=enableSpecification validateSpec=validateSpecification relySpec=relySpecification // -> ^(TOK_PRIMARY_KEY columnParenthesesList $relySpec $enableSpec $validateSpec) - // when the user does not specify the constraint name (i.e. child.getChildCount() == 6) - boolean userSpecifiedConstraintName = child.getChildCount() == 7; - int relyIndex = child.getChildCount() == 7 ? 4 : 3; - for (int j = 0; j < child.getChild(1).getChildCount(); j++) { - Tree grandChild = child.getChild(1).getChild(j); + // when the user does not specify the constraint name (i.e. child.getChildCount() == 4) + boolean userSpecifiedConstraintName = child.getChildCount() == 5; + int relyIndex = child.getChildCount() == 5 ? 2 : 1; + for (int j = 0; j < child.getChild(0).getChildCount(); j++) { + Tree grandChild = child.getChild(0).getChild(j); boolean rely = child.getChild(relyIndex).getType() == HiveParser.TOK_VALIDATE; boolean enable = child.getChild(relyIndex+1).getType() == HiveParser.TOK_ENABLE; boolean validate = child.getChild(relyIndex+2).getType() == HiveParser.TOK_VALIDATE; @@ -683,7 +683,7 @@ public abstract class BaseSemanticAnalyzer { new PKInfo( unescapeIdentifier(grandChild.getText().toLowerCase()), (userSpecifiedConstraintName ? - unescapeIdentifier(child.getChild(3).getText().toLowerCase()) : null), + unescapeIdentifier(child.getChild(1).getText().toLowerCase()) : null), rely)); } } @@ -725,11 +725,11 @@ public abstract class BaseSemanticAnalyzer { */ protected static void processPrimaryKeys(ASTNode parent, ASTNode child, List<SQLPrimaryKey> primaryKeys) throws SemanticException { - int relyIndex = 4; + int relyIndex = 2; int cnt = 1; String[] qualifiedTabName = getQualifiedTableName((ASTNode) parent.getChild(0)); - for (int j = 0; j < child.getChild(1).getChildCount(); j++) { - Tree grandChild = child.getChild(1).getChild(j); + for (int j = 0; j < child.getChild(0).getChildCount(); j++) { + Tree grandChild = child.getChild(0).getChild(j); boolean rely = child.getChild(relyIndex).getType() == HiveParser.TOK_VALIDATE; boolean enable = child.getChild(relyIndex+1).getType() == HiveParser.TOK_ENABLE; boolean validate = child.getChild(relyIndex+2).getType() == HiveParser.TOK_VALIDATE; @@ -746,7 +746,7 @@ public abstract class BaseSemanticAnalyzer { qualifiedTabName[0], qualifiedTabName[1], unescapeIdentifier(grandChild.getText().toLowerCase()), cnt++, - unescapeIdentifier(child.getChild(3).getText().toLowerCase()), false, false, + unescapeIdentifier(child.getChild(1).getText().toLowerCase()), false, false, rely)); } } @@ -766,17 +766,17 @@ public abstract class BaseSemanticAnalyzer { // KW_REFERENCES tabName=tableName parCols=columnParenthesesList // enableSpec=enableSpecification validateSpec=validateSpecification relySpec=relySpecification // -> ^(TOK_FOREIGN_KEY $idfr $fkCols $tabName $parCols $relySpec $enableSpec $validateSpec) - // when the user specifies the constraint name (i.e. child.getChildCount() == 11) + // when the user specifies the constraint name (i.e. child.getChildCount() == 7) // 2. KW_FOREIGN KW_KEY fkCols=columnParenthesesList // KW_REFERENCES tabName=tableName parCols=columnParenthesesList // enableSpec=enableSpecification validateSpec=validateSpecification relySpec=relySpecification // -> ^(TOK_FOREIGN_KEY $fkCols $tabName $parCols $relySpec $enableSpec $validateSpec) - // when the user does not specify the constraint name (i.e. child.getChildCount() == 10) - boolean userSpecifiedConstraintName = child.getChildCount() == 11; - int fkIndex = userSpecifiedConstraintName ? 2 : 1; - int pkIndex = userSpecifiedConstraintName ? 6 : 5; - int ptIndex = userSpecifiedConstraintName ? 4 : 3; - int relyIndex = child.getChildCount() == 11 ? 8 : 7; + // when the user does not specify the constraint name (i.e. child.getChildCount() == 6) + boolean userSpecifiedConstraintName = child.getChildCount() == 7; + int fkIndex = userSpecifiedConstraintName ? 1 : 0; + int ptIndex = fkIndex + 1; + int pkIndex = ptIndex + 1; + int relyIndex = pkIndex + 1; if (child.getChildCount() <= fkIndex ||child.getChildCount() <= pkIndex || child.getChildCount() <= ptIndex) { http://git-wip-us.apache.org/repos/asf/hive/blob/445b7915/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g index 37817ce..d98a663 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g @@ -2145,7 +2145,7 @@ columnNameOrderList columnParenthesesList @init { pushMsg("column parentheses list", state); } @after { popMsg(state); } - : LPAREN columnNameList RPAREN + : LPAREN! columnNameList RPAREN! ; enableSpecification
