Search in sources :

Example 96 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class DataSourceMetadataQueryTest method testContextSerde.

@Test
public void testContextSerde() throws Exception {
    final DataSourceMetadataQuery query = Druids.newDataSourceMetadataQueryBuilder().dataSource("foo").intervals("2013/2014").context(ImmutableMap.<String, Object>of("priority", 1, "useCache", true, "populateCache", "true", "finalize", true)).build();
    final ObjectMapper mapper = new DefaultObjectMapper();
    final Query serdeQuery = mapper.readValue(mapper.writeValueAsBytes(mapper.readValue(mapper.writeValueAsString(query), Query.class)), Query.class);
    Assert.assertEquals(1, serdeQuery.getContextValue("priority"));
    Assert.assertEquals(true, serdeQuery.getContextValue("useCache"));
    Assert.assertEquals("true", serdeQuery.getContextValue("populateCache"));
    Assert.assertEquals(true, serdeQuery.getContextValue("finalize"));
    Assert.assertEquals(true, serdeQuery.getContextBoolean("useCache", false));
    Assert.assertEquals(true, serdeQuery.getContextBoolean("populateCache", false));
    Assert.assertEquals(true, serdeQuery.getContextBoolean("finalize", false));
}
Also used : Query(io.druid.query.Query) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 97 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class AggregationTestHelper method createGroupByQueryAggregationTestHelper.

public static final AggregationTestHelper createGroupByQueryAggregationTestHelper(List<? extends Module> jsonModulesToRegister, GroupByQueryConfig config, TemporaryFolder tempFolder) {
    ObjectMapper mapper = new DefaultObjectMapper();
    GroupByQueryRunnerFactory factory = GroupByQueryRunnerTest.makeQueryRunnerFactory(mapper, config);
    IndexIO indexIO = new IndexIO(mapper, new ColumnConfig() {

        @Override
        public int columnCacheSizeBytes() {
            return 0;
        }
    });
    return new AggregationTestHelper(mapper, new IndexMerger(mapper, indexIO), indexIO, factory.getToolchest(), factory, tempFolder, jsonModulesToRegister);
}
Also used : IndexMerger(io.druid.segment.IndexMerger) GroupByQueryRunnerFactory(io.druid.query.groupby.GroupByQueryRunnerFactory) IndexIO(io.druid.segment.IndexIO) ColumnConfig(io.druid.segment.column.ColumnConfig) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 98 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper 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 99 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper 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 100 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper 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)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1523 Test (org.junit.Test)608 JsonNode (com.fasterxml.jackson.databind.JsonNode)217 IOException (java.io.IOException)191 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)172 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 Map (java.util.Map)122 HashMap (java.util.HashMap)111 ArrayList (java.util.ArrayList)71 File (java.io.File)56 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)53 JCodeModel (com.sun.codemodel.JCodeModel)52 InputStream (java.io.InputStream)50 JPackage (com.sun.codemodel.JPackage)44 List (java.util.List)42 JsonException (jmri.server.json.JsonException)41 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)39 JType (com.sun.codemodel.JType)38 Test (org.testng.annotations.Test)36 JsonFactory (com.fasterxml.jackson.core.JsonFactory)34