Search in sources :

Example 26 with ListSchemasRequest

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

the class TimestreamMetadataHandlerTest method doListSchemaNames.

@Test
public void doListSchemaNames() throws Exception {
    logger.info("doListSchemaNames - enter");
    when(mockTsMeta.listDatabases(any(ListDatabasesRequest.class))).thenAnswer((InvocationOnMock invocation) -> {
        ListDatabasesRequest request = invocation.getArgumentAt(0, ListDatabasesRequest.class);
        String newNextToken = null;
        List<Database> databases = new ArrayList<>();
        if (request.getNextToken() == null) {
            for (int i = 0; i < 10; i++) {
                databases.add(new Database().withDatabaseName("database_" + i));
            }
            newNextToken = "1";
        } else if (request.getNextToken().equals("1")) {
            for (int i = 10; i < 100; i++) {
                databases.add(new Database().withDatabaseName("database_" + i));
            }
            newNextToken = "2";
        } else if (request.getNextToken().equals("2")) {
            for (int i = 100; i < 1000; i++) {
                databases.add(new Database().withDatabaseName("database_" + i));
            }
            newNextToken = null;
        }
        return new ListDatabasesResult().withDatabases(databases).withNextToken(newNextToken);
    });
    ListSchemasRequest req = new ListSchemasRequest(identity, "queryId", "default");
    ListSchemasResponse res = handler.doListSchemaNames(allocator, req);
    logger.info("doListSchemaNames - {}", res.getSchemas());
    assertEquals(1000, res.getSchemas().size());
    verify(mockTsMeta, times(3)).listDatabases(any(ListDatabasesRequest.class));
    Iterator<String> schemaItr = res.getSchemas().iterator();
    for (int i = 0; i < 1000; i++) {
        assertEquals("database_" + i, schemaItr.next());
    }
    logger.info("doListSchemaNames - exit");
}
Also used : ListDatabasesResult(com.amazonaws.services.timestreamwrite.model.ListDatabasesResult) ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Database(com.amazonaws.services.timestreamwrite.model.Database) ArrayList(java.util.ArrayList) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) ListDatabasesRequest(com.amazonaws.services.timestreamwrite.model.ListDatabasesRequest) Test(org.junit.Test)

Example 27 with ListSchemasRequest

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

the class ExampleMetadataHandlerTest method doListSchemaNames.

@Test
public void doListSchemaNames() {
    if (!enableTests) {
        // We do this because until you complete the tutorial these tests will fail. When you attempt to publis
        // using ../toos/publish.sh ...  it will set the publishing flag and force these tests. This is how we
        // avoid breaking the build but still have a useful tutorial. We are also duplicateing this block
        // on purpose since this is a somewhat odd pattern.
        logger.info("doListSchemaNames: Tests are disabled, to enable them set the 'publishing' environment variable " + "using maven clean install -Dpublishing=true");
        return;
    }
    logger.info("doListSchemas - enter");
    ListSchemasRequest req = new ListSchemasRequest(fakeIdentity(), "queryId", "default");
    ListSchemasResponse res = handler.doListSchemaNames(allocator, req);
    logger.info("doListSchemas - {}", res.getSchemas());
    assertFalse(res.getSchemas().isEmpty());
    logger.info("doListSchemas - exit");
}
Also used : ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) Test(org.junit.Test)

Example 28 with ListSchemasRequest

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

the class LambdaMetadataProvider method listSchemas.

/**
 * This method builds and executes a ListSchemasRequest against the specified Lambda function.
 *
 * @param catalog the catalog name to be passed to Lambda
 * @param metadataFunction the name of the Lambda function to call
 * @param identity the identity of the caller
 * @return the response
 */
public static ListSchemasResponse listSchemas(String catalog, String metadataFunction, FederatedIdentity identity) {
    String queryId = generateQueryId();
    log.info("Submitting ListSchemasRequest with ID " + queryId);
    try (ListSchemasRequest request = new ListSchemasRequest(identity, queryId, catalog)) {
        log.info("Submitting request: {}", request);
        ListSchemasResponse response = (ListSchemasResponse) getService(metadataFunction, identity, catalog).call(request);
        log.info("Received response: {}", response);
        return response;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse)

Example 29 with ListSchemasRequest

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

the class AwsCmdbMetadataHandlerTest method doListSchemaNames.

@Test
public void doListSchemaNames() {
    ListSchemasRequest request = new ListSchemasRequest(identity, queryId, catalog);
    ListSchemasResponse response = handler.doListSchemaNames(blockAllocator, request);
    assertEquals(2, response.getSchemas().size());
    assertTrue(response.getSchemas().contains("schema1"));
    assertTrue(response.getSchemas().contains("schema2"));
}
Also used : ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) Test(org.junit.Test)

Example 30 with ListSchemasRequest

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

the class ImpalaMuxMetadataHandlerTest method doListSchemaNames.

@Test
public void doListSchemaNames() {
    ListSchemasRequest listSchemasRequest = Mockito.mock(ListSchemasRequest.class);
    Mockito.when(listSchemasRequest.getCatalogName()).thenReturn("metaImpala");
    this.jdbcMetadataHandler.doListSchemaNames(this.allocator, listSchemasRequest);
    Mockito.verify(this.impalaMetadataHandler, Mockito.times(1)).doListSchemaNames(Mockito.eq(this.allocator), Mockito.eq(listSchemasRequest));
}
Also used : ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) Test(org.junit.Test)

Aggregations

ListSchemasRequest (com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest)31 Test (org.junit.Test)29 ListSchemasResponse (com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse)15 ArrayList (java.util.ArrayList)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 FederationRequest (com.amazonaws.athena.connector.lambda.request.FederationRequest)2 Database (com.amazonaws.services.glue.model.Database)2 GetDatabasesResult (com.amazonaws.services.glue.model.GetDatabasesResult)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 BlockAllocatorImpl (com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl)1 TypedSerDeTest (com.amazonaws.athena.connector.lambda.serde.TypedSerDeTest)1 GetDatabasesRequest (com.amazonaws.services.glue.model.GetDatabasesRequest)1 DescribeLogGroupsRequest (com.amazonaws.services.logs.model.DescribeLogGroupsRequest)1 DescribeLogGroupsResult (com.amazonaws.services.logs.model.DescribeLogGroupsResult)1 LogGroup (com.amazonaws.services.logs.model.LogGroup)1 Database (com.amazonaws.services.timestreamwrite.model.Database)1 ListDatabasesRequest (com.amazonaws.services.timestreamwrite.model.ListDatabasesRequest)1