Search in sources :

Example 31 with DefaultObjectMapper

use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class AggregationTestHelper method createTopNQueryAggregationTestHelper.

public static final AggregationTestHelper createTopNQueryAggregationTestHelper(List<? extends Module> jsonModulesToRegister, TemporaryFolder tempFolder) {
    ObjectMapper mapper = new DefaultObjectMapper();
    TopNQueryQueryToolChest toolchest = new TopNQueryQueryToolChest(new TopNQueryConfig(), QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator());
    TopNQueryRunnerFactory factory = new TopNQueryRunnerFactory(new StupidPool<>("TopNQueryRunnerFactory-bufferPool", new Supplier<ByteBuffer>() {

        @Override
        public ByteBuffer get() {
            return ByteBuffer.allocate(10 * 1024 * 1024);
        }
    }), toolchest, QueryRunnerTestHelper.NOOP_QUERYWATCHER);
    IndexIO indexIO = new IndexIO(mapper, new ColumnConfig() {

        @Override
        public int columnCacheSizeBytes() {
            return 0;
        }
    });
    return new AggregationTestHelper(mapper, new IndexMerger(mapper, indexIO), indexIO, toolchest, factory, tempFolder, jsonModulesToRegister);
}
Also used : IndexMerger(io.druid.segment.IndexMerger) TopNQueryConfig(io.druid.query.topn.TopNQueryConfig) IndexIO(io.druid.segment.IndexIO) ColumnConfig(io.druid.segment.column.ColumnConfig) TopNQueryRunnerFactory(io.druid.query.topn.TopNQueryRunnerFactory) TopNQueryQueryToolChest(io.druid.query.topn.TopNQueryQueryToolChest) Supplier(com.google.common.base.Supplier) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 32 with DefaultObjectMapper

use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class ExtractionDimensionSpecTest method testSerdeWithType.

@Test
public void testSerdeWithType() throws Exception {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    final String oldJson = "{\n" + "    \"type\": \"extraction\",\n" + "    \"outputName\": \"first3Letters\",\n" + "    \"outputType\": \"LONG\",\n" + "    \"dimension\": \"myDim\"," + "    \"extractionFn\": {\n" + "        \"type\": \"regex\",\n" + "        \"expr\": \"(...).*\"\n" + "    }\n" + "}";
    final ExtractionDimensionSpec extractionDimensionSpec = (ExtractionDimensionSpec) objectMapper.readValue(oldJson, DimensionSpec.class);
    Assert.assertEquals("first3Letters", extractionDimensionSpec.getOutputName());
    Assert.assertEquals("myDim", extractionDimensionSpec.getDimension());
    Assert.assertNotNull(extractionDimensionSpec.getExtractionFn());
    Assert.assertEquals(ValueType.LONG, extractionDimensionSpec.getOutputType());
    Assert.assertTrue(extractionDimensionSpec.getExtractionFn() instanceof RegexDimExtractionFn);
    Assert.assertEquals(extractionDimensionSpec, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionDimensionSpec), DimensionSpec.class));
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 33 with DefaultObjectMapper

use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class ExtractionDimensionSpecTest method testSerdeBackwardsCompatibility.

@Test
public void testSerdeBackwardsCompatibility() throws Exception {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    final String oldJson = "{\n" + "    \"type\": \"extraction\",\n" + "    \"outputName\": \"first3Letters\",\n" + "    \"dimension\": \"myDim\"," + "    \"dimExtractionFn\": {\n" + "        \"type\": \"regex\",\n" + "        \"expr\": \"(...).*\"\n" + "    }\n" + "}";
    final ExtractionDimensionSpec extractionDimensionSpec = (ExtractionDimensionSpec) objectMapper.readValue(oldJson, DimensionSpec.class);
    Assert.assertEquals("first3Letters", extractionDimensionSpec.getOutputName());
    Assert.assertEquals("myDim", extractionDimensionSpec.getDimension());
    Assert.assertNotNull(extractionDimensionSpec.getExtractionFn());
    Assert.assertTrue(extractionDimensionSpec.getExtractionFn() instanceof RegexDimExtractionFn);
    Assert.assertEquals(extractionDimensionSpec, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionDimensionSpec), DimensionSpec.class));
    // new trumps old
    final String oldAndNewJson = "{\n" + "    \"type\": \"extraction\",\n" + "    \"outputName\": \"first3Letters\",\n" + "    \"dimension\": \"myDim\"," + "    \"extractionFn\": {\n" + "        \"type\": \"partial\",\n" + "        \"expr\": \"(...).*\"\n" + "    },\n" + "    \"dimExtractionFn\": {\n" + "        \"type\": \"regex\",\n" + "        \"expr\": \"(...).*\"\n" + "    }\n" + "}";
    Assert.assertTrue(objectMapper.readValue(oldAndNewJson, DimensionSpec.class).getExtractionFn() instanceof MatchingDimExtractionFn);
}
Also used : MatchingDimExtractionFn(io.druid.query.extraction.MatchingDimExtractionFn) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 34 with DefaultObjectMapper

use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class SubstringDimExtractionFnTest method testSerde.

@Test
public void testSerde() throws Exception {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    final String json = "{ \"type\" : \"substring\", \"index\" : 1, \"length\" : 3 }";
    final String jsonNoLength = "{ \"type\" : \"substring\", \"index\" : 1 }";
    SubstringDimExtractionFn extractionFn = (SubstringDimExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
    SubstringDimExtractionFn extractionFnNoLength = (SubstringDimExtractionFn) objectMapper.readValue(jsonNoLength, ExtractionFn.class);
    Assert.assertEquals(1, extractionFn.getIndex());
    Assert.assertEquals(new Integer(3), extractionFn.getLength());
    Assert.assertEquals(1, extractionFnNoLength.getIndex());
    Assert.assertEquals(null, extractionFnNoLength.getLength());
    // round trip
    Assert.assertEquals(extractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class));
    Assert.assertEquals(extractionFnNoLength, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFnNoLength), ExtractionFn.class));
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 35 with DefaultObjectMapper

use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class TimeDimExtractionFnTest method testSerde.

@Test
public void testSerde() throws Exception {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    final String json = "{ \"type\" : \"time\", \"timeFormat\" : \"MM/dd/yyyy\", \"resultFormat\" : \"QQQ/yyyy\" }";
    TimeDimExtractionFn extractionFn = (TimeDimExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
    Assert.assertEquals("MM/dd/yyyy", extractionFn.getTimeFormat());
    Assert.assertEquals("QQQ/yyyy", extractionFn.getResultFormat());
    // round trip
    Assert.assertEquals(extractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class));
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)164 Test (org.junit.Test)133 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)112 Interval (org.joda.time.Interval)24 DateTime (org.joda.time.DateTime)17 DataSegment (io.druid.timeline.DataSegment)16 File (java.io.File)16 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)14 Before (org.junit.Before)13 Map (java.util.Map)11 Period (org.joda.time.Period)11 Query (io.druid.query.Query)9 Result (io.druid.query.Result)9 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)9 IOException (java.io.IOException)9 DataSchema (io.druid.segment.indexing.DataSchema)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Sequence (io.druid.java.util.common.guava.Sequence)7 UniformGranularitySpec (io.druid.segment.indexing.granularity.UniformGranularitySpec)7 List (java.util.List)7