use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestDbNotificationListener method filterWithMax.
@Test
public void filterWithMax() throws Exception {
Database db = new Database("f10", "no description", "file:/tmp", emptyParameters);
msClient.createDatabase(db);
db = new Database("f11", "no description", "file:/tmp", emptyParameters);
msClient.createDatabase(db);
msClient.dropDatabase("f11");
IMetaStoreClient.NotificationFilter filter = new IMetaStoreClient.NotificationFilter() {
@Override
public boolean accept(NotificationEvent event) {
return event.getEventType().equals(EventType.CREATE_DATABASE.toString());
}
};
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 1, filter);
assertEquals(1, rsp.getEventsSize());
assertEquals(firstEventId + 1, rsp.getEvents().get(0).getEventId());
}
use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestDbNotificationListener method sqlInsertPartition.
@Test
public void sqlInsertPartition() throws Exception {
String tblName = "sqlinsptn";
// Event 1
driver.run("create table " + tblName + " (c int) partitioned by (ds string)");
// Event 2, 3, 4
driver.run("insert into table " + tblName + " partition (ds = 'today') values (1)");
// Event 5, 6, 7
driver.run("insert into table " + tblName + " partition (ds = 'today') values (2)");
// Event 8, 9, 10
driver.run("insert into table " + tblName + " partition (ds) values (3, 'today')");
// Event 9, 10
driver.run("alter table " + tblName + " add partition (ds = 'yesterday')");
// Event 10, 11, 12
driver.run("insert into table " + tblName + " partition (ds = 'yesterday') values (2)");
// Event 12, 13, 14
driver.run("insert into table " + tblName + " partition (ds) values (3, 'yesterday')");
// Event 15, 16, 17
driver.run("insert into table " + tblName + " partition (ds) values (3, 'tomorrow')");
// Event 18
driver.run("alter table " + tblName + " drop partition (ds = 'tomorrow')");
// Event 19, 20, 21
driver.run("insert into table " + tblName + " partition (ds) values (42, 'todaytwo')");
// Event 22, 23, 24
driver.run("insert overwrite table " + tblName + " partition(ds='todaytwo') select c from " + tblName + " where 'ds'='today'");
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(24, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(1);
assertEquals(firstEventId + 2, event.getEventId());
assertEquals(EventType.ADD_PARTITION.toString(), event.getEventType());
event = rsp.getEvents().get(3);
assertEquals(firstEventId + 4, event.getEventId());
assertEquals(EventType.INSERT.toString(), event.getEventType());
// Parse the message field
verifyInsert(event, null, tblName);
event = rsp.getEvents().get(6);
assertEquals(firstEventId + 7, event.getEventId());
assertEquals(EventType.INSERT.toString(), event.getEventType());
// Parse the message field
verifyInsert(event, null, tblName);
event = rsp.getEvents().get(9);
assertEquals(firstEventId + 10, event.getEventId());
assertEquals(EventType.ADD_PARTITION.toString(), event.getEventType());
event = rsp.getEvents().get(10);
assertEquals(firstEventId + 11, event.getEventId());
assertEquals(EventType.INSERT.toString(), event.getEventType());
// Parse the message field
verifyInsert(event, null, tblName);
event = rsp.getEvents().get(13);
assertEquals(firstEventId + 14, event.getEventId());
assertEquals(EventType.INSERT.toString(), event.getEventType());
// Parse the message field
verifyInsert(event, null, tblName);
event = rsp.getEvents().get(16);
assertEquals(firstEventId + 17, event.getEventId());
assertEquals(EventType.ADD_PARTITION.toString(), event.getEventType());
event = rsp.getEvents().get(18);
assertEquals(firstEventId + 19, event.getEventId());
assertEquals(EventType.DROP_PARTITION.toString(), event.getEventType());
event = rsp.getEvents().get(19);
assertEquals(firstEventId + 20, event.getEventId());
assertEquals(EventType.ADD_PARTITION.toString(), event.getEventType());
event = rsp.getEvents().get(20);
assertEquals(firstEventId + 21, event.getEventId());
assertEquals(EventType.ALTER_PARTITION.toString(), event.getEventType());
assertTrue(event.getMessage().matches(".*\"ds\":\"todaytwo\".*"));
event = rsp.getEvents().get(21);
assertEquals(firstEventId + 22, event.getEventId());
assertEquals(EventType.INSERT.toString(), event.getEventType());
// replace-overwrite introduces no new files
assertTrue(event.getMessage().matches(".*\"files\":\\[\\].*"));
event = rsp.getEvents().get(22);
assertEquals(firstEventId + 23, event.getEventId());
assertEquals(EventType.ALTER_PARTITION.toString(), event.getEventType());
assertTrue(event.getMessage().matches(".*\"ds\":\"todaytwo\".*"));
event = rsp.getEvents().get(23);
assertEquals(firstEventId + 24, event.getEventId());
assertEquals(EventType.ALTER_PARTITION.toString(), event.getEventType());
assertTrue(event.getMessage().matches(".*\"ds\":\"todaytwo\".*"));
}
use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestDbNotificationListener method filter.
@Test
public void filter() throws Exception {
Database db = new Database("f1", "no description", "file:/tmp", emptyParameters);
msClient.createDatabase(db);
db = new Database("f2", "no description", "file:/tmp", emptyParameters);
msClient.createDatabase(db);
msClient.dropDatabase("f2");
IMetaStoreClient.NotificationFilter filter = new IMetaStoreClient.NotificationFilter() {
@Override
public boolean accept(NotificationEvent event) {
return event.getEventType().equals(EventType.DROP_DATABASE.toString());
}
};
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, filter);
assertEquals(1, rsp.getEventsSize());
assertEquals(firstEventId + 3, rsp.getEvents().get(0).getEventId());
}
use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestDbNotificationListener method insertTable.
@Test
public void insertTable() throws Exception {
String defaultDbName = "default";
String tblName = "inserttbl";
String tblOwner = "me";
String serdeLocation = "file:/tmp";
String fileAdded = "/warehouse/mytable/b1";
String checksumAdded = "1234";
FieldSchema col1 = new FieldSchema("col1", "int", "no comment");
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(col1);
SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
StorageDescriptor sd = new StorageDescriptor(cols, serdeLocation, "input", "output", false, 0, serde, null, null, emptyParameters);
Table table = new Table(tblName, defaultDbName, tblOwner, startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 1
msClient.createTable(table);
FireEventRequestData data = new FireEventRequestData();
InsertEventRequestData insertData = new InsertEventRequestData();
data.setInsertData(insertData);
insertData.addToFilesAdded(fileAdded);
insertData.addToFilesAddedChecksum(checksumAdded);
FireEventRequest rqst = new FireEventRequest(true, data);
rqst.setDbName(defaultDbName);
rqst.setTableName(tblName);
// Event 2
msClient.fireListenerEvent(rqst);
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(2, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(1);
assertEquals(firstEventId + 2, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.INSERT.toString(), event.getEventType());
assertEquals(defaultDbName, event.getDbName());
assertEquals(tblName, event.getTableName());
// Parse the message field
verifyInsert(event, defaultDbName, tblName);
// Parse the message field
InsertMessage insertMessage = md.getInsertMessage(event.getMessage());
assertEquals(defaultDbName, insertMessage.getDB());
assertEquals(tblName, insertMessage.getTable());
assertEquals(TableType.MANAGED_TABLE.toString(), insertMessage.getTableType());
// Verify the eventID was passed to the non-transactional listener
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.INSERT, firstEventId + 2);
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_TABLE, firstEventId + 1);
}
use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestDbNotificationListener method alterPartition.
@Test
public void alterPartition() throws Exception {
String defaultDbName = "default";
String tblName = "alterptn";
String tblOwner = "me";
String serdeLocation = "file:/tmp";
FieldSchema col1 = new FieldSchema("col1", "int", "no comment");
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(col1);
SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
StorageDescriptor sd = new StorageDescriptor(cols, serdeLocation, "input", "output", false, 0, serde, null, null, emptyParameters);
FieldSchema partCol1 = new FieldSchema("ds", "string", "no comment");
List<FieldSchema> partCols = new ArrayList<FieldSchema>();
List<String> partCol1Vals = Arrays.asList("today");
partCols.add(partCol1);
Table table = new Table(tblName, defaultDbName, tblOwner, startTime, startTime, 0, sd, partCols, emptyParameters, null, null, null);
// Event 1
msClient.createTable(table);
Partition partition = new Partition(partCol1Vals, defaultDbName, tblName, startTime, startTime, sd, emptyParameters);
// Event 2
msClient.add_partition(partition);
Partition newPart = new Partition(Arrays.asList("today"), defaultDbName, tblName, startTime, startTime + 1, sd, emptyParameters);
// Event 3
msClient.alter_partition(defaultDbName, tblName, newPart, null);
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(3, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(2);
assertEquals(firstEventId + 3, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.ALTER_PARTITION.toString(), event.getEventType());
assertEquals(defaultDbName, event.getDbName());
assertEquals(tblName, event.getTableName());
// Parse the message field
AlterPartitionMessage alterPtnMsg = md.getAlterPartitionMessage(event.getMessage());
assertEquals(defaultDbName, alterPtnMsg.getDB());
assertEquals(tblName, alterPtnMsg.getTable());
assertEquals(newPart, alterPtnMsg.getPtnObjAfter());
assertEquals(TableType.MANAGED_TABLE.toString(), alterPtnMsg.getTableType());
// Verify the eventID was passed to the non-transactional listener
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.ADD_PARTITION, firstEventId + 2);
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_TABLE, firstEventId + 1);
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
DummyRawStoreFailEvent.setEventSucceed(false);
try {
msClient.alter_partition(defaultDbName, tblName, newPart, null);
fail("Error: alter partition should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(3, rsp.getEventsSize());
}
Aggregations