commit 0ae4eaea47325aa90d21d628f81496cfdb981c2f Author: Daniel Dai Date: Thu Aug 6 17:59:37 2015 -0700 HIVE-11441: No DDL allowed on table if user accidentally set table location wrong diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java index 21625bc..154e648 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java @@ -23,6 +23,7 @@ import org.antlr.runtime.tree.Tree; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.common.JavaUtils; import org.apache.hadoop.hive.conf.HiveConf; @@ -1464,6 +1465,14 @@ private void analyzeAlterTableLocation(ASTNode ast, String tableName, HashMap partSpec) throws SemanticException { String newLocation = unescapeSQLString(ast.getChild(0).getText()); + try { + // To make sure host/port pair is valid, the status of the location + // does not matter + FileSystem fsForFile = FileSystem.get(new URI(newLocation), conf); + fsForFile.getFileStatus(new Path(newLocation)); + } catch (Exception e) { + throw new SemanticException(e); + } addLocationToOutputs(newLocation); AlterTableDesc alterTblDesc = new AlterTableDesc(tableName, newLocation, partSpec); diff --git a/ql/src/test/queries/clientnegative/alter_table_wrong_location.q b/ql/src/test/queries/clientnegative/alter_table_wrong_location.q new file mode 100644 index 0000000..3721867 --- /dev/null +++ b/ql/src/test/queries/clientnegative/alter_table_wrong_location.q @@ -0,0 +1,4 @@ +create table testwrongloc(id int); + +-- Assume port 12345 is not open +alter table testwrongloc set location "hdfs://localhost:12345/tmp/testwrongloc"; diff --git a/ql/src/test/results/clientnegative/alter_table_wrong_location.q.out b/ql/src/test/results/clientnegative/alter_table_wrong_location.q.out new file mode 100644 index 0000000..0b18d3c --- /dev/null +++ b/ql/src/test/results/clientnegative/alter_table_wrong_location.q.out @@ -0,0 +1,9 @@ +PREHOOK: query: create table testwrongloc(id int) +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@testwrongloc +POSTHOOK: query: create table testwrongloc(id int) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@testwrongloc +FAILED: SemanticException java.net.ConnectException: Call From daijymacpro-2.local/10.11.3.220 to localhost:12345 failed on connection exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused