Search in sources :

Example 6 with ListTablesResponse

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

the class ListTablesResponseSerDeTest method deserialize.

@Test
public void deserialize() throws IOException {
    logger.info("deserialize: enter");
    InputStream input = new ByteArrayInputStream(expectedSerDeText.getBytes());
    ListTablesResponse actual = (ListTablesResponse) mapper.readValue(input, FederationResponse.class);
    logger.info("deserialize: deserialized[{}]", actual);
    assertEquals(expected, actual);
    logger.info("deserialize: exit");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse) FederationResponse(com.amazonaws.athena.connector.lambda.request.FederationResponse) TypedSerDeTest(com.amazonaws.athena.connector.lambda.serde.TypedSerDeTest) Test(org.junit.Test)

Example 7 with ListTablesResponse

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

the class JdbcMetadataHandlerTest method doListTables.

@Test
public void doListTables() throws SQLException {
    String[] schema = { "TABLE_SCHEM", "TABLE_NAME" };
    Object[][] values = { { "testSchema", "testTable" }, { "testSchema", "testtable2" } };
    TableName[] expected = { new TableName("testSchema", "testTable"), new TableName("testSchema", "testtable2") };
    AtomicInteger rowNumber = new AtomicInteger(-1);
    ResultSet resultSet = mockResultSet(schema, values, rowNumber);
    Mockito.when(connection.getMetaData().getTables("testCatalog", "testSchema", null, new String[] { "TABLE", "VIEW", "EXTERNAL TABLE" })).thenReturn(resultSet);
    Mockito.when(connection.getCatalog()).thenReturn("testCatalog");
    ListTablesResponse listTablesResponse = this.jdbcMetadataHandler.doListTables(this.blockAllocator, new ListTablesRequest(this.federatedIdentity, "testQueryId", "testCatalog", "testSchema", null, UNLIMITED_PAGE_SIZE_VALUE));
    Assert.assertArrayEquals(expected, listTablesResponse.getTables().toArray());
}
Also used : TableName(com.amazonaws.athena.connector.lambda.domain.TableName) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet) ListTablesRequest(com.amazonaws.athena.connector.lambda.metadata.ListTablesRequest) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse) Test(org.junit.Test)

Example 8 with ListTablesResponse

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

the class NeptuneMetadataHandlerTest method doListTables.

@Test
public void doListTables() {
    logger.info("doListTables - enter");
    List<Table> tables = new ArrayList<Table>();
    Table table1 = new Table();
    table1.setName("table1");
    Table table2 = new Table();
    table2.setName("table2");
    Table table3 = new Table();
    table3.setName("table3");
    tables.add(table1);
    tables.add(table2);
    tables.add(table3);
    GetTablesResult tableResult = new GetTablesResult();
    tableResult.setTableList(tables);
    ListTablesRequest req = new ListTablesRequest(IDENTITY, "queryId", "default", "default", null, UNLIMITED_PAGE_SIZE_VALUE);
    when(glue.getTables(any(GetTablesRequest.class))).thenReturn(tableResult);
    ListTablesResponse res = handler.doListTables(allocator, req);
    logger.info("doListTables - {}", res.getTables());
    assertFalse(res.getTables().isEmpty());
    logger.info("doListTables - exit");
}
Also used : Table(com.amazonaws.services.glue.model.Table) GetTablesResult(com.amazonaws.services.glue.model.GetTablesResult) ArrayList(java.util.ArrayList) ListTablesRequest(com.amazonaws.athena.connector.lambda.metadata.ListTablesRequest) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse) GetTablesRequest(com.amazonaws.services.glue.model.GetTablesRequest) Test(org.junit.Test)

Example 9 with ListTablesResponse

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

the class TimestreamMetadataHandler method doListTables.

@Override
public ListTablesResponse doListTables(BlockAllocator blockAllocator, ListTablesRequest request) throws Exception {
    List<TableName> tableNames = new ArrayList<>();
    com.amazonaws.services.timestreamwrite.model.ListTablesRequest listTablesRequest = new com.amazonaws.services.timestreamwrite.model.ListTablesRequest().withDatabaseName(request.getSchemaName());
    ListTablesResult nextResult = tsMeta.listTables(listTablesRequest);
    List<com.amazonaws.services.timestreamwrite.model.Table> nextTables = nextResult.getTables();
    while (!nextTables.isEmpty()) {
        nextTables.stream().forEach(next -> tableNames.add(new TableName(request.getSchemaName(), next.getTableName())));
        if (nextResult.getNextToken() != null && !nextResult.getNextToken().isEmpty()) {
            listTablesRequest.setNextToken(nextResult.getNextToken());
            nextResult = tsMeta.listTables(listTablesRequest);
            nextTables = nextResult.getTables();
        } else {
            nextTables = Collections.EMPTY_LIST;
        }
    }
    return new ListTablesResponse(request.getCatalogName(), tableNames, null);
}
Also used : Table(com.amazonaws.services.glue.model.Table) ArrayList(java.util.ArrayList) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) ListTablesResult(com.amazonaws.services.timestreamwrite.model.ListTablesResult) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse)

