jtuglu1 commented on code in PR #18426:
URL: https://github.com/apache/druid/pull/18426#discussion_r2299804997


##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllPostAggExprMacros.java:
##########
@@ -88,5 +105,44 @@ public ExprEval eval(ObjectBinding bindings)
       return round ? ExprEval.of(Math.round(estimate)) : ExprEval.of(estimate);
     }
   }
+
+  public static class HllSketchEstimateWithErrorBoundsExpr extends 
ExprMacroTable.BaseScalarMacroFunctionExpr
+  {
+    private Expr estimateExpr;
+    private Expr numStdDev;
+
+    public 
HllSketchEstimateWithErrorBoundsExpr(HllSketchEstimateWithErrorBoundsExprMacro 
macro, List<Expr> args)
+    {
+      super(macro, args);
+      this.estimateExpr = args.get(0);
+      if (args.size() == 2) {
+        numStdDev = args.get(1);
+      }
+    }
+
+    @Nullable
+    @Override
+    public ExpressionType getOutputType(InputBindingInspector inspector)
+    {
+      return ExpressionType.DOUBLE_ARRAY;
+    }
+
+    @Override
+    public ExprEval eval(ObjectBinding bindings)
+    {
+      int numStdDevs = 
HllSketchToEstimateWithBoundsPostAggregator.DEFAULT_NUM_STD_DEVS;
+      ExprEval eval = estimateExpr.eval(bindings);
+      if (numStdDev != null) {
+        numStdDevs = numStdDev.eval(bindings).asInt();
+      }
+
+      final Object valObj = eval.value();
+      if (valObj == null) {
+        return ExprEval.ofDoubleArray(new Double[]{0.0D, 0.0D, 0.0D});
+      }
+      HllSketchHolder sketch = HllSketchHolder.fromObj(valObj);
+      return ExprEval.ofDoubleArray(new Double[]{sketch.getEstimate(), 
sketch.getLowerBound(numStdDevs), sketch.getUpperBound(numStdDevs)});

Review Comment:
   I'm assuming it doesn't matter that `SketchEstimateWithErrorBounds` ctor 
used in ThetaSketch puts the parameter ordering like:
   ```
   estimate
   high
   low
   numstdev
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to