Search in sources :

Example 6 with ComplexMetricExtractor

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"));
}
Also used : HashMap(java.util.HashMap) ComplexMetricExtractor(org.apache.druid.segment.serde.ComplexMetricExtractor) MapBasedInputRow(org.apache.druid.data.input.MapBasedInputRow) Test(org.junit.Test)

Example 7 with ComplexMetricExtractor

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;
            }
        }
    };
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector) ComplexMetricExtractor(org.apache.druid.segment.serde.ComplexMetricExtractor) InputRow(org.apache.druid.data.input.InputRow)

Example 8 with ComplexMetricExtractor

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);
}
Also used : DoublesSketch(org.apache.datasketches.quantiles.DoublesSketch) ComplexMetricExtractor(org.apache.druid.segment.serde.ComplexMetricExtractor) MapBasedInputRow(org.apache.druid.data.input.MapBasedInputRow) Test(org.junit.Test)

Aggregations

ComplexMetricExtractor (org.apache.druid.segment.serde.ComplexMetricExtractor)8 MapBasedInputRow (org.apache.druid.data.input.MapBasedInputRow)7 Test (org.junit.Test)6 DoublesSketch (org.apache.datasketches.quantiles.DoublesSketch)5 InputRow (org.apache.druid.data.input.InputRow)2 HashMap (java.util.HashMap)1 HyperLogLogCollector (org.apache.druid.hll.HyperLogLogCollector)1 ISE (org.apache.druid.java.util.common.ISE)1 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)1 RuntimeShapeInspector (org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)1 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)1 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)1 NilColumnValueSelector (org.apache.druid.segment.NilColumnValueSelector)1 RowBasedColumnSelectorFactory (org.apache.druid.segment.RowBasedColumnSelectorFactory)1 ComplexMetricSerde (org.apache.druid.segment.serde.ComplexMetricSerde)1