Search in sources :

Example 1 with DropTableMessage

use of org.apache.hive.hcatalog.messaging.DropTableMessage in project hive by apache.

the class TestNotificationListener method onMessage.

@Override
public void onMessage(Message msg) {
    String event;
    try {
        event = msg.getStringProperty(HCatConstants.HCAT_EVENT);
        String format = msg.getStringProperty(HCatConstants.HCAT_MESSAGE_FORMAT);
        String version = msg.getStringProperty(HCatConstants.HCAT_MESSAGE_VERSION);
        String messageBody = ((TextMessage) msg).getText();
        actualMessages.add(event);
        MessageDeserializer deserializer = MessageFactory.getDeserializer(format, version);
        if (event.equals(HCatConstants.HCAT_CREATE_DATABASE_EVENT)) {
            Assert.assertEquals("topic://" + HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX, msg.getJMSDestination().toString());
            CreateDatabaseMessage message = deserializer.getCreateDatabaseMessage(messageBody);
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof CreateDatabaseMessage);
            Assert.assertEquals("mydb", message2.getDB());
        } else if (event.equals(HCatConstants.HCAT_CREATE_TABLE_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb", msg.getJMSDestination().toString());
            CreateTableMessage message = deserializer.getCreateTableMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof CreateTableMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((CreateTableMessage) message2).getTable());
        } else if (event.equals(HCatConstants.HCAT_ADD_PARTITION_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb.mytbl", msg.getJMSDestination().toString());
            AddPartitionMessage message = deserializer.getAddPartitionMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(1, message.getPartitions().size());
            Assert.assertEquals("2011", message.getPartitions().get(0).get("b"));
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof AddPartitionMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((AddPartitionMessage) message2).getTable());
            Assert.assertEquals(1, ((AddPartitionMessage) message2).getPartitions().size());
            Assert.assertEquals("2011", ((AddPartitionMessage) message2).getPartitions().get(0).get("b"));
        } else if (event.equals(HCatConstants.HCAT_ALTER_PARTITION_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb.mytbl", msg.getJMSDestination().toString());
            // for alter partition events
            AlterPartitionMessage message = deserializer.getAlterPartitionMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(1, message.getKeyValues().size());
            Assert.assertTrue(message.getKeyValues().values().contains("2011"));
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof AlterPartitionMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((AlterPartitionMessage) message2).getTable());
            Assert.assertEquals(1, ((AlterPartitionMessage) message2).getKeyValues().size());
            Assert.assertTrue(((AlterPartitionMessage) message2).getKeyValues().values().contains("2011"));
        } else if (event.equals(HCatConstants.HCAT_DROP_PARTITION_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb.mytbl", msg.getJMSDestination().toString());
            DropPartitionMessage message = deserializer.getDropPartitionMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(1, message.getPartitions().size());
            Assert.assertEquals("2011", message.getPartitions().get(0).get("b"));
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof DropPartitionMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((DropPartitionMessage) message2).getTable());
            Assert.assertEquals(1, ((DropPartitionMessage) message2).getPartitions().size());
            Assert.assertEquals("2011", ((DropPartitionMessage) message2).getPartitions().get(0).get("b"));
        } else if (event.equals(HCatConstants.HCAT_DROP_TABLE_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb", msg.getJMSDestination().toString());
            DropTableMessage message = deserializer.getDropTableMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof DropTableMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((DropTableMessage) message2).getTable());
        } else if (event.equals(HCatConstants.HCAT_DROP_DATABASE_EVENT)) {
            Assert.assertEquals("topic://" + HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX, msg.getJMSDestination().toString());
            DropDatabaseMessage message = deserializer.getDropDatabaseMessage(messageBody);
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof DropDatabaseMessage);
            Assert.assertEquals("mydb", message2.getDB());
        } else if (event.equals(HCatConstants.HCAT_ALTER_TABLE_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb", msg.getJMSDestination().toString());
            AlterTableMessage message = deserializer.getAlterTableMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof AlterTableMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((AlterTableMessage) message2).getTable());
        } else if (event.equals(HCatConstants.HCAT_PARTITION_DONE_EVENT)) {
            // TODO: Fill in when PARTITION_DONE_EVENT is supported.
            Assert.assertTrue("Unexpected: HCAT_PARTITION_DONE_EVENT not supported (yet).", false);
        } else {
            Assert.assertTrue("Unexpected event-type: " + event, false);
        }
    } catch (JMSException e) {
        e.printStackTrace(System.err);
        assert false;
    } finally {
        messageReceivedSignal.countDown();
    }
}
Also used : MessageDeserializer(org.apache.hive.hcatalog.messaging.MessageDeserializer) CreateDatabaseMessage(org.apache.hive.hcatalog.messaging.CreateDatabaseMessage) CreateTableMessage(org.apache.hive.hcatalog.messaging.CreateTableMessage) JMSException(javax.jms.JMSException) HCatEventMessage(org.apache.hive.hcatalog.messaging.HCatEventMessage) DropTableMessage(org.apache.hive.hcatalog.messaging.DropTableMessage) DropPartitionMessage(org.apache.hive.hcatalog.messaging.DropPartitionMessage) DropDatabaseMessage(org.apache.hive.hcatalog.messaging.DropDatabaseMessage) AlterTableMessage(org.apache.hive.hcatalog.messaging.AlterTableMessage) AddPartitionMessage(org.apache.hive.hcatalog.messaging.AddPartitionMessage) TextMessage(javax.jms.TextMessage) AlterPartitionMessage(org.apache.hive.hcatalog.messaging.AlterPartitionMessage)

