Search in sources :

Example 6 with JsonObjectMapperProvider

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

the class TestRange 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)));
    Range range = Range.all(BIGINT);
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
    range = Range.equal(DOUBLE, 0.123);
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
    range = Range.greaterThan(BIGINT, 0L);
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
    range = Range.greaterThanOrEqual(VARCHAR, utf8Slice("abc"));
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
    range = Range.lessThan(BIGINT, Long.MAX_VALUE);
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
    range = Range.lessThanOrEqual(DOUBLE, Double.MAX_VALUE);
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.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 7 with JsonObjectMapperProvider

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

the class TestEquatableValueSet 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)));
    EquatableValueSet set = EquatableValueSet.all(TestingIdType.ID);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.none(TestingIdType.ID);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.of(TestingIdType.ID, 1L);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.of(TestingIdType.ID, 1L, 2L);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.of(TestingIdType.ID, 1L, 2L).complement();
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
}
Also used : TestingIdType(com.facebook.presto.common.type.TestingIdType) 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 8 with JsonObjectMapperProvider

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

the class TestMarker 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)));
    Marker marker = Marker.above(BIGINT, 0L);
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
    marker = Marker.exactly(VARCHAR, utf8Slice("abc"));
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
    marker = Marker.below(DOUBLE, 0.123);
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
    marker = Marker.exactly(BOOLEAN, true);
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
    marker = Marker.upperUnbounded(BIGINT);
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
    marker = Marker.lowerUnbounded(BIGINT);
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.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 9 with JsonObjectMapperProvider

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

the class TestSetDigest method testHashCounts.

@Test
public void testHashCounts() throws Exception {
    SetDigest digest1 = new SetDigest();
    digest1.add(0);
    digest1.add(0);
    digest1.add(1);
    SetDigest digest2 = new SetDigest();
    digest2.add(0);
    digest2.add(0);
    digest2.add(2);
    digest2.add(2);
    ObjectMapper mapper = new JsonObjectMapperProvider().get();
    Slice slice = hashCounts(digest1.serialize());
    Map<Long, Short> counts = mapper.readValue(slice.toStringUtf8(), new TypeReference<Map<Long, Short>>() {
    });
    Set<Short> expected = ImmutableSet.of((short) 1, (short) 2);
    assertEquals(counts.values(), expected);
    digest1.mergeWith(digest2);
    slice = hashCounts(digest1.serialize());
    counts = mapper.readValue(slice.toStringUtf8(), new TypeReference<Map<Long, Short>>() {
    });
    expected = ImmutableSet.of((short) 1, (short) 2, (short) 4);
    assertEquals(ImmutableSet.copyOf(counts.values()), expected);
}
Also used : JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) Slice(io.airlift.slice.Slice) TypeReference(com.fasterxml.jackson.core.type.TypeReference) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 10 with JsonObjectMapperProvider

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

the class TestHeartbeatFailureDetector method testHeartbeatStatsSerialization.

@Test
public void testHeartbeatStatsSerialization() throws Exception {
    ObjectMapper objectMapper = new JsonObjectMapperProvider().get();
    Stats stats = new Stats(new URI("http://example.com"), 60);
    String serialized = objectMapper.writeValueAsString(stats);
    JsonNode deserialized = objectMapper.readTree(serialized);
    assertFalse(deserialized.has("lastFailureInfo"));
    stats.recordFailure(new SocketTimeoutException("timeout"));
    serialized = objectMapper.writeValueAsString(stats);
    deserialized = objectMapper.readTree(serialized);
    assertFalse(deserialized.get("lastFailureInfo").isNull());
    assertEquals(deserialized.get("lastFailureInfo").get("type").asText(), SocketTimeoutException.class.getName());
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) Stats(com.facebook.presto.failureDetector.HeartbeatFailureDetector.Stats) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

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