Search in sources :

Example 6 with TestingTypeDeserializer

use of io.trino.spi.type.TestingTypeDeserializer in project trino by trinodb.

the class TestTupleDomain method testJsonSerialization.

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

        @Override
        public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return new ObjectMapperProvider().get().readValue(jsonParser, TestingColumnHandle.class);
        }
    }).addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.all();
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
    tupleDomain = TupleDomain.none();
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
    tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.of(A, NullableValue.of(BIGINT, 1L), B, NullableValue.asNull(VARCHAR)));
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
}
Also used : TestingColumnHandle(io.trino.spi.connector.TestingColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) TestingBlockEncodingSerde(io.trino.spi.block.TestingBlockEncodingSerde) IOException(java.io.IOException) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingColumnHandle(io.trino.spi.connector.TestingColumnHandle) Type(io.trino.spi.type.Type) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) Block(io.trino.spi.block.Block) TestingBlockJsonSerde(io.trino.spi.block.TestingBlockJsonSerde) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TestingTypeManager(io.trino.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.testng.annotations.Test)

Aggregations

ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)6 TestingTypeDeserializer (io.trino.spi.type.TestingTypeDeserializer)6 TestingTypeManager (io.trino.spi.type.TestingTypeManager)6 Type (io.trino.spi.type.Type)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)5 Test (org.testng.annotations.Test)5 Block (io.trino.spi.block.Block)4 TestingBlockEncodingSerde (io.trino.spi.block.TestingBlockEncodingSerde)4 TestingBlockJsonSerde (io.trino.spi.block.TestingBlockJsonSerde)4 VarcharType.createVarcharType (io.trino.spi.type.VarcharType.createVarcharType)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)1 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)1 JsonCodecFactory (io.airlift.json.JsonCodecFactory)1 ColumnHandle (io.trino.spi.connector.ColumnHandle)1 TestingColumnHandle (io.trino.spi.connector.TestingColumnHandle)1 ArrayType (io.trino.spi.type.ArrayType)1 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)1