Search in sources :

Example 1 with DropTableMessage

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);
}
Also used : DropTableMessage(org.apache.hadoop.hive.metastore.messaging.DropTableMessage) Table(org.apache.hadoop.hive.metastore.api.Table) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent)

Example 2 with DropTableMessage

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);
}
Also used : DropTableMessage(org.apache.hadoop.hive.metastore.messaging.DropTableMessage) DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) AlterTableMessage(org.apache.hadoop.hive.metastore.messaging.AlterTableMessage) DropTableDesc(org.apache.hadoop.hive.ql.ddl.table.drop.DropTableDesc)

Example 3 with DropTableMessage

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);
}
Also used : NotificationEventResponse(org.apache.hadoop.hive.metastore.api.NotificationEventResponse) DropTableMessage(org.apache.hadoop.hive.metastore.messaging.DropTableMessage) Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) ArrayList(java.util.ArrayList) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) Test(org.junit.Test)

Aggregations

DropTableMessage (org.apache.hadoop.hive.metastore.messaging.DropTableMessage)3 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)2 Table (org.apache.hadoop.hive.metastore.api.Table)2 ArrayList (java.util.ArrayList)1 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NotificationEventResponse (org.apache.hadoop.hive.metastore.api.NotificationEventResponse)1 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)1 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)1 AlterTableMessage (org.apache.hadoop.hive.metastore.messaging.AlterTableMessage)1 DDLWork (org.apache.hadoop.hive.ql.ddl.DDLWork)1 DropTableDesc (org.apache.hadoop.hive.ql.ddl.table.drop.DropTableDesc)1 Test (org.junit.Test)1