Search in sources :

Example 1 with JsonCodecFactory

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

the class MetadataManager method createTestingViewCodec.

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

Example 2 with JsonCodecFactory

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

the class TestSignature method testSerializationRoundTrip.

@Test
public void testSerializationRoundTrip() {
    JsonObjectMapperProvider objectMapperProvider = new JsonObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(createTestFunctionAndTypeManager())));
    JsonCodec<Signature> codec = new JsonCodecFactory(objectMapperProvider, true).jsonCodec(Signature.class);
    Signature expected = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "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.getNameSuffix(), expected.getNameSuffix());
    assertEquals(actual.getKind(), expected.getKind());
    assertEquals(actual.getReturnType(), expected.getReturnType());
    assertEquals(actual.getArgumentTypes(), expected.getArgumentTypes());
}
Also used : Type(com.facebook.presto.common.type.Type) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) JsonCodecFactory(com.facebook.airlift.json.JsonCodecFactory) Test(org.testng.annotations.Test)

Aggregations

JsonCodecFactory (com.facebook.airlift.json.JsonCodecFactory)2 JsonObjectMapperProvider (com.facebook.airlift.json.JsonObjectMapperProvider)2 Type (com.facebook.presto.common.type.Type)2 TypeDeserializer (com.facebook.presto.type.TypeDeserializer)2 OperatorType (com.facebook.presto.common.function.OperatorType)1 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)1 Signature (com.facebook.presto.spi.function.Signature)1 Test (org.testng.annotations.Test)1