Search in sources :

Example 1 with ConstantProperty

use of io.prestosql.spi.connector.ConstantProperty in project hetu-core by openlookeng.

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 : TestingColumnHandle(io.prestosql.testing.TestingMetadata.TestingColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) ConstantProperty(io.prestosql.spi.connector.ConstantProperty) GroupingProperty(io.prestosql.spi.connector.GroupingProperty) SortingProperty(io.prestosql.spi.connector.SortingProperty) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingColumnHandle(io.prestosql.testing.TestingMetadata.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)

Aggregations

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 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 ConstantProperty (io.prestosql.spi.connector.ConstantProperty)1 GroupingProperty (io.prestosql.spi.connector.GroupingProperty)1 SortingProperty (io.prestosql.spi.connector.SortingProperty)1 TestingColumnHandle (io.prestosql.testing.TestingMetadata.TestingColumnHandle)1 Test (org.testng.annotations.Test)1