Search in sources :

Example 51 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class DimensionSelectorHavingSpecTest method testDimSelectorHavingClauseSerde.

@Test
public void testDimSelectorHavingClauseSerde() throws Exception {
    HavingSpec dimHavingSpec = new DimensionSelectorHavingSpec("dim", "v", null);
    Map<String, Object> dimSelectMap = ImmutableMap.<String, Object>of("type", "dimSelector", "dimension", "dim", "value", "v");
    ObjectMapper mapper = new DefaultObjectMapper();
    assertEquals(dimHavingSpec, mapper.convertValue(dimSelectMap, DimensionSelectorHavingSpec.class));
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 52 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class HavingSpecTest method testTypeTypo.

@Test(expected = IllegalArgumentException.class)
public void testTypeTypo() {
    Map<String, Object> greaterMap = ImmutableMap.<String, Object>of("type", "nonExistingType", "aggregation", "agg", "value", 1.3);
    ObjectMapper mapper = new DefaultObjectMapper();
    HavingSpec spec = mapper.convertValue(greaterMap, HavingSpec.class);
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 53 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class DefaultLimitSpecTest method testSerde.

@Test
public void testSerde() throws Exception {
    ObjectMapper mapper = TestHelper.getObjectMapper();
    //defaults
    String json = "{\"type\": \"default\"}";
    DefaultLimitSpec spec = mapper.readValue(mapper.writeValueAsString(mapper.readValue(json, DefaultLimitSpec.class)), DefaultLimitSpec.class);
    Assert.assertEquals(new DefaultLimitSpec(null, null), spec);
    //non-defaults
    json = "{\n" + "  \"type\":\"default\",\n" + "  \"columns\":[{\"dimension\":\"d\",\"direction\":\"DESCENDING\", \"dimensionOrder\":\"numeric\"}],\n" + "  \"limit\":10\n" + "}";
    spec = mapper.readValue(mapper.writeValueAsString(mapper.readValue(json, DefaultLimitSpec.class)), DefaultLimitSpec.class);
    Assert.assertEquals(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("d", OrderByColumnSpec.Direction.DESCENDING, StringComparators.NUMERIC)), 10), spec);
    json = "{\n" + "  \"type\":\"default\",\n" + "  \"columns\":[{\"dimension\":\"d\",\"direction\":\"DES\", \"dimensionOrder\":\"numeric\"}],\n" + "  \"limit\":10\n" + "}";
    spec = mapper.readValue(mapper.writeValueAsString(mapper.readValue(json, DefaultLimitSpec.class)), DefaultLimitSpec.class);
    Assert.assertEquals(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("d", OrderByColumnSpec.Direction.DESCENDING, StringComparators.NUMERIC)), 10), spec);
    json = "{\n" + "  \"type\":\"default\",\n" + "  \"columns\":[{\"dimension\":\"d\"}],\n" + "  \"limit\":10\n" + "}";
    spec = mapper.readValue(mapper.writeValueAsString(mapper.readValue(json, DefaultLimitSpec.class)), DefaultLimitSpec.class);
    Assert.assertEquals(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("d", OrderByColumnSpec.Direction.ASCENDING, StringComparators.LEXICOGRAPHIC)), 10), spec);
    json = "{\n" + "  \"type\":\"default\",\n" + "  \"columns\":[\"d\"],\n" + "  \"limit\":10\n" + "}";
    spec = mapper.readValue(mapper.writeValueAsString(mapper.readValue(json, DefaultLimitSpec.class)), DefaultLimitSpec.class);
    Assert.assertEquals(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("d", OrderByColumnSpec.Direction.ASCENDING, StringComparators.LEXICOGRAPHIC)), 10), spec);
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 54 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class StringComparatorsTest method testLexicographicComparatorSerdeTest.

@Test
public void testLexicographicComparatorSerdeTest() throws IOException {
    ObjectMapper jsonMapper = new DefaultObjectMapper();
    String expectJsonSpec = "{\"type\":\"lexicographic\"}";
    String jsonSpec = jsonMapper.writeValueAsString(StringComparators.LEXICOGRAPHIC);
    Assert.assertEquals(expectJsonSpec, jsonSpec);
    Assert.assertEquals(StringComparators.LEXICOGRAPHIC, jsonMapper.readValue(expectJsonSpec, StringComparator.class));
    String makeFromJsonSpec = "\"lexicographic\"";
    Assert.assertEquals(StringComparators.LEXICOGRAPHIC, jsonMapper.readValue(makeFromJsonSpec, StringComparator.class));
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 55 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class StringComparatorsTest method testNumericComparatorSerdeTest.

@Test
public void testNumericComparatorSerdeTest() throws IOException {
    ObjectMapper jsonMapper = new DefaultObjectMapper();
    String expectJsonSpec = "{\"type\":\"numeric\"}";
    String jsonSpec = jsonMapper.writeValueAsString(StringComparators.NUMERIC);
    Assert.assertEquals(expectJsonSpec, jsonSpec);
    Assert.assertEquals(StringComparators.NUMERIC, jsonMapper.readValue(expectJsonSpec, StringComparator.class));
    String makeFromJsonSpec = "\"numeric\"";
    Assert.assertEquals(StringComparators.NUMERIC, jsonMapper.readValue(makeFromJsonSpec, StringComparator.class));
    makeFromJsonSpec = "\"NuMeRiC\"";
    Assert.assertEquals(StringComparators.NUMERIC, jsonMapper.readValue(makeFromJsonSpec, StringComparator.class));
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6071 Test (org.junit.Test)2235 IOException (java.io.IOException)1016 JsonNode (com.fasterxml.jackson.databind.JsonNode)930 HashMap (java.util.HashMap)444 Map (java.util.Map)429 ArrayList (java.util.ArrayList)416 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)388 File (java.io.File)319 List (java.util.List)268 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)254 Before (org.junit.Before)246 Test (org.junit.jupiter.api.Test)238 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)202 InputStream (java.io.InputStream)185 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)156 Matchers.containsString (org.hamcrest.Matchers.containsString)136 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 TypeReference (com.fasterxml.jackson.core.type.TypeReference)123 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)121