diff --git ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index afec18f..13ec65f 100644 --- ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -595,7 +595,6 @@ public class Hive { /** * Drops table along with the data in it. If the table doesn't exist * then it is a no-op - * @param dbName database where the table lives * @param tableName table to drop * @throws HiveException thrown if the drop fails * Drops table along with the data in it. If the table doesn't exist then it @@ -668,7 +667,15 @@ public class Hive { * table doesn't exist */ public Table getTable(final String tableName) throws HiveException { - return this.getTable(getCurrentDatabase(), tableName, true); + if (-1 == tableName.indexOf('.')) { + return getTable(getCurrentDatabase(), tableName, true); + } else { + String namePart[] = tableName.split("\\."); + if (2 != namePart.length) { + throw new HiveException("Invalid table name: " + tableName); + } + return getTable(namePart[0], namePart[1], true); + } } /** diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g index 427f41a..9878676 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g +++ ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g @@ -302,8 +302,8 @@ databaseComment createTableStatement @init { msgs.push("create table statement"); } @after { msgs.pop(); } - : KW_CREATE (ext=KW_EXTERNAL)? KW_TABLE ifNotExists? name=Identifier - ( like=KW_LIKE likeName=Identifier + : KW_CREATE (ext=KW_EXTERNAL)? KW_TABLE ifNotExists? name=TableIdentifier + ( like=KW_LIKE likeName=TableIdentifier tableLocation? | (LPAREN columnNameTypeList RPAREN)? tableComment? @@ -386,7 +386,7 @@ dropIndexStatement dropTableStatement @init { msgs.push("drop statement"); } @after { msgs.pop(); } - : KW_DROP KW_TABLE Identifier -> ^(TOK_DROPTABLE Identifier) + : KW_DROP KW_TABLE TableIdentifier -> ^(TOK_DROPTABLE TableIdentifier) ; alterStatement @@ -519,7 +519,7 @@ alterStatementSuffixSerdeProperties tablePartitionPrefix @init {msgs.push("table partition prefix");} @after {msgs.pop();} - :name=Identifier partitionSpec? + :name=TableIdentifier partitionSpec? ->^(TOK_TABLE_PARTITION $name partitionSpec?) ; @@ -1299,8 +1299,7 @@ tableSource @init { msgs.push("table source"); } @after { msgs.pop(); } : - tabname=Identifier (ts=tableSample)? (alias=Identifier)? -> ^(TOK_TABREF $tabname $ts? $alias?) - + table=TableIdentifier (ts=tableSample)? (alias=Identifier)? -> ^(TOK_TABREF $table $ts? $alias?) ; subQuerySource @@ -1618,7 +1617,7 @@ booleanValue tabName : - Identifier partitionSpec? -> ^(TOK_TAB Identifier partitionSpec?) + TableIdentifier partitionSpec? -> ^(TOK_TAB TableIdentifier partitionSpec?) ; partitionSpec @@ -1880,6 +1879,7 @@ DOT : '.'; // generated as a part of Number rule COLON : ':' ; COMMA : ',' ; SEMICOLON : ';' ; +BACKTICK : '`'; LPAREN : '(' ; RPAREN : ')' ; @@ -1958,10 +1958,22 @@ Number (Digit)+ ( DOT (Digit)* (Exponent)? | Exponent)? ; +TableIdentifier + : + (Identifier DOT)? Identifier + ; + +fragment Identifier : + SimpleIdentifier + | BACKTICK SimpleIdentifier BACKTICK + ; + +fragment +SimpleIdentifier + : (Letter | Digit) (Letter | Digit | '_')* - | '`' RegexComponent+ '`' ; CharSetName