Search in sources :

Example 1 with GetTableRequest

use of com.amazonaws.athena.connector.lambda.metadata.GetTableRequest in project aws-athena-query-federation by awslabs.

the class ExampleMetadataHandlerTest method doGetTableFail.

@Test(expected = LambdaFunctionException.class)
public void doGetTableFail() {
    try {
        logger.info("doGetTableFail - enter");
        GetTableRequest req = new GetTableRequest(IdentityUtil.fakeIdentity(), "queryId", "default", new TableName("lambda", "fake"));
        metadataHandler.doGetTable(allocator, req);
    } catch (Exception ex) {
        logger.info("doGetTableFail: ", ex);
        throw new LambdaFunctionException(ex.getMessage(), false, "repackaged");
    }
}
Also used : GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) LambdaFunctionException(com.amazonaws.services.lambda.invoke.LambdaFunctionException) LambdaFunctionException(com.amazonaws.services.lambda.invoke.LambdaFunctionException) Test(org.junit.Test)

Example 2 with GetTableRequest

use of com.amazonaws.athena.connector.lambda.metadata.GetTableRequest in project aws-athena-query-federation by awslabs.

the class CompositeHandlerTest method doGetTable.

@Test
public void doGetTable() throws Exception {
    GetTableRequest req = mock(GetTableRequest.class);
    when(req.getRequestType()).thenReturn(MetadataRequestType.GET_TABLE);
    compositeHandler.handleRequest(allocator, req, new ByteArrayOutputStream(), objectMapper);
    verify(mockMetadataHandler, times(1)).doGetTable(any(BlockAllocatorImpl.class), any(GetTableRequest.class));
}
Also used : GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 3 with GetTableRequest

use of com.amazonaws.athena.connector.lambda.metadata.GetTableRequest in project aws-athena-query-federation by awslabs.

the class GlueMetadataHandlerTest method testGetCatalog.

@Test
public void testGetCatalog() {
    // Catalog should be the account from the request
    MetadataRequest req = new GetTableRequest(IdentityUtil.fakeIdentity(), queryId, catalog, new TableName(schema, table));
    String catalog = handler.getCatalog(req);
    assertEquals(IdentityUtil.fakeIdentity().getAccount(), catalog);
    // Catalog should be the account from the lambda context's function arn
    when(mockContext.getInvokedFunctionArn()).thenReturn("arn:aws:lambda:us-east-1:012345678912:function:athena-123");
    req.setContext(mockContext);
    catalog = handler.getCatalog(req);
    assertEquals("012345678912", catalog);
    // Catalog should be the account from the request since function arn is invalid
    when(mockContext.getInvokedFunctionArn()).thenReturn("arn:aws:lambda:us-east-1:012345678912:function:");
    req.setContext(mockContext);
    catalog = handler.getCatalog(req);
    assertEquals(IdentityUtil.fakeIdentity().getAccount(), catalog);
    // Catalog should be the account from the request since function arn is null
    when(mockContext.getInvokedFunctionArn()).thenReturn(null);
    req.setContext(mockContext);
    catalog = handler.getCatalog(req);
    assertEquals(IdentityUtil.fakeIdentity().getAccount(), catalog);
}
Also used : GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) GlueMetadataHandler.getSourceTableName(com.amazonaws.athena.connector.lambda.handlers.GlueMetadataHandler.getSourceTableName) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) MetadataRequest(com.amazonaws.athena.connector.lambda.metadata.MetadataRequest) Test(org.junit.Test)

Example 4 with GetTableRequest

use of com.amazonaws.athena.connector.lambda.metadata.GetTableRequest in project aws-athena-query-federation by awslabs.

the class ExampleMetadataHandlerTest method doGetTable.

@Test
public void doGetTable() {
    logger.info("doGetTable - enter");
    GetTableRequest req = new GetTableRequest(IdentityUtil.fakeIdentity(), "queryId", "default", new TableName("custom_source", "fake_table"));
    ObjectMapperUtil.assertSerialization(req);
    GetTableResponse res = metadataHandler.doGetTable(allocator, req);
    ObjectMapperUtil.assertSerialization(res);
    assertTrue(res.getSchema().getFields().size() > 0);
    assertTrue(res.getSchema().getCustomMetadata().size() > 0);
    logger.info("doGetTable - {}", res);
    logger.info("doGetTable - exit");
}
Also used : GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) GetTableResponse(com.amazonaws.athena.connector.lambda.metadata.GetTableResponse) Test(org.junit.Test)

Example 5 with GetTableRequest

use of com.amazonaws.athena.connector.lambda.metadata.GetTableRequest in project aws-athena-query-federation by awslabs.

the class GetTableRequestSerDeTest method deserialize.

@Test
public void deserialize() throws IOException {
    logger.info("deserialize: enter");
    InputStream input = new ByteArrayInputStream(expectedSerDeText.getBytes());
    GetTableRequest actual = (GetTableRequest) mapper.readValue(input, FederationRequest.class);
    logger.info("deserialize: deserialized[{}]", actual);
    assertEquals(expected, actual);
    logger.info("deserialize: exit");
}
Also used : GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FederationRequest(com.amazonaws.athena.connector.lambda.request.FederationRequest) TypedSerDeTest(com.amazonaws.athena.connector.lambda.serde.TypedSerDeTest) Test(org.junit.Test)

Aggregations

GetTableRequest (com.amazonaws.athena.connector.lambda.metadata.GetTableRequest)51 Test (org.junit.Test)48 GetTableResponse (com.amazonaws.athena.connector.lambda.metadata.GetTableResponse)33 TableName (com.amazonaws.athena.connector.lambda.domain.TableName)30 ArrayList (java.util.ArrayList)13 GetTableResult (com.amazonaws.services.glue.model.GetTableResult)11 Column (com.amazonaws.services.glue.model.Column)10 Schema (org.apache.arrow.vector.types.pojo.Schema)10 StorageDescriptor (com.amazonaws.services.glue.model.StorageDescriptor)9 Table (com.amazonaws.services.glue.model.Table)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 SchemaBuilder (com.amazonaws.athena.connector.lambda.data.SchemaBuilder)7 Constraints (com.amazonaws.athena.connector.lambda.domain.predicate.Constraints)7 HashMap (java.util.HashMap)7 BlockAllocatorImpl (com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl)6 ResultSet (java.sql.ResultSet)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Field (org.apache.arrow.vector.types.pojo.Field)6 ReadRecordsRequest (com.amazonaws.athena.connector.lambda.records.ReadRecordsRequest)5 ReadRecordsResponse (com.amazonaws.athena.connector.lambda.records.ReadRecordsResponse)4