diff --git a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java index 1360563..c9f130c 100644 --- a/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java +++ b/itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java @@ -531,12 +531,15 @@ public void sqlInsertPartition() throws Exception { driver.run("insert into table sip partition (ds) values (3, 'tomorrow')"); driver.run("alter table sip drop partition (ds = 'tomorrow')"); + driver.run("insert into table sip partition (ds) values (42, 'todaytwo')"); + driver.run("insert overwrite table sip partition(ds='todaytwo') select c from sip where 'ds'='today'"); + NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null); for (NotificationEvent ne : rsp.getEvents()) LOG.debug("EVENT: " + ne.getMessage()); // For reasons not clear to me there's one or more alter partitions after add partition and // insert. - assertEquals(19, rsp.getEventsSize()); + assertEquals(24, rsp.getEventsSize()); NotificationEvent event = rsp.getEvents().get(1); assertEquals(firstEventId + 2, event.getEventId()); assertEquals(HCatConstants.HCAT_ADD_PARTITION_EVENT, event.getEventType()); @@ -566,7 +569,29 @@ public void sqlInsertPartition() throws Exception { event = rsp.getEvents().get(18); assertEquals(firstEventId + 19, event.getEventId()); assertEquals(HCatConstants.HCAT_DROP_PARTITION_EVENT, event.getEventType()); - } + + event = rsp.getEvents().get(19); + assertEquals(firstEventId + 20, event.getEventId()); + assertEquals(HCatConstants.HCAT_ADD_PARTITION_EVENT, event.getEventType()); + event = rsp.getEvents().get(20); + assertEquals(firstEventId + 21, event.getEventId()); + assertEquals(HCatConstants.HCAT_ALTER_PARTITION_EVENT, event.getEventType()); + assertTrue(event.getMessage().matches(".*\"ds\":\"todaytwo\".*")); + + event = rsp.getEvents().get(21); + assertEquals(firstEventId + 22, event.getEventId()); + assertEquals(HCatConstants.HCAT_INSERT_EVENT, event.getEventType()); + assertTrue(event.getMessage().matches(".*\"files\":\\[\\].*")); // replace-overwrite introduces no new files + event = rsp.getEvents().get(22); + assertEquals(firstEventId + 23, event.getEventId()); + assertEquals(HCatConstants.HCAT_ALTER_PARTITION_EVENT, event.getEventType()); + assertTrue(event.getMessage().matches(".*\"ds\":\"todaytwo\".*")); + event = rsp.getEvents().get(23); + assertEquals(firstEventId + 24, event.getEventId()); + assertEquals(HCatConstants.HCAT_ALTER_PARTITION_EVENT, event.getEventType()); + assertTrue(event.getMessage().matches(".*\"ds\":\"todaytwo\".*")); + + } @Test public void cleanupNotifs() throws Exception { diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index ef0bb3d..47f7705 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -1554,8 +1554,10 @@ public Partition loadPartition(Path loadPath, Table tbl, Partition newTPart = oldPart != null ? oldPart : new Partition(tbl, partSpec, newPartPath); alterPartitionSpecInMemory(tbl, partSpec, newTPart.getTPartition(), inheritTableSpecs, newPartPath.toString()); validatePartition(newTPart); - if (null != newFiles) { + if ((null != newFiles) || replace) { fireInsertEvent(tbl, partSpec, newFiles); + } else { + LOG.debug("No new files were created, and is not a replace. Skipping generating INSERT event."); } //column stats will be inaccurate