use of com.amazonaws.athena.connector.lambda.data.BlockAllocator in project aws-athena-query-federation by awslabs.
the class MetadataHandler method handleRequest.
public final void handleRequest(InputStream inputStream, OutputStream outputStream, final Context context) throws IOException {
try (BlockAllocator allocator = new BlockAllocatorImpl()) {
ObjectMapper objectMapper = VersionedObjectMapperFactory.create(allocator);
try (FederationRequest rawReq = objectMapper.readValue(inputStream, FederationRequest.class)) {
if (rawReq instanceof PingRequest) {
try (PingResponse response = doPing((PingRequest) rawReq)) {
assertNotNull(response);
objectMapper.writeValue(outputStream, response);
}
return;
}
if (!(rawReq instanceof MetadataRequest)) {
throw new RuntimeException("Expected a MetadataRequest but found " + rawReq.getClass());
}
((MetadataRequest) rawReq).setContext(context);
doHandleRequest(allocator, objectMapper, (MetadataRequest) rawReq, outputStream);
} catch (Exception ex) {
logger.warn("handleRequest: Completed with an exception.", ex);
throw (ex instanceof RuntimeException) ? (RuntimeException) ex : new RuntimeException(ex);
}
}
}
use of com.amazonaws.athena.connector.lambda.data.BlockAllocator in project aws-athena-query-federation by awslabs.
the class RecordHandler method handleRequest.
public final void handleRequest(InputStream inputStream, OutputStream outputStream, final Context context) throws IOException {
try (BlockAllocator allocator = new BlockAllocatorImpl()) {
ObjectMapper objectMapper = VersionedObjectMapperFactory.create(allocator);
try (FederationRequest rawReq = objectMapper.readValue(inputStream, FederationRequest.class)) {
if (rawReq instanceof PingRequest) {
try (PingResponse response = doPing((PingRequest) rawReq)) {
assertNotNull(response);
objectMapper.writeValue(outputStream, response);
}
return;
}
if (!(rawReq instanceof RecordRequest)) {
throw new RuntimeException("Expected a RecordRequest but found " + rawReq.getClass());
}
doHandleRequest(allocator, objectMapper, (RecordRequest) rawReq, outputStream);
} catch (Exception ex) {
logger.warn("handleRequest: Completed with an exception.", ex);
throw (ex instanceof RuntimeException) ? (RuntimeException) ex : new RuntimeException(ex);
}
}
}
use of com.amazonaws.athena.connector.lambda.data.BlockAllocator in project aws-athena-query-federation by awslabs.
the class UserDefinedFunctionHandler method handleRequest.
@Override
public final void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) {
try (BlockAllocator allocator = new BlockAllocatorImpl()) {
ObjectMapper objectMapper = VersionedObjectMapperFactory.create(allocator);
try (FederationRequest rawRequest = objectMapper.readValue(inputStream, FederationRequest.class)) {
if (rawRequest instanceof PingRequest) {
try (PingResponse response = doPing((PingRequest) rawRequest)) {
assertNotNull(response);
objectMapper.writeValue(outputStream, response);
}
return;
}
if (!(rawRequest instanceof UserDefinedFunctionRequest)) {
throw new RuntimeException("Expected a UserDefinedFunctionRequest but found " + rawRequest.getClass());
}
doHandleRequest(allocator, objectMapper, (UserDefinedFunctionRequest) rawRequest, outputStream);
} catch (Exception ex) {
throw (ex instanceof RuntimeException) ? (RuntimeException) ex : new RuntimeException(ex);
}
}
}
use of com.amazonaws.athena.connector.lambda.data.BlockAllocator in project aws-athena-query-federation by awslabs.
the class ObjectMapperFactoryV2Test method testStrictDeserializer.
@Test(expected = JsonMappingException.class)
public void testStrictDeserializer() throws IOException {
try (BlockAllocator allocator = new BlockAllocatorImpl()) {
ObjectMapper mapper = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_TWO);
mapper.readValue("{\"@type\" : \"FloatingPoint\", \"precision\" : \"DOUBLE\"}", ArrowType.FloatingPoint.class);
}
}
use of com.amazonaws.athena.connector.lambda.data.BlockAllocator in project aws-athena-query-federation by awslabs.
the class ObjectMapperFactoryV2Test method testStrictSerializer.
@Test(expected = JsonMappingException.class)
public void testStrictSerializer() throws JsonProcessingException {
try (BlockAllocator allocator = new BlockAllocatorImpl()) {
ObjectMapper mapper = VersionedObjectMapperFactory.create(allocator, SERDE_VERSION_TWO);
mapper.writeValueAsString(new ArrowType.Null());
}
}
Aggregations