in src/main/java/org/apache/datasketches/server/DataQueryHandler.java [108:183]
private static JsonObject processDistinctQuery(final JsonObject result, final JsonObject query, final Family type, final Object sketch) {
if (query == null || type == null || sketch == null) {
return null;
}
// check if we need a summary
final boolean addSummary = checkSummaryFlag(query);
String summary = null;
final double estimate;
final boolean isEstimationMode;
final double p1StdDev;
final double p2StdDev;
final double p3StdDev;
final double m1StdDev;
final double m2StdDev;
final double m3StdDev;
switch (type) {
case UNION:
final CompactSketch thetaSketch = ((Union) sketch).getResult();
isEstimationMode = thetaSketch.isEstimationMode();
estimate = thetaSketch.getEstimate();
p1StdDev = thetaSketch.getUpperBound(1);
p2StdDev = thetaSketch.getUpperBound(2);
p3StdDev = thetaSketch.getUpperBound(3);
m1StdDev = thetaSketch.getLowerBound(1);
m2StdDev = thetaSketch.getLowerBound(2);
m3StdDev = thetaSketch.getLowerBound(3);
if (addSummary) { summary = thetaSketch.toString(); }
break;
case CPC:
final CpcSketch cpcSketch = (CpcSketch) sketch;
isEstimationMode = true; // no exact mode
estimate = cpcSketch.getEstimate();
p1StdDev = cpcSketch.getUpperBound(1);
p2StdDev = cpcSketch.getUpperBound(2);
p3StdDev = cpcSketch.getUpperBound(3);
m1StdDev = cpcSketch.getLowerBound(1);
m2StdDev = cpcSketch.getLowerBound(2);
m3StdDev = cpcSketch.getLowerBound(3);
if (addSummary) { summary = cpcSketch.toString(); }
break;
case HLL:
final HllSketch hllSketch = (HllSketch) sketch;
isEstimationMode = hllSketch.isEstimationMode();
estimate = hllSketch.getEstimate();
p1StdDev = hllSketch.getUpperBound(1);
p2StdDev = hllSketch.getUpperBound(2);
p3StdDev = hllSketch.getUpperBound(3);
m1StdDev = hllSketch.getLowerBound(1);
m2StdDev = hllSketch.getLowerBound(2);
m3StdDev = hllSketch.getLowerBound(3);
if (addSummary) { summary = hllSketch.toString(); }
break;
default:
throw new IllegalArgumentException("Unknown distinct counting sketch type: " + type);
}
//final JsonObject result = new JsonObject();
result.addProperty(RESPONSE_ESTIMATE_FIELD, estimate);
result.addProperty(RESPONSE_ESTIMATION_MODE_FIELD, isEstimationMode);
result.addProperty(RESPONSE_P1STDEV_FIELD, p1StdDev);
result.addProperty(RESPONSE_P2STDEV_FIELD, p2StdDev);
result.addProperty(RESPONSE_P3STDEV_FIELD, p3StdDev);
result.addProperty(RESPONSE_M1STDEV_FIELD, m1StdDev);
result.addProperty(RESPONSE_M2STDEV_FIELD, m2StdDev);
result.addProperty(RESPONSE_M3STDEV_FIELD, m3StdDev);
if (addSummary)
result.addProperty(RESPONSE_SUMMARY_FIELD, summary);
return result;
}