Search in sources :

Example 1 with CreateFunctionMessage

use of org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage in project hive by apache.

the class CreateFunctionHandler method handle.

@Override
public void handle(Context withinContext) throws Exception {
    CreateFunctionMessage createFunctionMessage = deserializer.getCreateFunctionMessage(event.getMessage());
    LOG.info("Processing#{} CREATE_MESSAGE message : {}", fromEventId(), event.getMessage());
    Path metadataPath = new Path(withinContext.eventRoot, EximUtil.METADATA_NAME);
    FileSystem fileSystem = metadataPath.getFileSystem(withinContext.hiveConf);
    try (JsonWriter jsonWriter = new JsonWriter(fileSystem, metadataPath)) {
        new FunctionSerializer(createFunctionMessage.getFunctionObj(), withinContext.hiveConf).writeTo(jsonWriter, withinContext.replicationSpec);
    }
    withinContext.createDmd(this).write();
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) CreateFunctionMessage(org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage) FunctionSerializer(org.apache.hadoop.hive.ql.parse.repl.dump.io.FunctionSerializer) JsonWriter(org.apache.hadoop.hive.ql.parse.repl.dump.io.JsonWriter)

Example 2 with CreateFunctionMessage

use of org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage in project hive by apache.

the class TestDbNotificationListener method createFunction.

@Test
public void createFunction() throws Exception {
    String defaultDbName = "default";
    String funcName = "createfunction";
    String funcName2 = "createfunction2";
    String ownerName = "me";
    String funcClass = "o.a.h.h.createfunc";
    String funcClass2 = "o.a.h.h.createfunc2";
    String funcResource = "file:/tmp/somewhere";
    String funcResource2 = "file:/tmp/somewhere2";
    Function func = new Function(funcName, defaultDbName, funcClass, ownerName, PrincipalType.USER, startTime, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, funcResource)));
    // Event 1
    msClient.createFunction(func);
    // 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_FUNCTION.toString(), event.getEventType());
    assertEquals(defaultDbName, event.getDbName());
    // Parse the message field
    CreateFunctionMessage createFuncMsg = md.getCreateFunctionMessage(event.getMessage());
    assertEquals(defaultDbName, createFuncMsg.getDB());
    Function funcObj = createFuncMsg.getFunctionObj();
    assertEquals(defaultDbName, funcObj.getDbName());
    assertEquals(funcName, funcObj.getFunctionName());
    assertEquals(funcClass, funcObj.getClassName());
    assertEquals(ownerName, funcObj.getOwnerName());
    assertEquals(FunctionType.JAVA, funcObj.getFunctionType());
    assertEquals(1, funcObj.getResourceUrisSize());
    assertEquals(ResourceType.JAR, funcObj.getResourceUris().get(0).getResourceType());
    assertEquals(funcResource, funcObj.getResourceUris().get(0).getUri());
    // Verify the eventID was passed to the non-transactional listener
    MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_FUNCTION, firstEventId + 1);
    // When hive.metastore.transactional.event.listeners is set,
    // a failed event should not create a new notification
    DummyRawStoreFailEvent.setEventSucceed(false);
    func = new Function(funcName2, defaultDbName, funcClass2, ownerName, PrincipalType.USER, startTime, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, funcResource2)));
    try {
        msClient.createFunction(func);
        fail("Error: create function should've failed");
    } catch (Exception ex) {
    // expected
    }
    rsp = msClient.getNextNotification(firstEventId, 0, null);
    assertEquals(1, rsp.getEventsSize());
}
Also used : NotificationEventResponse(org.apache.hadoop.hive.metastore.api.NotificationEventResponse) Function(org.apache.hadoop.hive.metastore.api.Function) ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri) CreateFunctionMessage(org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) Test(org.junit.Test)

Aggregations

CreateFunctionMessage (org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage)2 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 Function (org.apache.hadoop.hive.metastore.api.Function)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)1 NotificationEventResponse (org.apache.hadoop.hive.metastore.api.NotificationEventResponse)1 ResourceUri (org.apache.hadoop.hive.metastore.api.ResourceUri)1 FunctionSerializer (org.apache.hadoop.hive.ql.parse.repl.dump.io.FunctionSerializer)1 JsonWriter (org.apache.hadoop.hive.ql.parse.repl.dump.io.JsonWriter)1 Test (org.junit.Test)1