Search in sources :

Example 16 with ListSchemasResponse

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

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

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

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

the class ConnectorValidator method showDatabases.

private static Collection<String> showDatabases(TestConfig testConfig) {
    ListSchemasResponse schemasResponse = LambdaMetadataProvider.listSchemas(testConfig.getCatalogId(), testConfig.getMetadataFunction(), testConfig.getIdentity());
    final Collection<String> schemas = schemasResponse.getSchemas();
    log.info("Found databases: " + schemas);
    requireNonNull(schemas, "Returned collection of schemas was null!");
    checkState(!schemas.isEmpty(), "No schemas were returned!");
    List<String> notLower = schemas.stream().filter(s -> !s.equals(s.toLowerCase())).collect(Collectors.toList());
    checkState(notLower.isEmpty(), "All returned schemas must be lowercase! Found these non-lowercase schemas: " + notLower);
    return schemas;
}
Also used : GetSplitsResponse(com.amazonaws.athena.connector.lambda.metadata.GetSplitsResponse) Schema(org.apache.arrow.vector.types.pojo.Schema) Options(org.apache.commons.cli.Options) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) HelpFormatter(org.apache.commons.cli.HelpFormatter) DefaultParser(org.apache.commons.cli.DefaultParser) ArrayList(java.util.ArrayList) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Objects.requireNonNull(java.util.Objects.requireNonNull) CommandLine(org.apache.commons.cli.CommandLine) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) FederatedIdentity(com.amazonaws.athena.connector.lambda.security.FederatedIdentity) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Collection(java.util.Collection) Split(com.amazonaws.athena.connector.lambda.domain.Split) ReadRecordsResponse(com.amazonaws.athena.connector.lambda.records.ReadRecordsResponse) Set(java.util.Set) BlockUtils.rowToString(com.amazonaws.athena.connector.lambda.data.BlockUtils.rowToString) Field(org.apache.arrow.vector.types.pojo.Field) Collectors(java.util.stream.Collectors) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Constraints(com.amazonaws.athena.connector.lambda.domain.predicate.Constraints) GetTableLayoutResponse(com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutResponse) List(java.util.List) ConstraintParser.parseConstraints(com.amazonaws.athena.connector.validation.ConstraintParser.parseConstraints) ParseException(org.apache.commons.cli.ParseException) Optional(java.util.Optional) Collections(java.util.Collections) GetTableResponse(com.amazonaws.athena.connector.lambda.metadata.GetTableResponse) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) BlockUtils.rowToString(com.amazonaws.athena.connector.lambda.data.BlockUtils.rowToString)

Example 20 with ListSchemasResponse

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

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