Search in sources :

Example 21 with ListSchemasResponse

use of com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse 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 22 with ListSchemasResponse

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

the class CloudwatchMetadataHandler method doListSchemaNames.

/**
 * List LogGroups in your Cloudwatch account treating each as a 'schema' (aka database)
 *
 * @see MetadataHandler
 */
@Override
public ListSchemasResponse doListSchemaNames(BlockAllocator blockAllocator, ListSchemasRequest listSchemasRequest) throws TimeoutException {
    DescribeLogGroupsRequest request = new DescribeLogGroupsRequest();
    DescribeLogGroupsResult result;
    List<String> schemas = new ArrayList<>();
    do {
        if (schemas.size() > MAX_RESULTS) {
            throw new RuntimeException("Too many log groups, exceeded max metadata results for schema count.");
        }
        result = invoker.invoke(() -> awsLogs.describeLogGroups(request));
        result.getLogGroups().forEach(next -> schemas.add(next.getLogGroupName().toLowerCase()));
        request.setNextToken(result.getNextToken());
        logger.info("doListSchemaNames: Listing log groups {} {}", result.getNextToken(), schemas.size());
    } while (result.getNextToken() != null);
    return new ListSchemasResponse(listSchemasRequest.getCatalogName(), schemas);
}
Also used : DescribeLogGroupsResult(com.amazonaws.services.logs.model.DescribeLogGroupsResult) ArrayList(java.util.ArrayList) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) DescribeLogGroupsRequest(com.amazonaws.services.logs.model.DescribeLogGroupsRequest)

Example 23 with ListSchemasResponse

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

the class DocDBMetadataHandler method doListSchemaNames.

/**
 * List databases in your DocumentDB instance treating each as a 'schema' (aka database)
 *
 * @see GlueMetadataHandler
 */
@Override
public ListSchemasResponse doListSchemaNames(BlockAllocator blockAllocator, ListSchemasRequest request) {
    List<String> schemas = new ArrayList<>();
    MongoClient client = getOrCreateConn(request);
    try (MongoCursor<String> itr = client.listDatabaseNames().iterator()) {
        while (itr.hasNext()) {
            schemas.add(itr.next());
        }
        return new ListSchemasResponse(request.getCatalogName(), schemas);
    }
}
Also used : MongoClient(com.mongodb.client.MongoClient) ArrayList(java.util.ArrayList) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse)

Example 24 with ListSchemasResponse

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

the class DocDBMetadataHandlerTest method doListSchemaNames.

@Test
public void doListSchemaNames() {
    List<String> schemaNames = new ArrayList<>();
    schemaNames.add("schema1");
    schemaNames.add("schema2");
    schemaNames.add("schema3");
    when(mockClient.listDatabaseNames()).thenReturn(StubbingCursor.iterate(schemaNames));
    ListSchemasRequest req = new ListSchemasRequest(IDENTITY, QUERY_ID, DEFAULT_CATALOG);
    ListSchemasResponse res = handler.doListSchemaNames(allocator, req);
    logger.info("doListSchemas - {}", res.getSchemas());
    assertEquals(schemaNames, new ArrayList<>(res.getSchemas()));
}
Also used : ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) Test(org.junit.Test)

Example 25 with ListSchemasResponse

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

the class GlueMetadataHandler method doListSchemaNames.

/**
 * Returns a list of schemas (aka databases) from AWS Glue DataCatalog with optional filtering.
 *
 * @param blockAllocator Tool for creating and managing Apache Arrow Blocks.
 * @param request Provides details on who made the request and which Athena catalog they are querying.
 * @param filter The DatabaseFilter to apply to all schemas (aka databases) before adding them to the results list.
 * @return The ListSchemasResponse which mostly contains the list of schemas (aka databases).
 */
protected ListSchemasResponse doListSchemaNames(BlockAllocator blockAllocator, ListSchemasRequest request, DatabaseFilter filter) throws Exception {
    GetDatabasesRequest getDatabasesRequest = new GetDatabasesRequest();
    getDatabasesRequest.setCatalogId(getCatalog(request));
    List<String> schemas = new ArrayList<>();
    String nextToken = null;
    do {
        getDatabasesRequest.setNextToken(nextToken);
        GetDatabasesResult result = awsGlue.getDatabases(getDatabasesRequest);
        for (Database next : result.getDatabaseList()) {
            if (filter == null || filter.filter(next)) {
                schemas.add(next.getName());
            }
        }
        nextToken = result.getNextToken();
    } while (nextToken != null);
    return new ListSchemasResponse(request.getCatalogName(), schemas);
}
Also used : ArrayList(java.util.ArrayList) GetDatabasesResult(com.amazonaws.services.glue.model.GetDatabasesResult) Database(com.amazonaws.services.glue.model.Database) GetDatabasesRequest(com.amazonaws.services.glue.model.GetDatabasesRequest) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse)

Aggregations

ListSchemasResponse (com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse)26 ListSchemasRequest (com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest)16 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)11 GetSplitsResponse (com.amazonaws.athena.connector.lambda.metadata.GetSplitsResponse)3 GetTableLayoutResponse (com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutResponse)3 GetTableResponse (com.amazonaws.athena.connector.lambda.metadata.GetTableResponse)3 ListTablesResponse (com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse)3 Database (com.amazonaws.services.glue.model.Database)3 GetDatabasesResult (com.amazonaws.services.glue.model.GetDatabasesResult)3 BlockAllocatorImpl (com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl)2 TableName (com.amazonaws.athena.connector.lambda.domain.TableName)2 ReadRecordsResponse (com.amazonaws.athena.connector.lambda.records.ReadRecordsResponse)2 GetDatabasesRequest (com.amazonaws.services.glue.model.GetDatabasesRequest)2 DescribeLogGroupsRequest (com.amazonaws.services.logs.model.DescribeLogGroupsRequest)2 DescribeLogGroupsResult (com.amazonaws.services.logs.model.DescribeLogGroupsResult)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 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2