hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ekoif...@apache.org
Subject [1/2] hive git commit: HIVE-11848 - tables in subqueries don't get locked (Eugene Koifman, reviewed by Wei Zheng)
Date Tue, 03 May 2016 22:24:39 GMT
Repository: hive
Updated Branches:
  refs/heads/branch-1 ab2951237 -> bfc249632


HIVE-11848 - tables in subqueries don't get locked (Eugene Koifman, reviewed by Wei Zheng)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/0780218f
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/0780218f
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/0780218f

Branch: refs/heads/branch-1
Commit: 0780218f2e075e43aa9051313b1e13b034d778ae
Parents: ab29512
Author: Eugene Koifman <ekoifman@hortonworks.com>
Authored: Tue May 3 14:51:38 2016 -0700
Committer: Eugene Koifman <ekoifman@hortonworks.com>
Committed: Tue May 3 14:51:38 2016 -0700

----------------------------------------------------------------------
 .../ql/parse/UpdateDeleteSemanticAnalyzer.java  | 16 +++++++++-
 .../hive/ql/lockmgr/TestDbTxnManager2.java      | 33 ++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/0780218f/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java
b/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java
index 4c69534..a80c093 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/UpdateDeleteSemanticAnalyzer.java
@@ -321,7 +321,9 @@ public class UpdateDeleteSemanticAnalyzer extends SemanticAnalyzer {
     // Walk through all our inputs and set them to note that this read is part of an update
or a
     // delete.
     for (ReadEntity input : inputs) {
-      input.setUpdateOrDelete(true);
+      if(isWritten(input)) {
+        input.setUpdateOrDelete(true);
+      }
     }
 
     if (inputIsPartitioned(inputs)) {
@@ -369,6 +371,18 @@ public class UpdateDeleteSemanticAnalyzer extends SemanticAnalyzer {
     }
   }
 
+  /**
+   * Check that {@code readEntity} is also being written
+   */
+  private boolean isWritten(Entity readEntity) {
+    for(Entity writeEntity : outputs) {
+      //make sure to compare them as Entity, i.e. that it's the same table or partition,
etc
+      if(writeEntity.toString().equalsIgnoreCase(readEntity.toString())) {
+        return true;
+      }
+    }
+    return false;
+  }
   private String operation() {
     if (updating()) return "update";
     else if (deleting()) return "delete";

http://git-wip-us.apache.org/repos/asf/hive/blob/0780218f/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java b/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java
index 0a91348..42c7064 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java
@@ -72,6 +72,39 @@ public class TestDbTxnManager2 {
     TxnDbUtil.prepDb();
   }
   @Test
+  public void testLocksInSubquery() throws Exception {
+    checkCmdOnDriver(driver.run("create table if not exists T (a int, b int)"));
+    checkCmdOnDriver(driver.run("create table if not exists S (a int, b int) clustered by(b)
into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')"));
+    checkCmdOnDriver(driver.run("create table if not exists R (a int, b int) clustered by(b)
into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')"));
+
+    checkCmdOnDriver(driver.compileAndRespond("delete from S where a in (select a from T
where b = 1)"));
+    txnMgr.openTxn("one");
+    txnMgr.acquireLocks(driver.getPlan(), ctx, "one");
+    List<ShowLocksResponseElement> locks = getLocks();
+    Assert.assertEquals("Unexpected lock count", 2, locks.size());
+    checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T", null, locks.get(0));
+    checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "S", null, locks.get(1));
+    txnMgr.rollbackTxn();
+
+    checkCmdOnDriver(driver.compileAndRespond("update S set a = 7 where a in (select a from
T where b = 1)"));
+    txnMgr.openTxn("one");
+    txnMgr.acquireLocks(driver.getPlan(), ctx, "one");
+    locks = getLocks();
+    Assert.assertEquals("Unexpected lock count", 2, locks.size());
+    checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T", null, locks.get(0));
+    checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "S", null, locks.get(1));
+    txnMgr.rollbackTxn();
+
+    checkCmdOnDriver(driver.compileAndRespond("insert into R select * from S where a in (select
a from T where b = 1)"));
+    txnMgr.openTxn("three");
+    txnMgr.acquireLocks(driver.getPlan(), ctx, "three");
+    locks = getLocks();
+    Assert.assertEquals("Unexpected lock count", 3, locks.size());
+    checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T", null, locks.get(0));
+    checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "S", null, locks.get(1));
+    checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "R", null, locks.get(2));
+  }
+  @Test
   public void createTable() throws Exception {
     CommandProcessorResponse cpr = driver.compileAndRespond("create table if not exists T
(a int, b int)");
     checkCmdOnDriver(cpr);


Mime
View raw message