Search in sources :

Example 11 with JsonObjectMapperProvider

use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.

the class TestAllOrNoneValueSet method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    ObjectMapper mapper = new JsonObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)));
    AllOrNoneValueSet all = AllOrNoneValueSet.all(HYPER_LOG_LOG);
    assertEquals(all, mapper.readValue(mapper.writeValueAsString(all), AllOrNoneValueSet.class));
    AllOrNoneValueSet none = AllOrNoneValueSet.none(HYPER_LOG_LOG);
    assertEquals(none, mapper.readValue(mapper.writeValueAsString(none), AllOrNoneValueSet.class));
}
Also used : Type(com.facebook.presto.common.type.Type) TestingTypeDeserializer(com.facebook.presto.common.type.TestingTypeDeserializer) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) TestingTypeManager(com.facebook.presto.common.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.testng.annotations.Test)

Example 12 with JsonObjectMapperProvider

use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.

the class TestSortedRangeSet method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
    ObjectMapper mapper = new JsonObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    SortedRangeSet set = SortedRangeSet.all(BIGINT);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.none(DOUBLE);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.of(VARCHAR, utf8Slice("abc"));
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.of(Range.equal(BOOLEAN, true), Range.equal(BOOLEAN, false));
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
}
Also used : Type(com.facebook.presto.common.type.Type) TestingTypeDeserializer(com.facebook.presto.common.type.TestingTypeDeserializer) TestingBlockEncodingSerde(com.facebook.presto.common.block.TestingBlockEncodingSerde) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) TestingTypeDeserializer(com.facebook.presto.common.type.TestingTypeDeserializer) Block(com.facebook.presto.common.block.Block) TestingBlockJsonSerde(com.facebook.presto.common.block.TestingBlockJsonSerde) TestingTypeManager(com.facebook.presto.common.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.testng.annotations.Test)

Example 13 with JsonObjectMapperProvider

use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.

the class TestDomain method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
    ObjectMapper mapper = new JsonObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    Domain domain = Domain.all(BIGINT);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.none(DOUBLE);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.notNull(BOOLEAN);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.notNull(HYPER_LOG_LOG);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.onlyNull(VARCHAR);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.onlyNull(HYPER_LOG_LOG);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.singleValue(BIGINT, Long.MIN_VALUE);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.singleValue(ID, Long.MIN_VALUE);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 0L), Range.equal(BIGINT, 1L), Range.range(BIGINT, 2L, true, 3L, true)), true);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
}
Also used : Type(com.facebook.presto.common.type.Type) TestingTypeDeserializer(com.facebook.presto.common.type.TestingTypeDeserializer) TestingBlockEncodingSerde(com.facebook.presto.common.block.TestingBlockEncodingSerde) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) TestingTypeDeserializer(com.facebook.presto.common.type.TestingTypeDeserializer) Block(com.facebook.presto.common.block.Block) TestingBlockJsonSerde(com.facebook.presto.common.block.TestingBlockJsonSerde) TestingTypeManager(com.facebook.presto.common.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.testng.annotations.Test)

Example 14 with JsonObjectMapperProvider

use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.

the class TestLocalProperties method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    ObjectMapper mapper = new JsonObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(ColumnHandle.class, new JsonDeserializer<ColumnHandle>() {

        @Override
        public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return new JsonObjectMapperProvider().get().readValue(jsonParser, TestingColumnHandle.class);
        }
    }));
    TestingColumnHandle columnHandle = new TestingColumnHandle("a");
    LocalProperty<ColumnHandle> property1 = new ConstantProperty<>(columnHandle);
    assertEquals(property1, mapper.readValue(mapper.writeValueAsString(property1), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
    LocalProperty<ColumnHandle> property2 = new SortingProperty<>(columnHandle, SortOrder.ASC_NULLS_FIRST);
    assertEquals(property2, mapper.readValue(mapper.writeValueAsString(property2), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
    LocalProperty<ColumnHandle> property3 = new GroupingProperty<>(ImmutableList.of(columnHandle));
    assertEquals(property3, mapper.readValue(mapper.writeValueAsString(property3), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
}
Also used : TestingColumnHandle(com.facebook.presto.testing.TestingMetadata.TestingColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConstantProperty(com.facebook.presto.spi.ConstantProperty) GroupingProperty(com.facebook.presto.spi.GroupingProperty) SortingProperty(com.facebook.presto.spi.SortingProperty) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) TestingColumnHandle(com.facebook.presto.testing.TestingMetadata.TestingColumnHandle) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.testng.annotations.Test)

Example 15 with JsonObjectMapperProvider

use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.

the class ClusterSizeFetcher method fetchClusterSize.

private int fetchClusterSize() {
    Request request = prepareGet().setUri(nodeResourceUri).setHeader(CONTENT_TYPE, APPLICATION_JSON).build();
    StringResponse response = httpClient.execute(request, createStringResponseHandler());
    checkState(response.getStatusCode() == OK.getStatusCode(), "Invalid response: %s %s", response.getStatusCode(), response.getStatusMessage());
    List<Map<String, Object>> values;
    try {
        values = new JsonObjectMapperProvider().get().readValue(response.getBody(), new TypeReference<List<Map<String, Object>>>() {
        });
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return values.size();
}
Also used : JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) Request(com.facebook.airlift.http.client.Request) UncheckedIOException(java.io.UncheckedIOException) StringResponse(com.facebook.airlift.http.client.StringResponseHandler.StringResponse) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Map(java.util.Map)

Aggregations

JsonObjectMapperProvider (com.facebook.airlift.json.JsonObjectMapperProvider)19 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 Test (org.testng.annotations.Test)12 Type (com.facebook.presto.common.type.Type)9 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)9 TestingTypeDeserializer (com.facebook.presto.common.type.TestingTypeDeserializer)7 TestingTypeManager (com.facebook.presto.common.type.TestingTypeManager)7 Block (com.facebook.presto.common.block.Block)6 TestingBlockEncodingSerde (com.facebook.presto.common.block.TestingBlockEncodingSerde)6 TestingBlockJsonSerde (com.facebook.presto.common.block.TestingBlockJsonSerde)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 IOException (java.io.IOException)3 JsonCodecFactory (com.facebook.airlift.json.JsonCodecFactory)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 TypeDeserializer (com.facebook.presto.type.TypeDeserializer)2 JsonParser (com.fasterxml.jackson.core.JsonParser)2 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)2 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)2 File (java.io.File)2 Map (java.util.Map)2