Search in sources :

Example 31 with GetTableRequest

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

the class GlueMetadataHandlerTest method doGetTable.

@Test
public void doGetTable() throws Exception {
    String sourceTable = "My-Table";
    Map<String, String> expectedParams = new HashMap<>();
    expectedParams.put(SOURCE_TABLE_PROPERTY, sourceTable);
    expectedParams.put(COLUMN_NAME_MAPPING_PROPERTY, "col2=Col2,col3=Col3, col4=Col4");
    expectedParams.put(DATETIME_FORMAT_MAPPING_PROPERTY, "col2=someformat2, col1=someformat1 ");
    List<Column> columns = new ArrayList<>();
    columns.add(new Column().withName("col1").withType("int").withComment("comment"));
    columns.add(new Column().withName("col2").withType("bigint").withComment("comment"));
    columns.add(new Column().withName("col3").withType("string").withComment("comment"));
    columns.add(new Column().withName("col4").withType("timestamp").withComment("comment"));
    columns.add(new Column().withName("col5").withType("date").withComment("comment"));
    columns.add(new Column().withName("col6").withType("timestamptz").withComment("comment"));
    columns.add(new Column().withName("col7").withType("timestamptz").withComment("comment"));
    Table mockTable = mock(Table.class);
    StorageDescriptor mockSd = mock(StorageDescriptor.class);
    when(mockTable.getName()).thenReturn(table);
    when(mockTable.getStorageDescriptor()).thenReturn(mockSd);
    when(mockTable.getParameters()).thenReturn(expectedParams);
    when(mockSd.getColumns()).thenReturn(columns);
    when(mockGlue.getTable(any(com.amazonaws.services.glue.model.GetTableRequest.class))).thenAnswer((InvocationOnMock invocationOnMock) -> {
        com.amazonaws.services.glue.model.GetTableRequest request = (com.amazonaws.services.glue.model.GetTableRequest) invocationOnMock.getArguments()[0];
        assertEquals(accountId, request.getCatalogId());
        assertEquals(schema, request.getDatabaseName());
        assertEquals(table, request.getName());
        GetTableResult mockResult = mock(GetTableResult.class);
        when(mockResult.getTable()).thenReturn(mockTable);
        return mockResult;
    });
    GetTableRequest req = new GetTableRequest(IdentityUtil.fakeIdentity(), queryId, catalog, new TableName(schema, table));
    GetTableResponse res = handler.doGetTable(allocator, req);
    logger.info("doGetTable - {}", res);
    assertTrue(res.getSchema().getFields().size() == 7);
    assertTrue(res.getSchema().getCustomMetadata().size() > 0);
    assertTrue(res.getSchema().getCustomMetadata().containsKey(DATETIME_FORMAT_MAPPING_PROPERTY));
    assertEquals(res.getSchema().getCustomMetadata().get(DATETIME_FORMAT_MAPPING_PROPERTY_NORMALIZED), "Col2=someformat2,col1=someformat1");
    assertEquals(sourceTable, getSourceTableName(res.getSchema()));
    // Verify column name mapping works
    assertNotNull(res.getSchema().findField("col1"));
    assertNotNull(res.getSchema().findField("Col2"));
    assertNotNull(res.getSchema().findField("Col3"));
    assertNotNull(res.getSchema().findField("Col4"));
    assertNotNull(res.getSchema().findField("col5"));
    assertNotNull(res.getSchema().findField("col6"));
    assertNotNull(res.getSchema().findField("col7"));
    // Verify types
    assertTrue(Types.getMinorTypeForArrowType(res.getSchema().findField("col1").getType()).equals(Types.MinorType.INT));
    assertTrue(Types.getMinorTypeForArrowType(res.getSchema().findField("Col2").getType()).equals(Types.MinorType.BIGINT));
    assertTrue(Types.getMinorTypeForArrowType(res.getSchema().findField("Col3").getType()).equals(Types.MinorType.VARCHAR));
    assertTrue(Types.getMinorTypeForArrowType(res.getSchema().findField("Col4").getType()).equals(Types.MinorType.DATEMILLI));
    assertTrue(Types.getMinorTypeForArrowType(res.getSchema().findField("col5").getType()).equals(Types.MinorType.DATEDAY));
    assertTrue(Types.getMinorTypeForArrowType(res.getSchema().findField("col6").getType()).equals(Types.MinorType.TIMESTAMPMILLITZ));
    assertTrue(Types.getMinorTypeForArrowType(res.getSchema().findField("col7").getType()).equals(Types.MinorType.TIMESTAMPMILLITZ));
}
Also used : Table(com.amazonaws.services.glue.model.Table) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StorageDescriptor(com.amazonaws.services.glue.model.StorageDescriptor) GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) GlueMetadataHandler.getSourceTableName(com.amazonaws.athena.connector.lambda.handlers.GlueMetadataHandler.getSourceTableName) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) Column(com.amazonaws.services.glue.model.Column) GetTableResponse(com.amazonaws.athena.connector.lambda.metadata.GetTableResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GetTableResult(com.amazonaws.services.glue.model.GetTableResult) Test(org.junit.Test)

Example 32 with GetTableRequest

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

the class HbaseMetadataHandlerTest method doGetTable.

/**
 * TODO: Add more types.
 */
@Test
public void doGetTable() throws Exception {
    List<Result> results = TestUtils.makeResults();
    ResultScanner mockScanner = mock(ResultScanner.class);
    when(mockScanner.iterator()).thenReturn(results.iterator());
    when(mockClient.scanTable(anyObject(), any(Scan.class), anyObject())).thenAnswer((InvocationOnMock invocationOnMock) -> {
        ResultProcessor processor = (ResultProcessor) invocationOnMock.getArguments()[2];
        return processor.scan(mockScanner);
    });
    GetTableRequest req = new GetTableRequest(IDENTITY, QUERY_ID, DEFAULT_CATALOG, TABLE_NAME);
    GetTableResponse res = handler.doGetTable(allocator, req);
    logger.info("doGetTable - {}", res);
    Schema expectedSchema = TestUtils.makeSchema().addField(HbaseSchemaUtils.ROW_COLUMN_NAME, Types.MinorType.VARCHAR.getType()).build();
    assertEquals(expectedSchema.getFields().size(), res.getSchema().getFields().size());
}
Also used : GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) GetTableResponse(com.amazonaws.athena.connector.lambda.metadata.GetTableResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Schema(org.apache.arrow.vector.types.pojo.Schema) Scan(org.apache.hadoop.hbase.client.Scan) ResultProcessor(com.amazonaws.athena.connectors.hbase.connection.ResultProcessor) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 33 with GetTableRequest

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

the class GetTableRequestSerDeTest method beforeTest.

@Before
public void beforeTest() throws IOException {
    expected = new GetTableRequest(federatedIdentity, "test-query-id", "test-catalog", new TableName("test-schema", "test-table"));
    String expectedSerDeFile = utils.getResourceOrFail("serde/v2", "GetTableRequest.json");
    expectedSerDeText = utils.readAllAsString(expectedSerDeFile).trim();
}
Also used : GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) Before(org.junit.Before)

