Search in sources :

Example 1 with MomentSketchWrapper

use of org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper in project druid by druid-io.

the class MomentSketchAggregatorFactory method combine.

@Override
public Object combine(@Nullable Object lhs, @Nullable Object rhs) {
    if (lhs == null) {
        return rhs;
    }
    if (rhs == null) {
        return lhs;
    }
    MomentSketchWrapper union = (MomentSketchWrapper) lhs;
    union.merge((MomentSketchWrapper) rhs);
    return union;
}
Also used : MomentSketchWrapper(org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper)

Example 2 with MomentSketchWrapper

use of org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper in project druid by druid-io.

the class MomentSketchBuildBufferAggregator method init.

@Override
public synchronized void init(final ByteBuffer buffer, final int position) {
    ByteBuffer mutationBuffer = buffer.duplicate();
    mutationBuffer.position(position);
    MomentSketchWrapper emptyStruct = new MomentSketchWrapper(k);
    emptyStruct.setCompressed(compress);
    emptyStruct.toBytes(mutationBuffer);
}
Also used : MomentSketchWrapper(org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper) ByteBuffer(java.nio.ByteBuffer)

Example 3 with MomentSketchWrapper

use of org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper in project druid by druid-io.

the class MomentSketchMergeBufferAggregator method init.

@Override
public void init(ByteBuffer buf, int position) {
    MomentSketchWrapper h = new MomentSketchWrapper(size);
    h.setCompressed(compress);
    ByteBuffer mutationBuffer = buf.duplicate();
    mutationBuffer.position(position);
    h.toBytes(mutationBuffer);
}
Also used : MomentSketchWrapper(org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper) ByteBuffer(java.nio.ByteBuffer)

Example 4 with MomentSketchWrapper

use of org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper in project druid by druid-io.

the class MomentSketchQuantilePostAggregator method compute.

@Override
public Object compute(final Map<String, Object> combinedAggregators) {
    final MomentSketchWrapper sketch = (MomentSketchWrapper) field.compute(combinedAggregators);
    double[] quantiles = sketch.getQuantiles(fractions);
    return quantiles;
}
Also used : MomentSketchWrapper(org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper)

Example 5 with MomentSketchWrapper

use of org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper in project druid by druid-io.

the class MomentsSketchAggregatorTest method buildingSketchesAtQueryTime.

@Test
public void buildingSketchesAtQueryTime() throws Exception {
    Sequence<ResultRow> seq = helper.createIndexAndRunQueryOnSegment(new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), String.join("\n", "{", "  \"type\": \"string\",", "  \"parseSpec\": {", "    \"format\": \"tsv\",", "    \"timestampSpec\": {\"column\": \"timestamp\", \"format\": \"yyyyMMddHH\"},", "    \"dimensionsSpec\": {", "      \"dimensions\": [ \"product\", {\"name\":\"valueWithNulls\", \"type\":\"double\"}],", "      \"dimensionExclusions\": [\"sequenceNumber\"],", "      \"spatialDimensions\": []", "    },", "    \"columns\": [\"timestamp\", \"sequenceNumber\", \"product\", \"value\", \"valueWithNulls\"]", "  }", "}"), "[{\"type\": \"doubleSum\", \"name\": \"value\", \"fieldName\": \"value\"}]", // minTimestamp
    0, Granularities.NONE, // maxRowCount
    10, String.join("\n", "{", "  \"queryType\": \"groupBy\",", "  \"dataSource\": \"test_datasource\",", "  \"granularity\": \"ALL\",", "  \"dimensions\": [],", "  \"aggregations\": [", "    {\"type\": \"momentSketch\", \"name\": \"sketch\", \"fieldName\": \"value\", \"k\": 10},", "    {\"type\": \"momentSketch\", \"name\": \"sketchWithNulls\", \"fieldName\": \"valueWithNulls\", \"k\": 10}", "  ],", "  \"intervals\": [\"2016-01-01T00:00:00.000Z/2016-01-31T00:00:00.000Z\"]", "}"));
    List<ResultRow> results = seq.toList();
    Assert.assertEquals(1, results.size());
    ResultRow row = results.get(0);
    // "sketch"
    MomentSketchWrapper sketchObject = (MomentSketchWrapper) row.get(0);
    // 385 total products since roll-up limited by valueWithNulls column
    Assert.assertEquals(385.0, sketchObject.getPowerSums()[0], 1e-10);
    // "sketchWithNulls"
    MomentSketchWrapper sketchObjectWithNulls = (MomentSketchWrapper) row.get(1);
    // in default mode, all 385 rows have a number value so will be computed, but only 377 rows have actual values in
    // sql null mode
    Assert.assertEquals(hasNulls ? 377.0 : 385.0, sketchObjectWithNulls.getPowerSums()[0], 1e-10);
}
Also used : ResultRow(org.apache.druid.query.groupby.ResultRow) MomentSketchWrapper(org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper) File(java.io.File) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) GroupByQueryRunnerTest(org.apache.druid.query.groupby.GroupByQueryRunnerTest)

Aggregations

MomentSketchWrapper (org.apache.druid.query.aggregation.momentsketch.MomentSketchWrapper)9 ByteBuffer (java.nio.ByteBuffer)4 File (java.io.File)2 GroupByQueryRunnerTest (org.apache.druid.query.groupby.GroupByQueryRunnerTest)2 ResultRow (org.apache.druid.query.groupby.ResultRow)2 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)2 Test (org.junit.Test)2