Search in sources :

Example 1 with ListDatabasesResult

use of com.amazonaws.services.timestreamwrite.model.ListDatabasesResult in project aws-athena-query-federation by awslabs.

the class TimestreamMetadataHandler method doListSchemaNames.

@Override
public ListSchemasResponse doListSchemaNames(BlockAllocator blockAllocator, ListSchemasRequest request) throws Exception {
    List<String> schemaNames = new ArrayList<>();
    ListDatabasesRequest listDatabasesRequest = new ListDatabasesRequest();
    ListDatabasesResult nextResult = tsMeta.listDatabases(listDatabasesRequest);
    List<Database> nextDatabases = nextResult.getDatabases();
    while (!nextDatabases.isEmpty()) {
        nextDatabases.stream().forEach(next -> schemaNames.add(next.getDatabaseName()));
        if (nextResult.getNextToken() != null && !nextResult.getNextToken().isEmpty()) {
            listDatabasesRequest.setNextToken(nextResult.getNextToken());
            nextResult = tsMeta.listDatabases(listDatabasesRequest);
            nextDatabases = nextResult.getDatabases();
        } else {
            nextDatabases = Collections.EMPTY_LIST;
        }
    }
    return new ListSchemasResponse(request.getCatalogName(), schemaNames);
}
Also used : ListDatabasesResult(com.amazonaws.services.timestreamwrite.model.ListDatabasesResult) ArrayList(java.util.ArrayList) Database(com.amazonaws.services.timestreamwrite.model.Database) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) ListDatabasesRequest(com.amazonaws.services.timestreamwrite.model.ListDatabasesRequest)

Example 2 with ListDatabasesResult

use of com.amazonaws.services.timestreamwrite.model.ListDatabasesResult 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)

Aggregations

ListSchemasResponse (com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse)2 Database (com.amazonaws.services.timestreamwrite.model.Database)2 ListDatabasesRequest (com.amazonaws.services.timestreamwrite.model.ListDatabasesRequest)2 ListDatabasesResult (com.amazonaws.services.timestreamwrite.model.ListDatabasesResult)2 ArrayList (java.util.ArrayList)2 ListSchemasRequest (com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1