Example 34 with GetTableRequest

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

the class HiveMuxMetadataHandlerTest method doGetTable.

@Test
public void doGetTable() throws Exception {
    GetTableRequest getTableRequest = Mockito.mock(GetTableRequest.class);
    Mockito.when(getTableRequest.getCatalogName()).thenReturn("metaHive");
    this.jdbcMetadataHandler.doGetTable(this.allocator, getTableRequest);
    Mockito.verify(this.hiveMetadataHandler, Mockito.times(1)).doGetTable(Mockito.eq(this.allocator), Mockito.eq(getTableRequest));
}
Also used : GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) Test(org.junit.Test)

Example 35 with GetTableRequest

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

the class MySqlMuxJdbcMetadataHandlerTest method doGetTable.

@Test
public void doGetTable() {
    GetTableRequest getTableRequest = Mockito.mock(GetTableRequest.class);
    Mockito.when(getTableRequest.getCatalogName()).thenReturn("fakedatabase");
    this.jdbcMetadataHandler.doGetTable(this.allocator, getTableRequest);
    Mockito.verify(this.mySqlMetadataHandler, Mockito.times(1)).doGetTable(Mockito.eq(this.allocator), Mockito.eq(getTableRequest));
}
Also used : GetTableRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableRequest) Test(org.junit.Test)

Aggregations

GetTableRequest (com.amazonaws.athena.connector.lambda.metadata.GetTableRequest)51 Test (org.junit.Test)48 GetTableResponse (com.amazonaws.athena.connector.lambda.metadata.GetTableResponse)33 TableName (com.amazonaws.athena.connector.lambda.domain.TableName)30 ArrayList (java.util.ArrayList)13 GetTableResult (com.amazonaws.services.glue.model.GetTableResult)11 Column (com.amazonaws.services.glue.model.Column)10 Schema (org.apache.arrow.vector.types.pojo.Schema)10 StorageDescriptor (com.amazonaws.services.glue.model.StorageDescriptor)9 Table (com.amazonaws.services.glue.model.Table)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 SchemaBuilder (com.amazonaws.athena.connector.lambda.data.SchemaBuilder)7 Constraints (com.amazonaws.athena.connector.lambda.domain.predicate.Constraints)7 HashMap (java.util.HashMap)7 BlockAllocatorImpl (com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl)6 ResultSet (java.sql.ResultSet)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Field (org.apache.arrow.vector.types.pojo.Field)6 ReadRecordsRequest (com.amazonaws.athena.connector.lambda.records.ReadRecordsRequest)5 ReadRecordsResponse (com.amazonaws.athena.connector.lambda.records.ReadRecordsResponse)4