Example 2 with DropTableMessage

use of org.apache.hive.hcatalog.messaging.DropTableMessage in project hive by apache.

the class TestHCatClientNotification method dropTable.

// TODO - Currently no way to test alter table, as this interface doesn't support alter table
@Test
public void dropTable() throws Exception {
    String dbName = "default";
    String tableName = "hcatdroptable";
    HCatTable table = new HCatTable(dbName, tableName);
    table.cols(Arrays.asList(new HCatFieldSchema("onecol", TypeInfoFactory.stringTypeInfo, "")));
    hCatClient.createTable(HCatCreateTableDesc.create(table).build());
    hCatClient.dropTable(dbName, tableName, false);
    List<HCatNotificationEvent> events = hCatClient.getNextNotification(firstEventId, 0, null);
    assertEquals(2, events.size());
    HCatNotificationEvent event = events.get(1);
    assertEquals(firstEventId + 2, event.getEventId());
    assertTrue(event.getEventTime() >= startTime);
    assertEquals(HCatConstants.HCAT_DROP_TABLE_EVENT, event.getEventType());
    assertEquals(dbName, event.getDbName());
    assertEquals(tableName, event.getTableName());
    DropTableMessage dropTableMessage = md.getDropTableMessage(event.getMessage());
    assertEquals(dbName, dropTableMessage.getDB());
    assertEquals(tableName, dropTableMessage.getTable());
}
Also used : DropTableMessage(org.apache.hive.hcatalog.messaging.DropTableMessage) HCatFieldSchema(org.apache.hive.hcatalog.data.schema.HCatFieldSchema) Test(org.junit.Test)

Aggregations

DropTableMessage (org.apache.hive.hcatalog.messaging.DropTableMessage)2 JMSException (javax.jms.JMSException)1 TextMessage (javax.jms.TextMessage)1 HCatFieldSchema (org.apache.hive.hcatalog.data.schema.HCatFieldSchema)1 AddPartitionMessage (org.apache.hive.hcatalog.messaging.AddPartitionMessage)1 AlterPartitionMessage (org.apache.hive.hcatalog.messaging.AlterPartitionMessage)1 AlterTableMessage (org.apache.hive.hcatalog.messaging.AlterTableMessage)1 CreateDatabaseMessage (org.apache.hive.hcatalog.messaging.CreateDatabaseMessage)1 CreateTableMessage (org.apache.hive.hcatalog.messaging.CreateTableMessage)1 DropDatabaseMessage (org.apache.hive.hcatalog.messaging.DropDatabaseMessage)1 DropPartitionMessage (org.apache.hive.hcatalog.messaging.DropPartitionMessage)1 HCatEventMessage (org.apache.hive.hcatalog.messaging.HCatEventMessage)1 MessageDeserializer (org.apache.hive.hcatalog.messaging.MessageDeserializer)1 Test (org.junit.Test)1