use of org.apache.hadoop.hive.metastore.messaging.DropTableMessage in project hive by apache.
the class DbNotificationListener method onDropTable.
/**
* @param tableEvent table event.
* @throws MetaException
*/
@Override
public void onDropTable(DropTableEvent tableEvent) throws MetaException {
Table t = tableEvent.getTable();
DropTableMessage msg = MessageBuilder.getInstance().buildDropTableMessage(t);
NotificationEvent event = new NotificationEvent(0, now(), EventType.DROP_TABLE.toString(), msgEncoder.getSerializer().serialize(msg));
event.setCatName(t.isSetCatName() ? t.getCatName() : DEFAULT_CATALOG_NAME);
event.setDbName(t.getDbName());
event.setTableName(t.getTableName());
process(event, tableEvent);
}
use of org.apache.hadoop.hive.metastore.messaging.DropTableMessage in project hive by apache.
the class DropTableHandler method handle.
@Override
public List<Task<?>> handle(Context context) throws SemanticException {
String actualDbName;
String actualTblName;
if (context.dmd.getDumpType() == DumpType.EVENT_RENAME_DROP_TABLE) {
AlterTableMessage msg = deserializer.getAlterTableMessage(context.dmd.getPayload());
actualDbName = context.isDbNameEmpty() ? msg.getDB() : context.dbName;
actualTblName = msg.getTable();
} else {
DropTableMessage msg = deserializer.getDropTableMessage(context.dmd.getPayload());
actualDbName = context.isDbNameEmpty() ? msg.getDB() : context.dbName;
actualTblName = msg.getTable();
}
DropTableDesc dropTableDesc = new DropTableDesc(actualDbName + "." + actualTblName, true, true, context.eventOnlyReplicationSpec(), false);
Task<DDLWork> dropTableTask = TaskFactory.get(new DDLWork(readEntitySet, writeEntitySet, dropTableDesc, true, context.getDumpDirectory(), context.getMetricCollector()), context.hiveConf);
context.log.debug("Added drop tbl task : {}:{}", dropTableTask.getId(), dropTableDesc.getTableName());
updatedMetadata.set(context.dmd.getEventTo().toString(), actualDbName, null, null);
return Collections.singletonList(dropTableTask);
}
use of org.apache.hadoop.hive.metastore.messaging.DropTableMessage in project hive by apache.
the class TestDbNotificationListener method dropTable.
@Test
public void dropTable() throws Exception {
String defaultDbName = "default";
String tblName = "droptbl";
String tblName2 = "droptbl2";
String tblOwner = "me";
String serdeLocation = testTempDir;
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);
// Event 2
msClient.dropTable(defaultDbName, tblName);
// 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.DROP_TABLE.toString(), event.getEventType());
assertEquals(defaultDbName, event.getDbName());
assertEquals(tblName, event.getTableName());
// Parse the message field
DropTableMessage dropTblMsg = md.getDropTableMessage(event.getMessage());
assertEquals(defaultDbName, dropTblMsg.getDB());
assertEquals(tblName, dropTblMsg.getTable());
assertEquals(TableType.MANAGED_TABLE.toString(), dropTblMsg.getTableType());
Table tableObj = dropTblMsg.getTableObj();
assertEquals(table.getDbName(), tableObj.getDbName());
assertEquals(table.getTableName(), tableObj.getTableName());
assertEquals(table.getOwner(), tableObj.getOwner());
assertEquals(table.getParameters(), tableObj.getParameters());
assertEquals(TableType.MANAGED_TABLE.toString(), tableObj.getTableType());
// Verify the eventID was passed to the non-transactional listener
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.DROP_TABLE, 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
table = new Table(tblName2, defaultDbName, tblOwner, startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
msClient.createTable(table);
DummyRawStoreFailEvent.setEventSucceed(false);
try {
msClient.dropTable(defaultDbName, tblName2);
fail("Error: drop table should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(3, rsp.getEventsSize());
testEventCounts(defaultDbName, firstEventId, null, null, 3);
}
Aggregations