use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class URIExtractionNamespaceTest method testMatchedJson.
@Test
public void testMatchedJson() throws IOException {
final ObjectMapper mapper = registerTypes(new DefaultObjectMapper());
URIExtractionNamespace namespace = mapper.readValue("{\"type\":\"uri\", \"uriPrefix\":\"file:/foo\", \"namespaceParseSpec\":{\"format\":\"simpleJson\"}, \"pollPeriod\":\"PT5M\", \"versionRegex\":\"a.b.c\", \"namespace\":\"testNamespace\"}", URIExtractionNamespace.class);
Assert.assertEquals(URIExtractionNamespace.ObjectMapperFlatDataParser.class.getCanonicalName(), namespace.getNamespaceParseSpec().getClass().getCanonicalName());
Assert.assertEquals("file:/foo", namespace.getUriPrefix().toString());
Assert.assertEquals("a.b.c", namespace.getFileRegex());
Assert.assertEquals(5L * 60_000L, namespace.getPollMs());
}
use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class NamespacedExtractorModuleTest method testNewTask.
@Test
public void testNewTask() throws Exception {
final File tmpFile = temporaryFolder.newFile();
try (OutputStreamWriter out = new FileWriter(tmpFile)) {
out.write(mapper.writeValueAsString(ImmutableMap.<String, String>of("foo", "bar")));
}
final URIExtractionNamespaceCacheFactory factory = new URIExtractionNamespaceCacheFactory(ImmutableMap.<String, SearchableVersionedDataFinder>of("file", new LocalFileTimestampVersionFinder()));
final URIExtractionNamespace namespace = new URIExtractionNamespace(tmpFile.toURI(), null, null, new URIExtractionNamespace.ObjectMapperFlatDataParser(URIExtractionNamespaceTest.registerTypes(new DefaultObjectMapper())), new Period(0), null);
CacheScheduler.VersionedCache versionedCache = factory.populateCache(namespace, null, null, scheduler);
Assert.assertNotNull(versionedCache);
Map<String, String> map = versionedCache.getCache();
Assert.assertEquals("bar", map.get("foo"));
Assert.assertEquals(null, map.get("baz"));
}
use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class AggregationTestHelper method createSelectQueryAggregationTestHelper.
public static final AggregationTestHelper createSelectQueryAggregationTestHelper(List<? extends Module> jsonModulesToRegister, TemporaryFolder tempFolder) {
ObjectMapper mapper = new DefaultObjectMapper();
mapper.setInjectableValues(new InjectableValues.Std().addValue(SelectQueryConfig.class, new SelectQueryConfig(true)));
Supplier<SelectQueryConfig> configSupplier = Suppliers.ofInstance(new SelectQueryConfig(true));
SelectQueryQueryToolChest toolchest = new SelectQueryQueryToolChest(new DefaultObjectMapper(), QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator(), configSupplier);
SelectQueryRunnerFactory factory = new SelectQueryRunnerFactory(new SelectQueryQueryToolChest(new DefaultObjectMapper(), QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator(), configSupplier), new SelectQueryEngine(configSupplier), 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 io.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class AggregationTestHelper method createTimeseriesQueryAggregationTestHelper.
public static final AggregationTestHelper createTimeseriesQueryAggregationTestHelper(List<? extends Module> jsonModulesToRegister, TemporaryFolder tempFolder) {
ObjectMapper mapper = new DefaultObjectMapper();
TimeseriesQueryQueryToolChest toolchest = new TimeseriesQueryQueryToolChest(QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator());
TimeseriesQueryRunnerFactory factory = new TimeseriesQueryRunnerFactory(toolchest, new TimeseriesQueryEngine(), 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 io.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class HistogramTest method testAsVisual.
@Test
public void testAsVisual() throws Exception {
float[] breaks = { -1f, -0.5f, 0.0f, 0.5f, 1f };
long[] bins = { 23, 123, 4, 56, 7, 493210 };
Histogram h = new Histogram(breaks, bins, -1f, 1f);
Double[] visualBreaks = { -1.0, -0.5, 0.0, 0.5, 1.0 };
Double[] visualCounts = { 123., 4., 56., 7. };
ObjectMapper objectMapper = new DefaultObjectMapper();
String json = objectMapper.writeValueAsString(h.asVisual());
Map<String, Object> expectedObj = Maps.newLinkedHashMap();
expectedObj.put("breaks", Arrays.asList(visualBreaks));
expectedObj.put("counts", Arrays.asList(visualCounts));
expectedObj.put("quantiles", Arrays.asList(new Double[] { -1.0, 1.0 }));
Map<String, Object> obj = (Map<String, Object>) objectMapper.readValue(json, Object.class);
Assert.assertEquals(expectedObj, obj);
}
Aggregations