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