use of com.amazonaws.athena.connector.lambda.metadata.GetTableResponse in project aws-athena-query-federation by awslabs.
the class CompositeHandlerTest method setUp.
@Before
public void setUp() throws Exception {
logger.info("{}: enter", testName.getMethodName());
allocator = new BlockAllocatorImpl();
objectMapper = ObjectMapperFactory.create(allocator);
mockMetadataHandler = mock(MetadataHandler.class);
mockRecordHandler = mock(RecordHandler.class);
schemaForRead = SchemaBuilder.newBuilder().addField("col1", new ArrowType.Int(32, true)).build();
when(mockMetadataHandler.doGetTableLayout(any(BlockAllocatorImpl.class), any(GetTableLayoutRequest.class))).thenReturn(new GetTableLayoutResponse("catalog", new TableName("schema", "table"), BlockUtils.newBlock(allocator, "col1", Types.MinorType.BIGINT.getType(), 1L)));
when(mockMetadataHandler.doListTables(any(BlockAllocatorImpl.class), any(ListTablesRequest.class))).thenReturn(new ListTablesResponse("catalog", Collections.singletonList(new TableName("schema", "table")), null));
when(mockMetadataHandler.doGetTable(any(BlockAllocatorImpl.class), any(GetTableRequest.class))).thenReturn(new GetTableResponse("catalog", new TableName("schema", "table"), SchemaBuilder.newBuilder().addStringField("col1").build()));
when(mockMetadataHandler.doListSchemaNames(any(BlockAllocatorImpl.class), any(ListSchemasRequest.class))).thenReturn(new ListSchemasResponse("catalog", Collections.singleton("schema1")));
when(mockMetadataHandler.doGetSplits(any(BlockAllocatorImpl.class), any(GetSplitsRequest.class))).thenReturn(new GetSplitsResponse("catalog", Split.newBuilder(null, null).build()));
when(mockMetadataHandler.doPing(any(PingRequest.class))).thenReturn(new PingResponse("catalog", "queryId", "type", 23, 2));
when(mockRecordHandler.doReadRecords(any(BlockAllocatorImpl.class), any(ReadRecordsRequest.class))).thenReturn(new ReadRecordsResponse("catalog", BlockUtils.newEmptyBlock(allocator, "col", new ArrowType.Int(32, true))));
compositeHandler = new CompositeHandler(mockMetadataHandler, mockRecordHandler);
}
use of com.amazonaws.athena.connector.lambda.metadata.GetTableResponse in project aws-athena-query-federation by awslabs.
the class ExampleMetadataHandlerTest method doGetTable.
@Test
public void doGetTable() {
logger.info("doGetTable - enter");
GetTableRequest req = new GetTableRequest(IdentityUtil.fakeIdentity(), "queryId", "default", new TableName("custom_source", "fake_table"));
ObjectMapperUtil.assertSerialization(req);
GetTableResponse res = metadataHandler.doGetTable(allocator, req);
ObjectMapperUtil.assertSerialization(res);
assertTrue(res.getSchema().getFields().size() > 0);
assertTrue(res.getSchema().getCustomMetadata().size() > 0);
logger.info("doGetTable - {}", res);
logger.info("doGetTable - exit");
}
use of com.amazonaws.athena.connector.lambda.metadata.GetTableResponse in project aws-athena-query-federation by awslabs.
the class GetTableResponseSerDeTest method deserialize.
@Test
public void deserialize() throws IOException {
logger.info("deserialize: enter");
InputStream input = new ByteArrayInputStream(expectedSerDeText.getBytes());
GetTableResponse actual = (GetTableResponse) 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.GetTableResponse in project aws-athena-query-federation by awslabs.
the class BigQueryMetadataHandler method doGetTable.
@Override
public GetTableResponse doGetTable(BlockAllocator blockAllocator, GetTableRequest getTableRequest) {
try {
logger.info("doGetTable called with request {}:{}", BigQueryUtils.getProjectName(getTableRequest), getTableRequest.getTableName());
final Schema tableSchema = getSchema(BigQueryUtils.getProjectName(getTableRequest), getTableRequest.getTableName().getSchemaName(), getTableRequest.getTableName().getTableName());
return new GetTableResponse(BigQueryUtils.getProjectName(getTableRequest).toLowerCase(), getTableRequest.getTableName(), tableSchema);
} catch (Exception e) {
logger.error("Error: ", e);
}
return null;
}
use of com.amazonaws.athena.connector.lambda.metadata.GetTableResponse in project aws-athena-query-federation by awslabs.
the class HbaseMetadataHandler method doGetTable.
/**
* If Glue is enabled as a source of supplemental metadata we look up the requested Schema/Table in Glue and
* filters out any results that don't have the HBASE_METADATA_FLAG set. If no matching results were found in Glue,
* then we resort to inferring the schema of the HBase table using HbaseSchemaUtils.inferSchema(...). If there
* is no such table in HBase the operation will fail.
*
* @see GlueMetadataHandler
*/
@Override
public GetTableResponse doGetTable(BlockAllocator blockAllocator, GetTableRequest request) throws Exception {
logger.info("doGetTable: enter", request.getTableName());
Schema origSchema = null;
try {
if (awsGlue != null) {
origSchema = super.doGetTable(blockAllocator, request, TABLE_FILTER).getSchema();
}
} catch (RuntimeException ex) {
logger.warn("doGetTable: Unable to retrieve table[{}:{}] from AWSGlue.", request.getTableName().getSchemaName(), request.getTableName().getTableName(), ex);
}
if (origSchema == null) {
origSchema = HbaseSchemaUtils.inferSchema(getOrCreateConn(request), request.getTableName(), NUM_ROWS_TO_SCAN);
}
SchemaBuilder schemaBuilder = SchemaBuilder.newBuilder();
origSchema.getFields().forEach((Field field) -> schemaBuilder.addField(field.getName(), field.getType(), field.getChildren()));
origSchema.getCustomMetadata().entrySet().forEach((Map.Entry<String, String> meta) -> schemaBuilder.addMetadata(meta.getKey(), meta.getValue()));
schemaBuilder.addField(HbaseSchemaUtils.ROW_COLUMN_NAME, Types.MinorType.VARCHAR.getType());
Schema schema = schemaBuilder.build();
logger.info("doGetTable: return {}", schema);
return new GetTableResponse(request.getCatalogName(), request.getTableName(), schema);
}
Aggregations