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