Search in sources :

Example 1 with TestingBlockEncodingSerde

use of io.prestosql.spi.block.TestingBlockEncodingSerde in project hetu-core by openlookeng.

the class TestDomain 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(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    Domain domain = Domain.all(BIGINT);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.none(DOUBLE);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.notNull(BOOLEAN);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.notNull(HYPER_LOG_LOG);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.onlyNull(VARCHAR);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.onlyNull(HYPER_LOG_LOG);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.singleValue(BIGINT, Long.MIN_VALUE);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.singleValue(ID, Long.MIN_VALUE);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 0L), Range.equal(BIGINT, 1L), Range.range(BIGINT, 2L, true, 3L, true)), true);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
}
Also used : Type(io.prestosql.spi.type.Type) TestingTypeDeserializer(io.prestosql.spi.type.TestingTypeDeserializer) TestingBlockEncodingSerde(io.prestosql.spi.block.TestingBlockEncodingSerde) TestingTypeDeserializer(io.prestosql.spi.type.TestingTypeDeserializer) Block(io.prestosql.spi.block.Block) TestingBlockJsonSerde(io.prestosql.spi.block.TestingBlockJsonSerde) TestingTypeManager(io.prestosql.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)

Example 2 with TestingBlockEncodingSerde

use of io.prestosql.spi.block.TestingBlockEncodingSerde in project hetu-core by openlookeng.

the class TestEquatableValueSet 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(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    EquatableValueSet set = EquatableValueSet.all(ID);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.none(ID);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.of(ID, 1L);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.of(ID, 1L, 2L);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.of(ID, 1L, 2L).complement();
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
}
Also used : Type(io.prestosql.spi.type.Type) TestingTypeDeserializer(io.prestosql.spi.type.TestingTypeDeserializer) TestingBlockEncodingSerde(io.prestosql.spi.block.TestingBlockEncodingSerde) TestingTypeDeserializer(io.prestosql.spi.type.TestingTypeDeserializer) Block(io.prestosql.spi.block.Block) TestingBlockJsonSerde(io.prestosql.spi.block.TestingBlockJsonSerde) TestingTypeManager(io.prestosql.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)

Example 3 with TestingBlockEncodingSerde

use of io.prestosql.spi.block.TestingBlockEncodingSerde in project hetu-core by openlookeng.

the class TestSortedRangeSet 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(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    SortedRangeSet set = SortedRangeSet.all(BIGINT);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.none(DOUBLE);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.of(VARCHAR, utf8Slice("abc"));
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.of(Range.equal(BOOLEAN, true), Range.equal(BOOLEAN, false));
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
}
Also used : Type(io.prestosql.spi.type.Type) TestingTypeDeserializer(io.prestosql.spi.type.TestingTypeDeserializer) TestingBlockEncodingSerde(io.prestosql.spi.block.TestingBlockEncodingSerde) TestingTypeDeserializer(io.prestosql.spi.type.TestingTypeDeserializer) Block(io.prestosql.spi.block.Block) TestingBlockJsonSerde(io.prestosql.spi.block.TestingBlockJsonSerde) TestingTypeManager(io.prestosql.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)

Example 4 with TestingBlockEncodingSerde

use of io.prestosql.spi.block.TestingBlockEncodingSerde in project hetu-core by openlookeng.

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<ColumnHandle>() {

        @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.prestosql.spi.connector.TestingColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) TestingBlockEncodingSerde(io.prestosql.spi.block.TestingBlockEncodingSerde) IOException(java.io.IOException) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) Type(io.prestosql.spi.type.Type) TestingTypeDeserializer(io.prestosql.spi.type.TestingTypeDeserializer) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) TestingTypeDeserializer(io.prestosql.spi.type.TestingTypeDeserializer) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) Block(io.prestosql.spi.block.Block) TestingBlockJsonSerde(io.prestosql.spi.block.TestingBlockJsonSerde) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TestingTypeManager(io.prestosql.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)

Example 5 with TestingBlockEncodingSerde

use of io.prestosql.spi.block.TestingBlockEncodingSerde in project hetu-core by openlookeng.

the class TestSplitKey method testSerde.

@Test
public void testSerde() throws IOException {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
    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);
        }
    }).addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)).addKeyDeserializer(SplitKey.class, new SplitKey.KeyDeserializer()));
    SplitKey splitkey = new SplitKey(split1, catalogName.toString(), schema, table);
    assertEquals(mapper.readerFor(SplitKey.class).readValue(mapper.writeValueAsString(splitkey)), splitkey);
    Map<SplitKey, String> splitWorkers = new HashMap<>();
    splitWorkers.put(splitkey, "worker1");
    String mapJson = mapper.writeValueAsString(splitWorkers);
    TypeReference<HashMap<SplitKey, String>> typeRef = new TypeReference<HashMap<SplitKey, String>>() {
    };
    assertEquals(mapper.readValue(mapJson, typeRef), splitWorkers);
}
Also used : TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) TestingBlockEncodingSerde(io.prestosql.spi.block.TestingBlockEncodingSerde) HashMap(java.util.HashMap) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingTypeDeserializer(io.prestosql.spi.type.TestingTypeDeserializer) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) Block(io.prestosql.spi.block.Block) TestingBlockJsonSerde(io.prestosql.spi.block.TestingBlockJsonSerde) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TestingTypeManager(io.prestosql.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) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)7 Block (io.prestosql.spi.block.Block)7 TestingBlockEncodingSerde (io.prestosql.spi.block.TestingBlockEncodingSerde)7 TestingBlockJsonSerde (io.prestosql.spi.block.TestingBlockJsonSerde)7 TestingTypeDeserializer (io.prestosql.spi.type.TestingTypeDeserializer)7 TestingTypeManager (io.prestosql.spi.type.TestingTypeManager)7 Test (org.testng.annotations.Test)7 Type (io.prestosql.spi.type.Type)6 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 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)2 TestingColumnHandle (io.prestosql.spi.connector.TestingColumnHandle)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 BeforeTest (org.testng.annotations.BeforeTest)1