commit 665f8ee4b2169db289ea657f58868c1cfa8546fc Author: Alan Gates Date: Mon Mar 2 09:59:56 2015 -0800 HIVE-9826 Firing insert event fails on temporary table diff --git itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java index 9a8c50f..8ef5394 100644 --- itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java +++ itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java @@ -438,6 +438,41 @@ public void sqlInsertTable() throws Exception { } @Test + public void sqlCTAS() throws Exception { + + driver.run("create table ctas_source (c int)"); + driver.run("insert into table ctas_source values (1)"); + driver.run("create table ctas_target as select c from ctas_source"); + + NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null); + + assertEquals(6, rsp.getEventsSize()); + NotificationEvent event = rsp.getEvents().get(0); + assertEquals(firstEventId + 1, event.getEventId()); + assertEquals(HCatConstants.HCAT_CREATE_TABLE_EVENT, event.getEventType()); + event = rsp.getEvents().get(2); + assertEquals(firstEventId + 3, event.getEventId()); + assertEquals(HCatConstants.HCAT_INSERT_EVENT, event.getEventType()); + // Make sure the files are listed in the insert + assertTrue(event.getMessage().matches(".*\"files\":\\[\"pfile.*")); + event = rsp.getEvents().get(4); + assertEquals(firstEventId + 5, event.getEventId()); + assertEquals(HCatConstants.HCAT_CREATE_TABLE_EVENT, event.getEventType()); + } + + @Test + public void sqlTempTable() throws Exception { + + LOG.info("XXX Starting temp table"); + driver.run("create temporary table tmp1 (c int)"); + driver.run("insert into table tmp1 values (1)"); + + NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null); + + assertEquals(0, rsp.getEventsSize()); + } + + @Test public void sqlDb() throws Exception { driver.run("create database sd"); diff --git ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index aacf913..69ebdf0 100644 --- ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -1886,6 +1886,10 @@ private void fireInsertEvent(Table tbl, Map partitionSpec, List< throws HiveException { if (conf.getBoolVar(ConfVars.FIRE_EVENTS_FOR_DML)) { LOG.debug("Firing dml insert event"); + if (tbl.isTemporary()) { + LOG.debug("Not firing dml insert event as " + tbl.getTableName() + " is temporary"); + return; + } FireEventRequestData data = new FireEventRequestData(); InsertEventRequestData insertData = new InsertEventRequestData(); data.setInsertData(insertData);