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());
// 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());
}
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 createDatabase.
@Test
public void createDatabase() throws Exception {
String dbName = "createdb";
String dbName2 = "createdb2";
String dbLocationUri = "file:/tmp";
String dbDescription = "no description";
Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters);
msClient.createDatabase(db);
// Read notification from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(1, rsp.getEventsSize());
// Read event from notification
NotificationEvent event = rsp.getEvents().get(0);
assertEquals(firstEventId + 1, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.CREATE_DATABASE.toString(), event.getEventType());
assertEquals(dbName, event.getDbName());
assertNull(event.getTableName());
// Parse the message field
CreateDatabaseMessage createDbMsg = md.getCreateDatabaseMessage(event.getMessage());
assertEquals(dbName, createDbMsg.getDB());
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
DummyRawStoreFailEvent.setEventSucceed(false);
db = new Database(dbName2, dbDescription, dbLocationUri, emptyParameters);
try {
msClient.createDatabase(db);
fail("Error: create database should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(1, rsp.getEventsSize());
}
use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestDbNotificationListener method alterTable.
@Test
public void alterTable() throws Exception {
String defaultDbName = "default";
String tblName = "altertabletbl";
String tblOwner = "me";
String serdeLocation = "file:/tmp";
FieldSchema col1 = new FieldSchema("col1", "int", "no comment");
FieldSchema col2 = new FieldSchema("col2", "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, new ArrayList<FieldSchema>(), emptyParameters, null, null, null);
// Event 1
msClient.createTable(table);
cols.add(col2);
table = new Table(tblName, defaultDbName, tblOwner, startTime, startTime, 0, sd, new ArrayList<FieldSchema>(), emptyParameters, null, null, null);
// Event 2
msClient.alter_table(defaultDbName, tblName, table);
// 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.ALTER_TABLE.toString(), event.getEventType());
assertEquals(defaultDbName, event.getDbName());
assertEquals(tblName, event.getTableName());
AlterTableMessage alterTableMessage = md.getAlterTableMessage(event.getMessage());
assertEquals(table, alterTableMessage.getTableObjAfter());
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
DummyRawStoreFailEvent.setEventSucceed(false);
try {
msClient.alter_table(defaultDbName, tblName, table);
fail("Error: alter table should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(2, rsp.getEventsSize());
}
use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class DbNotificationListener method onCreateFunction.
/**
* @param fnEvent function event
* @throws MetaException
*/
@Override
public void onCreateFunction(CreateFunctionEvent fnEvent) throws MetaException {
Function fn = fnEvent.getFunction();
NotificationEvent event = new NotificationEvent(0, now(), EventType.CREATE_FUNCTION.toString(), msgFactory.buildCreateFunctionMessage(fn).toString());
event.setDbName(fn.getDbName());
process(event);
}
Aggregations