commit 00dd390bdbe56f921d2f4ee582c2999cca2d1387 Author: Reuben Kuhnert Date: Tue Mar 8 11:26:41 2016 -0600 HIVE-13231: Show helpful message when create as location fails because parent directory does not exist. Change-Id: Idb5dabba4f93facfa00927d5732bc74a25671d98 diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index ad170963c4044bdf71e3d498cab669014e452ab3..0268dbd55c84a6a5762751f52aafdab05e32745b 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -2798,7 +2798,15 @@ public static boolean moveFile(HiveConf conf, Path srcf, Path destf, LOG.info((replace ? "Replacing src:" : "Renaming src: ") + srcf.toString() + ", dest: " + destf.toString() + ", Status:" + success); } catch (IOException ioe) { - throw new HiveException("Unable to move source " + srcf + " to destination " + destf, ioe); + StringBuilder message = new StringBuilder( + String.format("Unable to move source %s to destination %s. ", srcf, destf) + ); + + if (!HiveConf.getBoolVar(conf, ConfVars.HIVE_INSERT_INTO_MULTILEVEL_DIRS)) { + message.append("To enable automatic subdirectory generation set 'hive.insert.into.multilevel.dirs=true'."); + } + + throw new HiveException(message.toString(), ioe); } if (success && inheritPerms) { diff --git a/ql/src/test/queries/clientnegative/location_with_new_parent_directories.q b/ql/src/test/queries/clientnegative/location_with_new_parent_directories.q new file mode 100644 index 0000000000000000000000000000000000000000..e87303109b7fcaadc148a7d7b309e9f368cf8953 --- /dev/null +++ b/ql/src/test/queries/clientnegative/location_with_new_parent_directories.q @@ -0,0 +1,2 @@ +set hive.insert.into.multilevel.dirs=false; +create table shouldfail location '${hiveconf:hive.metastore.warehouse.dir}/x/y/z/shouldfail' as select * from src; diff --git a/ql/src/test/queries/clientpositive/location_with_new_parent_directories.q b/ql/src/test/queries/clientpositive/location_with_new_parent_directories.q new file mode 100644 index 0000000000000000000000000000000000000000..f34fa29dd0c30065b9d8809b17fa650b18e81418 --- /dev/null +++ b/ql/src/test/queries/clientpositive/location_with_new_parent_directories.q @@ -0,0 +1,2 @@ +set hive.insert.into.multilevel.dirs=true; +create table shouldwork location '${hiveconf:hive.metastore.warehouse.dir}/x/y/z/shouldwork' as select * from src; diff --git a/ql/src/test/results/clientnegative/location_with_new_parent_directories.q.out b/ql/src/test/results/clientnegative/location_with_new_parent_directories.q.out new file mode 100644 index 0000000000000000000000000000000000000000..a3c2a4dfbff94354a9623cd35e199391b6254150 --- /dev/null +++ b/ql/src/test/results/clientnegative/location_with_new_parent_directories.q.out @@ -0,0 +1,8 @@ +#### A masked pattern was here #### +PREHOOK: type: CREATETABLE_AS_SELECT +PREHOOK: Input: default@src +#### A masked pattern was here #### +PREHOOK: Output: database:default +PREHOOK: Output: default@shouldfail +#### A masked pattern was here #### +FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask diff --git a/ql/src/test/results/clientpositive/location_with_new_parent_directories.q.out b/ql/src/test/results/clientpositive/location_with_new_parent_directories.q.out new file mode 100644 index 0000000000000000000000000000000000000000..f5c8fd5789411edc5cd086a9892165fcab9453c6 --- /dev/null +++ b/ql/src/test/results/clientpositive/location_with_new_parent_directories.q.out @@ -0,0 +1,12 @@ +#### A masked pattern was here #### +PREHOOK: type: CREATETABLE_AS_SELECT +PREHOOK: Input: default@src +#### A masked pattern was here #### +PREHOOK: Output: database:default +PREHOOK: Output: default@shouldwork +#### A masked pattern was here #### +POSTHOOK: type: CREATETABLE_AS_SELECT +POSTHOOK: Input: default@src +#### A masked pattern was here #### +POSTHOOK: Output: database:default +POSTHOOK: Output: default@shouldwork