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));
}
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);
}
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);
}
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));
}
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);
}
Aggregations