Search in sources :

Example 26 with BlockAllocator

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);
        }
    }
}
Also used : PingRequest(com.amazonaws.athena.connector.lambda.request.PingRequest) MetadataRequest(com.amazonaws.athena.connector.lambda.metadata.MetadataRequest) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) PingResponse(com.amazonaws.athena.connector.lambda.request.PingResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) FederationRequest(com.amazonaws.athena.connector.lambda.request.FederationRequest)

Example 27 with BlockAllocator

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);
        }
    }
}
Also used : RecordRequest(com.amazonaws.athena.connector.lambda.records.RecordRequest) PingRequest(com.amazonaws.athena.connector.lambda.request.PingRequest) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) PingResponse(com.amazonaws.athena.connector.lambda.request.PingResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) FederationRequest(com.amazonaws.athena.connector.lambda.request.FederationRequest)

Example 28 with BlockAllocator

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);
        }
    }
}
Also used : PingRequest(com.amazonaws.athena.connector.lambda.request.PingRequest) UserDefinedFunctionRequest(com.amazonaws.athena.connector.lambda.udf.UserDefinedFunctionRequest) BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) PingResponse(com.amazonaws.athena.connector.lambda.request.PingResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InvocationTargetException(java.lang.reflect.InvocationTargetException) FederationRequest(com.amazonaws.athena.connector.lambda.request.FederationRequest)

Example 29 with BlockAllocator

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);
    }
}
Also used : BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 30 with BlockAllocator

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());
    }
}
Also used : BlockAllocatorImpl(com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

BlockAllocator (com.amazonaws.athena.connector.lambda.data.BlockAllocator)51 BlockAllocatorImpl (com.amazonaws.athena.connector.lambda.data.BlockAllocatorImpl)50 Test (org.junit.Test)43 Schema (org.apache.arrow.vector.types.pojo.Schema)39 TableName (com.amazonaws.athena.connector.lambda.domain.TableName)38 ResultSet (java.sql.ResultSet)36 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)36 Constraints (com.amazonaws.athena.connector.lambda.domain.predicate.Constraints)35 PreparedStatement (java.sql.PreparedStatement)27 GetTableLayoutRequest (com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutRequest)26 GetTableLayoutResponse (com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutResponse)25 SchemaBuilder (com.amazonaws.athena.connector.lambda.data.SchemaBuilder)20 Map (java.util.Map)16 GetSplitsRequest (com.amazonaws.athena.connector.lambda.metadata.GetSplitsRequest)15 GetSplitsResponse (com.amazonaws.athena.connector.lambda.metadata.GetSplitsResponse)15 HashSet (java.util.HashSet)15 ArrayList (java.util.ArrayList)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 FederationRequest (com.amazonaws.athena.connector.lambda.request.FederationRequest)6 IOException (java.io.IOException)5