diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java index f88f4dd..a058824 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java @@ -528,7 +528,7 @@ static public void deleteWHDirectory(Path path, Configuration conf, * if it doesn't match the pattern. */ static public boolean validateName(String name) { - Pattern tpat = Pattern.compile("[\\w_]+"); + Pattern tpat = Pattern.compile("[\\w_$]+"); Matcher m = tpat.matcher(name); if (m.matches()) { return true; diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/FromClauseParser.g b/ql/src/java/org/apache/hadoop/hive/ql/parse/FromClauseParser.g index 038ed99..839ad16 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/FromClauseParser.g +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/FromClauseParser.g @@ -38,6 +38,26 @@ k=3; protected boolean useSQL11ReservedKeywordsForIdentifier() { return gParent.useSQL11ReservedKeywordsForIdentifier(); } + public String checkTableName(String name) { + Pattern tpat = Pattern.compile("[\\w_]+"); + Matcher m = tpat.matcher(name); + if (m.matches()) { + return name; + } + // replace all the other characters with the number in ASCII. + else { + String ret = ""; + for (char c : name.toCharArray()) { + m = tpat.matcher(String.valueOf(c)); + if (m.matches()) { + ret += c; + } else { + ret += "$"+(short) c+"$"; + } + } + return ret; + } + } } @rulecatch { @@ -194,10 +214,10 @@ tableName @after { gParent.popMsg(state); } : db=identifier DOT tab=identifier - -> ^(TOK_TABNAME $db $tab) + -> ^(TOK_TABNAME $db {adaptor.create(Identifier, checkTableName($tab.text))}) | tab=identifier - -> ^(TOK_TABNAME $tab) + -> ^(TOK_TABNAME {adaptor.create(Identifier, checkTableName($tab.text))}) ; viewName @@ -205,7 +225,7 @@ viewName @after { gParent.popMsg(state); } : (db=identifier DOT)? view=identifier - -> ^(TOK_TABNAME $db? $view) + -> ^(TOK_TABNAME $db? {adaptor.create(Identifier, checkTableName($view.text))}) ; subQuerySource @@ -303,7 +323,7 @@ Note that we only want literals as column names */ tableNameColList : - KW_AS? identifier LPAREN identifier (COMMA identifier)* RPAREN -> ^(TOK_VIRTUAL_TABREF ^(TOK_TABNAME identifier) ^(TOK_COL_NAME identifier+)) + KW_AS? tabName=identifier LPAREN identifier (COMMA identifier)* RPAREN -> ^(TOK_VIRTUAL_TABREF ^(TOK_TABNAME {adaptor.create(Identifier, checkTableName($tabName.text))}) ^(TOK_COL_NAME identifier+)) ; //----------------------------------------------------------------------------------- \ No newline at end of file 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 cf7ab3a..0f8d945 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 @@ -375,6 +375,8 @@ import java.util.Collection; import java.util.HashMap; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.conf.HiveConf; +import java.util.regex.Matcher; +import java.util.regex.Pattern; }