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"));
}
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);
}
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);
}
}
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()));
}
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);
}
Aggregations