FAQ
Author: navis
Date: Mon Aug 18 05:42:21 2014
New Revision: 1618540

URL: http://svn.apache.org/r1618540
Log:
HIVE-7710 : Rename table across database might fail (Chun Chen via Navis)

Modified:
     hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
     hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
     hive/trunk/ql/src/test/queries/clientpositive/alter_rename_table.q
     hive/trunk/ql/src/test/results/clientpositive/alter_rename_table.q.out

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java?rev=1618540&r1=1618539&r2=1618540&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java Mon Aug 18 05:42:21 2014
@@ -222,10 +222,10 @@ public class HiveAlterHandler implements
        if (success && moveData) {
          // change the file name in hdfs
          // check that src exists otherwise there is no need to copy the data
+ // rename the src to destination
          try {
- if (srcFs.exists(srcPath)) {
- // rename the src to destination
- srcFs.rename(srcPath, destPath);
+ if (srcFs.exists(srcPath) && !srcFs.rename(srcPath, destPath)) {
+ throw new IOException("Renaming " + srcPath + " to " + destPath + " is failed");
            }
          } catch (IOException e) {
            boolean revertMetaDataTransaction = false;

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java?rev=1618540&r1=1618539&r2=1618540&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java Mon Aug 18 05:42:21 2014
@@ -2564,13 +2564,13 @@ public class ObjectStore implements RawS
        }

        // For now only alter name, owner, paramters, cols, bucketcols are allowed
+ oldt.setDatabase(newt.getDatabase());
        oldt.setTableName(newt.getTableName().toLowerCase());
        oldt.setParameters(newt.getParameters());
        oldt.setOwner(newt.getOwner());
        // Fully copy over the contents of the new SD into the old SD,
        // so we don't create an extra SD in the metastore db that has no references.
        copyMSD(newt.getSd(), oldt.getSd());
- oldt.setDatabase(newt.getDatabase());
        oldt.setRetention(newt.getRetention());
        oldt.setPartitionKeys(newt.getPartitionKeys());
        oldt.setTableType(newt.getTableType());

Modified: hive/trunk/ql/src/test/queries/clientpositive/alter_rename_table.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/alter_rename_table.q?rev=1618540&r1=1618539&r2=1618540&view=diff
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/alter_rename_table.q (original)
+++ hive/trunk/ql/src/test/queries/clientpositive/alter_rename_table.q Mon Aug 18 05:42:21 2014
@@ -26,3 +26,10 @@ ALTER TABLE source.srcpart RENAME TO tar
  ALTER TABLE source.srcpart RENAME TO target.srcpart;

  select * from target.srcpart tablesample (10 rows);
+
+create table source.src like default.src;
+create table source.src1 like default.src;
+load data local inpath '../../data/files/kv1.txt' overwrite into table source.src;
+
+ALTER TABLE source.src RENAME TO target.src1;
+select * from target.src1 tablesample (10 rows);
\ No newline at end of file

Modified: hive/trunk/ql/src/test/results/clientpositive/alter_rename_table.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/alter_rename_table.q.out?rev=1618540&r1=1618539&r2=1618540&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/alter_rename_table.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/alter_rename_table.q.out Mon Aug 18 05:42:21 2014
@@ -212,3 +212,56 @@ POSTHOOK: Input: target@srcpart@ds=2008-
  278 val_278 2008-04-08 11
  98 val_98 2008-04-08 11
  484 val_484 2008-04-08 11
+PREHOOK: query: create table source.src like default.src
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:source
+PREHOOK: Output: source@source.src
+POSTHOOK: query: create table source.src like default.src
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:source
+POSTHOOK: Output: source@source.src
+POSTHOOK: Output: source@src
+PREHOOK: query: create table source.src1 like default.src
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:source
+PREHOOK: Output: source@source.src1
+POSTHOOK: query: create table source.src1 like default.src
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:source
+POSTHOOK: Output: source@source.src1
+POSTHOOK: Output: source@src1
+PREHOOK: query: load data local inpath '../../data/files/kv1.txt' overwrite into table source.src
+PREHOOK: type: LOAD
+#### A masked pattern was here ####
+PREHOOK: Output: source@src
+POSTHOOK: query: load data local inpath '../../data/files/kv1.txt' overwrite into table source.src
+POSTHOOK: type: LOAD
+#### A masked pattern was here ####
+POSTHOOK: Output: source@src
+PREHOOK: query: ALTER TABLE source.src RENAME TO target.src1
+PREHOOK: type: ALTERTABLE_RENAME
+PREHOOK: Input: source@src
+PREHOOK: Output: source@src
+POSTHOOK: query: ALTER TABLE source.src RENAME TO target.src1
+POSTHOOK: type: ALTERTABLE_RENAME
+POSTHOOK: Input: source@src
+POSTHOOK: Output: source@src
+POSTHOOK: Output: target@src1
+PREHOOK: query: select * from target.src1 tablesample (10 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: target@src1
+#### A masked pattern was here ####
+POSTHOOK: query: select * from target.src1 tablesample (10 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: target@src1
+#### A masked pattern was here ####
+238 val_238
+86 val_86
+311 val_311
+27 val_27
+165 val_165
+409 val_409
+255 val_255
+278 val_278
+98 val_98
+484 val_484

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommits @
categorieshive, hadoop
postedAug 18, '14 at 5:42a
activeAug 18, '14 at 5:42a
posts1
users1
websitehive.apache.org

1 user in discussion

Navis: 1 post

People

Translate

site design / logo © 2021 Grokbase