use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestDbNotificationListener method createIndex.
@Test
public void createIndex() throws Exception {
String indexName = "createIndex";
String dbName = "default";
String tableName = "createIndexTable";
String indexTableName = tableName + "__" + indexName + "__";
int startTime = (int) (System.currentTimeMillis() / 1000);
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(new FieldSchema("col1", "int", ""));
SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
Map<String, String> params = new HashMap<String, String>();
params.put("key", "value");
StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 17, serde, Arrays.asList("bucketcol"), Arrays.asList(new Order("sortcol", 1)), params);
Table table = new Table(tableName, dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 1
msClient.createTable(table);
Index index = new Index(indexName, null, "default", tableName, startTime, startTime, indexTableName, sd, emptyParameters, false);
Table indexTable = new Table(indexTableName, dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 2, 3 (index table and index)
msClient.createIndex(index, indexTable);
// 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.CREATE_INDEX.toString(), event.getEventType());
assertEquals(dbName, event.getDbName());
// Parse the message field
CreateIndexMessage createIdxMessage = md.getCreateIndexMessage(event.getMessage());
assertEquals(dbName, createIdxMessage.getDB());
Index indexObj = createIdxMessage.getIndexObj();
assertEquals(dbName, indexObj.getDbName());
assertEquals(indexName, indexObj.getIndexName());
assertEquals(tableName, indexObj.getOrigTableName());
assertEquals(indexTableName, indexObj.getIndexTableName());
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
DummyRawStoreFailEvent.setEventSucceed(false);
index = new Index("createIndexTable2", null, "default", tableName, startTime, startTime, "createIndexTable2__createIndexTable2__", sd, emptyParameters, false);
Table indexTable2 = new Table("createIndexTable2__createIndexTable2__", dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
try {
msClient.createIndex(index, indexTable2);
fail("Error: create index 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 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 createTable.
@Test
public void createTable() throws Exception {
String defaultDbName = "default";
String tblName = "createtable";
String tblName2 = "createtable2";
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);
Table table = new Table(tblName, defaultDbName, tblOwner, startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
msClient.createTable(table);
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(1, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(0);
assertEquals(firstEventId + 1, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.CREATE_TABLE.toString(), event.getEventType());
assertEquals(defaultDbName, event.getDbName());
assertEquals(tblName, event.getTableName());
// Parse the message field
CreateTableMessage createTblMsg = md.getCreateTableMessage(event.getMessage());
assertEquals(defaultDbName, createTblMsg.getDB());
assertEquals(tblName, createTblMsg.getTable());
assertEquals(table, createTblMsg.getTableObj());
// 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);
DummyRawStoreFailEvent.setEventSucceed(false);
try {
msClient.createTable(table);
fail("Error: create table 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 dropDatabase.
@Test
public void dropDatabase() throws Exception {
String dbName = "dropdb";
String dbName2 = "dropdb2";
String dbLocationUri = "file:/tmp";
String dbDescription = "no description";
Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters);
msClient.createDatabase(db);
msClient.dropDatabase(dbName);
// Read notification from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
// Two events: one for create db and other for drop db
assertEquals(2, rsp.getEventsSize());
// Read event from notification
NotificationEvent event = rsp.getEvents().get(1);
assertEquals(firstEventId + 2, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.DROP_DATABASE.toString(), event.getEventType());
assertEquals(dbName, event.getDbName());
assertNull(event.getTableName());
// Parse the message field
DropDatabaseMessage dropDbMsg = md.getDropDatabaseMessage(event.getMessage());
assertEquals(dbName, dropDbMsg.getDB());
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
db = new Database(dbName2, dbDescription, dbLocationUri, emptyParameters);
msClient.createDatabase(db);
DummyRawStoreFailEvent.setEventSucceed(false);
try {
msClient.dropDatabase(dbName2);
fail("Error: drop database 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 dropTable.
@Test
public void dropTable() throws Exception {
String defaultDbName = "default";
String tblName = "droptbl";
String tblName2 = "droptbl2";
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);
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());
// 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());
}
Aggregations