Example 10 with ListTablesResponse

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

the class DynamoDBMetadataHandlerTest method doListTablesGlueAndDynamo.

@Test
public void doListTablesGlueAndDynamo() throws Exception {
    List<String> tableNames = new ArrayList<>();
    tableNames.add("table1");
    tableNames.add("table2");
    tableNames.add("table3");
    GetTablesResult mockResult = new GetTablesResult();
    List<Table> tableList = new ArrayList<>();
    tableList.add(new Table().withName("table1").withParameters(ImmutableMap.of("classification", "dynamodb")).withStorageDescriptor(new StorageDescriptor().withLocation("some.location")));
    tableList.add(new Table().withName("table2").withParameters(ImmutableMap.of()).withStorageDescriptor(new StorageDescriptor().withLocation("some.location").withParameters(ImmutableMap.of("classification", "dynamodb"))));
    tableList.add(new Table().withName("table3").withParameters(ImmutableMap.of()).withStorageDescriptor(new StorageDescriptor().withLocation("arn:aws:dynamodb:us-east-1:012345678910:table/table3")));
    tableList.add(new Table().withName("notADynamoTable").withParameters(ImmutableMap.of()).withStorageDescriptor(new StorageDescriptor().withParameters(ImmutableMap.of()).withLocation("some_location")));
    mockResult.setTableList(tableList);
    when(glueClient.getTables(any())).thenReturn(mockResult);
    ListTablesRequest req = new ListTablesRequest(TEST_IDENTITY, TEST_QUERY_ID, TEST_CATALOG_NAME, DEFAULT_SCHEMA, null, UNLIMITED_PAGE_SIZE_VALUE);
    ListTablesResponse res = handler.doListTables(allocator, req);
    logger.info("doListTables - {}", res.getTables());
    List<TableName> expectedTables = tableNames.stream().map(table -> new TableName(DEFAULT_SCHEMA, table)).collect(Collectors.toList());
    expectedTables.add(TEST_TABLE_NAME);
    expectedTables.add(new TableName(DEFAULT_SCHEMA, "test_table2"));
    expectedTables.add(new TableName(DEFAULT_SCHEMA, "test_table3"));
    expectedTables.add(new TableName(DEFAULT_SCHEMA, "test_table4"));
    assertThat(new HashSet<>(res.getTables()), equalTo(new HashSet<>(expectedTables)));
}
Also used : Types(org.apache.arrow.vector.types.Types) LoggerFactory(org.slf4j.LoggerFactory) SEGMENT_COUNT_METADATA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.SEGMENT_COUNT_METADATA) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) SOURCE_TABLE_PROPERTY(com.amazonaws.athena.connector.lambda.handlers.GlueMetadataHandler.SOURCE_TABLE_PROPERTY) GetDatabasesResult(com.amazonaws.services.glue.model.GetDatabasesResult) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) MAX_SPLITS_PER_REQUEST(com.amazonaws.athena.connectors.dynamodb.DynamoDBMetadataHandler.MAX_SPLITS_PER_REQUEST) After(org.junit.After) Map(java.util.Map) DATETIME_FORMAT_MAPPING_PROPERTY_NORMALIZED(com.amazonaws.athena.connector.lambda.handlers.GlueMetadataHandler.DATETIME_FORMAT_MAPPING_PROPERTY_NORMALIZED) DYNAMO_DB_FLAG(com.amazonaws.athena.connectors.dynamodb.DynamoDBMetadataHandler.DYNAMO_DB_FLAG) ValueSet(com.amazonaws.athena.connector.lambda.domain.predicate.ValueSet) ZoneOffset(java.time.ZoneOffset) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) GetTablesResult(com.amazonaws.services.glue.model.GetTablesResult) COLUMN_NAME_MAPPING_PROPERTY(com.amazonaws.athena.connector.lambda.handlers.GlueMetadataHandler.COLUMN_NAME_MAPPING_PROPERTY) RANGE_KEY_FILTER_METADATA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.RANGE_KEY_FILTER_METADATA) ListSchemasResponse(com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse) AmazonServiceException(com.amazonaws.AmazonServiceException) ImmutableMap(com.google.common.collect.ImmutableMap) TimeZone(java.util.TimeZone) Split(com.amazonaws.athena.connector.lambda.domain.Split) Column(com.amazonaws.services.glue.model.Column) PARTITION_TYPE_METADATA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.PARTITION_TYPE_METADATA) EXPRESSION_NAMES_METADATA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.EXPRESSION_NAMES_METADATA) Instant(java.time.Instant) QUERY_PARTITION_TYPE(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.QUERY_PARTITION_TYPE) Collectors(java.util.stream.Collectors) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) Matchers.any(org.mockito.Matchers.any) GetTableLayoutResponse(com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutResponse) EXPRESSION_VALUES_METADATA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.EXPRESSION_VALUES_METADATA) RANGE_KEY_NAME_METADATA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.RANGE_KEY_NAME_METADATA) List(java.util.List) GetTableLayoutRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutRequest) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) ListSchemasRequest(com.amazonaws.athena.connector.lambda.metadata.ListSchemasRequest) GetSplitsResponse(com.amazonaws.athena.connector.lambda.metadata.GetSplitsResponse) Iterables(com.google.common.collect.Iterables) DATETIME_FORMAT_MAPPING_PROPERTY(com.amazonaws.athena.connector.lambda.handlers.GlueMetadataHandler.DATETIME_FORMAT_MAPPING_PROPERTY) SCAN_PARTITION_TYPE(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.SCAN_PARTITION_TYPE) Mock(org.mockito.Mock) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) EquatableValueSet(com.amazonaws.athena.connector.lambda.domain.predicate.EquatableValueSet) RunWith(org.junit.runner.RunWith) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) Jackson(com.amazonaws.util.json.Jackson) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Range(com.amazonaws.athena.connector.lambda.domain.predicate.Range) MetadataResponse(com.amazonaws.athena.connector.lambda.metadata.MetadataResponse) ImmutableList(com.google.common.collect.ImmutableList) DEFAULT_SCHEMA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.DEFAULT_SCHEMA) AWSGlue(com.amazonaws.services.glue.AWSGlue) SchemaBuilder(com.amazonaws.athena.connector.lambda.data.SchemaBuilder) TestName(org.junit.rules.TestName) LocalKeyFactory(com.amazonaws.athena.connector.lambda.security.LocalKeyFactory) ItemUtils(com.amazonaws.services.dynamodbv2.document.ItemUtils) Table(com.amazonaws.services.glue.model.Table) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) INDEX_METADATA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.INDEX_METADATA) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse) NON_KEY_FILTER_METADATA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.NON_KEY_FILTER_METADATA) GetSplitsRequest(com.amazonaws.athena.connector.lambda.metadata.GetSplitsRequest) Before(org.junit.Before) HASH_KEY_NAME_METADATA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.HASH_KEY_NAME_METADATA) Logger(org.slf4j.Logger) AmazonAthena(com.amazonaws.services.athena.AmazonAthena) SortedRangeSet(com.amazonaws.athena.connector.lambda.domain.predicate.SortedRangeSet) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) Test(org.junit.Test) UNLIMITED_PAGE_SIZE_VALUE(com.amazonaws.athena.connector.lambda.metadata.ListTablesRequest.UNLIMITED_PAGE_SIZE_VALUE) SEGMENT_ID_PROPERTY(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.SEGMENT_ID_PROPERTY) Mockito.when(org.mockito.Mockito.when) MetadataRequestType(com.amazonaws.athena.connector.lambda.metadata.MetadataRequestType) GetTableResult(com.amazonaws.services.glue.model.GetTableResult) TABLE_METADATA(com.amazonaws.athena.connectors.dynamodb.constants.DynamoDBConstants.TABLE_METADATA) Constraints(com.amazonaws.athena.connector.lambda.domain.predicate.Constraints) StorageDescriptor(com.amazonaws.services.glue.model.StorageDescriptor) Rule(org.junit.Rule) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) ChronoUnit(java.time.temporal.ChronoUnit) ListTablesRequest(com.amazonaws.athena.connector.lambda.metadata.ListTablesRequest) Database(com.amazonaws.services.glue.model.Database) Collections(java.util.Collections) GetTableResponse(com.amazonaws.athena.connector.lambda.metadata.GetTableResponse) Table(com.amazonaws.services.glue.model.Table) GetTablesResult(com.amazonaws.services.glue.model.GetTablesResult) ArrayList(java.util.ArrayList) StorageDescriptor(com.amazonaws.services.glue.model.StorageDescriptor) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) ListTablesRequest(com.amazonaws.athena.connector.lambda.metadata.ListTablesRequest) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ListTablesResponse (com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse)31 TableName (com.amazonaws.athena.connector.lambda.domain.TableName)24 ListTablesRequest (com.amazonaws.athena.connector.lambda.metadata.ListTablesRequest)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)13 Table (com.amazonaws.services.glue.model.Table)5 SchemaBuilder (com.amazonaws.athena.connector.lambda.data.SchemaBuilder)4 GetSplitsResponse (com.amazonaws.athena.connector.lambda.metadata.GetSplitsResponse)4 GetTableLayoutResponse (com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutResponse)4 GetTableResponse (com.amazonaws.athena.connector.lambda.metadata.GetTableResponse)4 ListSchemasResponse (com.amazonaws.athena.connector.lambda.metadata.ListSchemasResponse)4 GetTablesResult (com.amazonaws.services.glue.model.GetTablesResult)4 ImmutableList (com.google.common.collect.ImmutableList)4 BlockAllocatorImpl (com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl)3 Before (org.junit.Before)3 BlockAllocator (com.amazonaws.athena.connector.lambda.data.BlockAllocator)2 Split (com.amazonaws.athena.connector.lambda.domain.Split)2 Constraints (com.amazonaws.athena.connector.lambda.domain.predicate.Constraints)2 GetSplitsRequest (com.amazonaws.athena.connector.lambda.metadata.GetSplitsRequest)2 GetTableLayoutRequest (com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutRequest)2