diff --git ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommandsForMmTable.java ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommandsForMmTable.java index d4f1dd5a86..f0fb58d4d8 100644 --- ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommandsForMmTable.java +++ ql/src/test/org/apache/hadoop/hive/ql/TestTxnCommandsForMmTable.java @@ -591,6 +591,52 @@ public void testInsertOverwriteWithUnionAll() throws Exception { Assert.assertEquals(stringifyValues(rExpected), rs); } + @Test + public void testTemporaryMmTableAtomicity() throws Exception { + String tblName = "hive18619"; + // Create temporary MM table. + runStatementOnDriver("drop table if exists " + tblName); + runStatementOnDriver("create temporary table " + tblName + " (a int, b string) " + + " TBLPROPERTIES ('transactional'='true', 'transactional_properties'='insert_only')"); + + // Create some data + runStatementOnDriver("insert into " + tblName + " values(1, 'foo')"); + runStatementOnDriver("insert into " + tblName + " values(2, 'bar')"); + + // Start a transaction with insert and roll back this transaction. + hiveConf.setBoolVar(HiveConf.ConfVars.HIVETESTMODEROLLBACKTXN, true); + runStatementOnDriver("insert into " + tblName + " values (3, 'baz')"); + hiveConf.setBoolVar(HiveConf.ConfVars.HIVETESTMODEROLLBACKTXN, false); + + List expected = new ArrayList<>(); + expected.add("1\tfoo"); + expected.add("2\tbar"); + Assert.assertEquals("", expected, + runStatementOnDriver("select a,b from " + tblName + " order by a")); + + // Run Worker to execute compaction + TxnStore txnHandler = TxnUtils.getTxnStore(hiveConf); + txnHandler.compact(new CompactionRequest("default", tblName, CompactionType.MINOR)); + Worker t = new Worker(); + t.setThreadId((int) t.getId()); + t.setConf(hiveConf); + AtomicBoolean stop = new AtomicBoolean(true); + AtomicBoolean looped = new AtomicBoolean(); + t.init(stop, looped); + t.run(); + + // Run Cleaner + Cleaner c = new Cleaner(); + c.setThreadId((int)c.getId()); + c.setConf(hiveConf); + c.init(stop, new AtomicBoolean()); + c.run(); + + // Check that aborted operation didn't become committed + Assert.assertEquals("", expected, + runStatementOnDriver("select a,b from " + tblName + " order by a")); + } + private void verifyDirAndResult(int expectedDeltas) throws Exception { FileSystem fs = FileSystem.get(hiveConf); // Verify the content of subdirs