Repository: hive Updated Branches: refs/heads/master 1b6303849 -> 99f1e5457
HIVE-12946: alter table should also add default scheme and authority for the location similar to create table (Aihua Xu, reviewed by Yongzhi Chen) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/99f1e545 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/99f1e545 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/99f1e545 Branch: refs/heads/master Commit: 99f1e54571044308e58115524dd17d69d23397d2 Parents: 1b63038 Author: Aihua Xu <aihu...@apache.org> Authored: Fri Jan 29 15:24:11 2016 -0500 Committer: Aihua Xu <aihu...@apache.org> Committed: Wed Feb 3 10:09:27 2016 -0500 ---------------------------------------------------------------------- .../hadoop/hive/metastore/HiveMetaStore.java | 19 +++++++++++ .../org/apache/hadoop/hive/ql/ErrorMsg.java | 2 +- .../org/apache/hadoop/hive/ql/exec/DDLTask.java | 3 +- .../alter_table_wrong_location2.q | 3 ++ .../queries/clientpositive/schemeAuthority3.q | 7 ++++ .../alter_table_wrong_location2.q.out | 14 ++++++++ .../clientpositive/schemeAuthority3.q.out | 35 ++++++++++++++++++++ 7 files changed, 80 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/99f1e545/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java ---------------------------------------------------------------------- diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index dde253a..bb33693 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -3350,6 +3350,15 @@ public class HiveMetaStore extends ThriftHiveMetastore { } } + // Adds the missing scheme/authority for the new partition location + if (new_part.getSd() != null) { + String newLocation = new_part.getSd().getLocation(); + if (org.apache.commons.lang.StringUtils.isNotEmpty(newLocation)) { + Path tblPath = wh.getDnsPath(new Path(newLocation)); + new_part.getSd().setLocation(tblPath.toString()); + } + } + Partition oldPart = null; Exception ex = null; try { @@ -3545,6 +3554,16 @@ public class HiveMetaStore extends ThriftHiveMetastore { newTable.putToParameters(hive_metastoreConstants.DDL_TIME, Long.toString(System .currentTimeMillis() / 1000)); } + + // Adds the missing scheme/authority for the new table location + if (newTable.getSd() != null) { + String newLocation = newTable.getSd().getLocation(); + if (org.apache.commons.lang.StringUtils.isNotEmpty(newLocation)) { + Path tblPath = wh.getDnsPath(new Path(newLocation)); + newTable.getSd().setLocation(tblPath.toString()); + } + } + boolean success = false; Exception ex = null; try { http://git-wip-us.apache.org/repos/asf/hive/blob/99f1e545/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java b/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java index 08bc654..d46c71f 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/ErrorMsg.java @@ -350,7 +350,7 @@ public enum ErrorMsg { TABLE_NOT_PARTITIONED(10241, "Table {0} is not a partitioned table", true), DATABSAE_ALREADY_EXISTS(10242, "Database {0} already exists", true), CANNOT_REPLACE_COLUMNS(10243, "Replace columns is not supported for table {0}. SerDe may be incompatible.", true), - BAD_LOCATION_VALUE(10244, "{0} is not absolute or has no scheme information. Please specify a complete absolute uri with scheme information."), + BAD_LOCATION_VALUE(10244, "{0} is not absolute. Please specify a complete absolute uri."), UNSUPPORTED_ALTER_TBL_OP(10245, "{0} alter table options is not supported"), INVALID_BIGTABLE_MAPJOIN(10246, "{0} table chosen for streaming is not valid", true), MISSING_OVER_CLAUSE(10247, "Missing over clause for function : "), http://git-wip-us.apache.org/repos/asf/hive/blob/99f1e545/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java index 2e45913..be6ea63 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java @@ -3504,8 +3504,7 @@ public class DDLTask extends Task<DDLWork> implements Serializable { String newLocation = alterTbl.getNewLocation(); try { URI locUri = new URI(newLocation); - if (!locUri.isAbsolute() || locUri.getScheme() == null - || locUri.getScheme().trim().equals("")) { + if (!new Path(locUri).isAbsolute()) { throw new HiveException(ErrorMsg.BAD_LOCATION_VALUE, newLocation); } sd.setLocation(newLocation); http://git-wip-us.apache.org/repos/asf/hive/blob/99f1e545/ql/src/test/queries/clientnegative/alter_table_wrong_location2.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/alter_table_wrong_location2.q b/ql/src/test/queries/clientnegative/alter_table_wrong_location2.q new file mode 100644 index 0000000..ab2800e --- /dev/null +++ b/ql/src/test/queries/clientnegative/alter_table_wrong_location2.q @@ -0,0 +1,3 @@ +create table testwrongloc(id int); + +alter table testwrongloc set location "relative/testwrongloc"; http://git-wip-us.apache.org/repos/asf/hive/blob/99f1e545/ql/src/test/queries/clientpositive/schemeAuthority3.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientpositive/schemeAuthority3.q b/ql/src/test/queries/clientpositive/schemeAuthority3.q new file mode 100644 index 0000000..4a7f5c5 --- /dev/null +++ b/ql/src/test/queries/clientpositive/schemeAuthority3.q @@ -0,0 +1,7 @@ +set hive.mapred.mode=nonstrict; + +create table noschemeTable(key string) partitioned by (value string, value2 string) row format delimited fields terminated by '\\t' stored as textfile; +insert into noschemeTable partition(value='0', value2='clusterA') select key from src where (key = 10) order by key; + +alter table noschemeTable set location '/tmp/newtest'; +alter table noschemeTable partition (value='0', value2='clusterA') set location '/tmp/newtest2/value=0/value2=clusterA'; http://git-wip-us.apache.org/repos/asf/hive/blob/99f1e545/ql/src/test/results/clientnegative/alter_table_wrong_location2.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientnegative/alter_table_wrong_location2.q.out b/ql/src/test/results/clientnegative/alter_table_wrong_location2.q.out new file mode 100644 index 0000000..b50786a --- /dev/null +++ b/ql/src/test/results/clientnegative/alter_table_wrong_location2.q.out @@ -0,0 +1,14 @@ +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 +PREHOOK: query: alter table testwrongloc set location "relative/testwrongloc" +PREHOOK: type: ALTERTABLE_LOCATION +PREHOOK: Input: default@testwrongloc +PREHOOK: Output: default@testwrongloc +#### A masked pattern was here #### +FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. {0} is not absolute. Please specify a complete absolute uri. relative/testwrongloc http://git-wip-us.apache.org/repos/asf/hive/blob/99f1e545/ql/src/test/results/clientpositive/schemeAuthority3.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientpositive/schemeAuthority3.q.out b/ql/src/test/results/clientpositive/schemeAuthority3.q.out new file mode 100644 index 0000000..b26bf42 --- /dev/null +++ b/ql/src/test/results/clientpositive/schemeAuthority3.q.out @@ -0,0 +1,35 @@ +PREHOOK: query: create table noschemeTable(key string) partitioned by (value string, value2 string) row format delimited fields terminated by '\\t' stored as textfile +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@noschemeTable +POSTHOOK: query: create table noschemeTable(key string) partitioned by (value string, value2 string) row format delimited fields terminated by '\\t' stored as textfile +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@noschemeTable +PREHOOK: query: insert into noschemeTable partition(value='0', value2='clusterA') select key from src where (key = 10) order by key +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Output: default@noschemetable@value=0/value2=clusterA +POSTHOOK: query: insert into noschemeTable partition(value='0', value2='clusterA') select key from src where (key = 10) order by key +POSTHOOK: type: QUERY +POSTHOOK: Input: default@src +POSTHOOK: Output: default@noschemetable@value=0/value2=clusterA +POSTHOOK: Lineage: noschemetable PARTITION(value=0,value2=clusterA).key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ] +#### A masked pattern was here #### +PREHOOK: type: ALTERTABLE_LOCATION +PREHOOK: Input: default@noschemetable +PREHOOK: Output: default@noschemetable +#### A masked pattern was here #### +POSTHOOK: type: ALTERTABLE_LOCATION +POSTHOOK: Input: default@noschemetable +POSTHOOK: Output: default@noschemetable +#### A masked pattern was here #### +PREHOOK: type: ALTERPARTITION_LOCATION +PREHOOK: Input: default@noschemetable +PREHOOK: Output: default@noschemetable@value=0/value2=clusterA +#### A masked pattern was here #### +POSTHOOK: type: ALTERPARTITION_LOCATION +POSTHOOK: Input: default@noschemetable +POSTHOOK: Input: default@noschemetable@value=0/value2=clusterA +POSTHOOK: Output: default@noschemetable@value=0/value2=clusterA +#### A masked pattern was here ####