Search in sources :

Example 16 with ListTablesResponse

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

the class HbaseMetadataHandlerTest method doListTables.

@Test
public void doListTables() throws IOException {
    logger.info("doListTables - enter");
    String schema = "schema1";
    org.apache.hadoop.hbase.TableName[] tables = { org.apache.hadoop.hbase.TableName.valueOf("schema1", "table1"), org.apache.hadoop.hbase.TableName.valueOf("schema1", "table2"), org.apache.hadoop.hbase.TableName.valueOf("schema1", "table3") };
    Set<String> tableNames = new HashSet<>();
    tableNames.add("table1");
    tableNames.add("table2");
    tableNames.add("table3");
    when(mockClient.listTableNamesByNamespace(eq(schema))).thenReturn(tables);
    ListTablesRequest req = new ListTablesRequest(IDENTITY, QUERY_ID, DEFAULT_CATALOG, schema, null, UNLIMITED_PAGE_SIZE_VALUE);
    ListTablesResponse res = handler.doListTables(allocator, req);
    logger.info("doListTables - {}", res.getTables());
    for (TableName next : res.getTables()) {
        assertEquals(schema, next.getSchemaName());
        assertTrue(tableNames.contains(next.getTableName()));
    }
    assertEquals(tableNames.size(), res.getTables().size());
}
Also used : TableName(com.amazonaws.athena.connector.lambda.domain.TableName) ListTablesRequest(com.amazonaws.athena.connector.lambda.metadata.ListTablesRequest) Matchers.anyString(org.mockito.Matchers.anyString) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with ListTablesResponse

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

the class ListTablesResponseSerDeTest method beforeTest.

@Before
public void beforeTest() throws IOException {
    expected = new ListTablesResponse("test-catalog", ImmutableList.of(new TableName("schema1", "table1"), new TableName("schema1", "table2")), "table3");
    String expectedSerDeFile = utils.getResourceOrFail("serde/v2", "ListTablesResponse.json");
    expectedSerDeText = utils.readAllAsString(expectedSerDeFile).trim();
}
Also used : TableName(com.amazonaws.athena.connector.lambda.domain.TableName) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse) Before(org.junit.Before)

Example 18 with ListTablesResponse

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

the class JdbcMetadataHandlerTest method doListTablesEscaped.

@Test
public void doListTablesEscaped() throws SQLException {
    String[] schema = { "TABLE_SCHEM", "TABLE_NAME" };
    Object[][] values = { { "test_Schema", "testTable" }, { "test_Schema", "testtable2" } };
    TableName[] expected = { new TableName("test_Schema", "testTable"), new TableName("test_Schema", "testtable2") };
    AtomicInteger rowNumber = new AtomicInteger(-1);
    ResultSet resultSet = mockResultSet(schema, values, rowNumber);
    Mockito.when(connection.getMetaData().getTables("testCatalog", "test\\_Schema", null, new String[] { "TABLE", "VIEW", "EXTERNAL TABLE" })).thenReturn(resultSet);
    Mockito.when(connection.getCatalog()).thenReturn("testCatalog");
    Mockito.when(connection.getMetaData().getSearchStringEscape()).thenReturn("\\");
    ListTablesResponse listTablesResponse = this.jdbcMetadataHandler.doListTables(this.blockAllocator, new ListTablesRequest(this.federatedIdentity, "testQueryId", "testCatalog", "test_Schema", 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 19 with ListTablesResponse

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

the class NeptuneMetadataHandler method doListTables.

/**
 * Used to get the list of tables that this data source contains. In this case,
 * fetch list of tables in the Glue database provided.
 *
 * @param allocator Tool for creating and managing Apache Arrow Blocks.
 * @param request   Provides details on who made the request and which Athena
 *                  catalog and database they are querying.
 * @return A ListTablesResponse which primarily contains a List<TableName>
 *         enumerating the tables in this catalog, database tuple. It also
 *         contains the catalog name corresponding the Athena catalog that was
 *         queried.
 * @see GlueMetadataHandler
 */
@Override
public ListTablesResponse doListTables(BlockAllocator allocator, ListTablesRequest request) {
    logger.info("doListTables: enter - " + request);
    List<TableName> tables = new ArrayList<>();
    GetTablesRequest getTablesRequest = new GetTablesRequest();
    getTablesRequest.setDatabaseName(request.getSchemaName());
    GetTablesResult getTablesResult = glue.getTables(getTablesRequest);
    List<Table> glueTableList = getTablesResult.getTableList();
    String schemaName = request.getSchemaName();
    glueTableList.forEach(e -> {
        tables.add(new TableName(schemaName, e.getName()));
    });
    return new ListTablesResponse(request.getCatalogName(), tables, null);
}
Also used : TableName(com.amazonaws.athena.connector.lambda.domain.TableName) Table(com.amazonaws.services.glue.model.Table) GetTablesResult(com.amazonaws.services.glue.model.GetTablesResult) ArrayList(java.util.ArrayList) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse) GetTablesRequest(com.amazonaws.services.glue.model.GetTablesRequest)

Example 20 with ListTablesResponse

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

the class TPCDSMetadataHandlerTest method doListTables.

@Test
public void doListTables() {
    logger.info("doListTables - enter");
    ListTablesRequest req = new ListTablesRequest(identity, "queryId", "default", "tpcds1", null, UNLIMITED_PAGE_SIZE_VALUE);
    ListTablesResponse res = handler.doListTables(allocator, req);
    logger.info("doListTables - {}", res.getTables());
    assertTrue(res.getTables().contains(new TableName("tpcds1", "customer")));
    assertTrue(res.getTables().size() == 25);
    logger.info("doListTables - exit");
}
Also used : TableName(com.amazonaws.athena.connector.lambda.domain.TableName) ListTablesRequest(com.amazonaws.athena.connector.lambda.metadata.ListTablesRequest) ListTablesResponse(com.amazonaws.athena.connector.lambda.metadata.ListTablesResponse) 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