Search in sources :

Example 6 with ObjectMapperProvider

use of io.airlift.json.ObjectMapperProvider in project presto by prestodb.

the class TestSignature method testSerializationRoundTrip.

@Test
public void testSerializationRoundTrip() {
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(new TypeRegistry())));
    JsonCodec<Signature> codec = new JsonCodecFactory(objectMapperProvider, true).jsonCodec(Signature.class);
    Signature expected = new Signature("function", SCALAR, parseTypeSignature(StandardTypes.BIGINT), ImmutableList.of(parseTypeSignature(StandardTypes.BOOLEAN), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.VARCHAR)));
    String json = codec.toJson(expected);
    Signature actual = codec.fromJson(json);
    assertEquals(actual.getName(), expected.getName());
    assertEquals(actual.getKind(), expected.getKind());
    assertEquals(actual.getReturnType(), expected.getReturnType());
    assertEquals(actual.getArgumentTypes(), expected.getArgumentTypes());
}
Also used : Type(com.facebook.presto.spi.type.Type) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) TypeRegistry(com.facebook.presto.type.TypeRegistry) JsonCodecFactory(io.airlift.json.JsonCodecFactory) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Test(org.testng.annotations.Test)

Example 7 with ObjectMapperProvider

use of io.airlift.json.ObjectMapperProvider in project presto by prestodb.

the class MetadataManager method createTestingViewCodec.

private static JsonCodec<ViewDefinition> createTestingViewCodec() {
    ObjectMapperProvider provider = new ObjectMapperProvider();
    provider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(new TypeRegistry())));
    return new JsonCodecFactory(provider).jsonCodec(ViewDefinition.class);
}
Also used : OperatorType(com.facebook.presto.spi.function.OperatorType) Type(com.facebook.presto.spi.type.Type) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) TypeRegistry(com.facebook.presto.type.TypeRegistry) JsonCodecFactory(io.airlift.json.JsonCodecFactory) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider)

Example 8 with ObjectMapperProvider

use of io.airlift.json.ObjectMapperProvider in project presto by prestodb.

the class TestHttpQueryStatsClient method setUp.

@BeforeMethod
public void setUp() throws Exception {
    ObjectMapper objectMapper = new ObjectMapperProvider().get();
    TestingHttpClient httpClient = new TestingHttpClient(httpRequest -> httpResponse);
    this.queryStatsClient = new HttpQueryStatsClient(httpClient, objectMapper, BASE_URL);
}
Also used : TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with ObjectMapperProvider

use of io.airlift.json.ObjectMapperProvider in project presto by prestodb.

the class TestLocalProperties method testJsonSerialization.

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

        @Override
        public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return new ObjectMapperProvider().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 : ColumnHandle(com.facebook.presto.spi.ColumnHandle) TestingColumnHandle(com.facebook.presto.sql.planner.TestingColumnHandle) ConstantProperty(com.facebook.presto.spi.ConstantProperty) GroupingProperty(com.facebook.presto.spi.GroupingProperty) SortingProperty(com.facebook.presto.spi.SortingProperty) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingColumnHandle(com.facebook.presto.sql.planner.TestingColumnHandle) 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 10 with ObjectMapperProvider

use of io.airlift.json.ObjectMapperProvider in project presto by prestodb.

the class TestAllOrNoneValueSet method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    ObjectMapper mapper = new ObjectMapperProvider().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.spi.type.Type) TestingTypeDeserializer(com.facebook.presto.spi.type.TestingTypeDeserializer) TestingTypeManager(com.facebook.presto.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Test(org.testng.annotations.Test)

Aggregations

ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)12 Type (com.facebook.presto.spi.type.Type)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 Test (org.testng.annotations.Test)9 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)8 TestingTypeDeserializer (com.facebook.presto.spi.type.TestingTypeDeserializer)7 TestingTypeManager (com.facebook.presto.spi.type.TestingTypeManager)7 Block (com.facebook.presto.spi.block.Block)6 TestingBlockEncodingSerde (com.facebook.presto.spi.block.TestingBlockEncodingSerde)6 TestingBlockJsonSerde (com.facebook.presto.spi.block.TestingBlockJsonSerde)6 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 TypeDeserializer (com.facebook.presto.type.TypeDeserializer)2 TypeRegistry (com.facebook.presto.type.TypeRegistry)2 JsonParser (com.fasterxml.jackson.core.JsonParser)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)2 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)2 JsonCodecFactory (io.airlift.json.JsonCodecFactory)2 ConstantProperty (com.facebook.presto.spi.ConstantProperty)1 GroupingProperty (com.facebook.presto.spi.GroupingProperty)1