use of org.apache.druid.segment.serde.ComplexMetricExtractor in project druid by druid-io.
the class ApproximateHistogramFoldingSerdeTest method testExtractor.
@Test
public void testExtractor() {
final ApproximateHistogramFoldingSerde serde = new ApproximateHistogramFoldingSerde();
final ComplexMetricExtractor extractor = serde.getExtractor();
final Map<String, Object> theMap = new HashMap<>();
theMap.put("nullValue", null);
theMap.put("listValue", ImmutableList.of("1.0", 2, 3.0));
theMap.put("stringValue", "1.0");
theMap.put("numberValue", 1.0);
final MapBasedInputRow row = new MapBasedInputRow(0L, ImmutableList.of(), theMap);
Assert.assertEquals("nullValue", new ApproximateHistogram(0), extractor.extractValue(row, "nullValue"));
Assert.assertEquals("missingValue", new ApproximateHistogram(0), extractor.extractValue(row, "missingValue"));
Assert.assertEquals("listValue", makeHistogram(1, 2, 3), extractor.extractValue(row, "listValue"));
Assert.assertEquals("stringValue", makeHistogram(1), extractor.extractValue(row, "stringValue"));
Assert.assertEquals("numberValue", makeHistogram(1), extractor.extractValue(row, "numberValue"));
}
use of org.apache.druid.segment.serde.ComplexMetricExtractor in project druid by druid-io.
the class HyperUniquesSerde method getExtractor.
@Override
public ComplexMetricExtractor<HyperLogLogCollector> getExtractor() {
return new ComplexMetricExtractor<HyperLogLogCollector>() {
@Override
public Class<HyperLogLogCollector> extractedClass() {
return HyperLogLogCollector.class;
}
@Override
public HyperLogLogCollector extractValue(InputRow inputRow, String metricName) {
Object rawValue = inputRow.getRaw(metricName);
if (rawValue instanceof HyperLogLogCollector) {
return (HyperLogLogCollector) rawValue;
} else {
HyperLogLogCollector collector = HyperLogLogCollector.makeLatestCollector();
List<String> dimValues = inputRow.getDimension(metricName);
if (dimValues == null) {
return collector;
}
for (String dimensionValue : dimValues) {
collector.add(hyperLogLogHash.hash(dimensionValue));
}
return collector;
}
}
};
}
use of org.apache.druid.segment.serde.ComplexMetricExtractor in project druid by druid-io.
the class DoublesSketchComplexMetricSerdeTest method testExtractorOnPositiveNumber.
@Test
public void testExtractorOnPositiveNumber() {
final DoublesSketchComplexMetricSerde serde = new DoublesSketchComplexMetricSerde();
final ComplexMetricExtractor extractor = serde.getExtractor();
final DoublesSketch sketch = (DoublesSketch) extractor.extractValue(new MapBasedInputRow(0L, ImmutableList.of(), ImmutableMap.of("foo", "777")), "foo");
Assert.assertEquals(1, sketch.getRetainedItems());
Assert.assertEquals(777d, sketch.getMaxValue(), 0.01d);
}
Aggregations