leventov commented on a change in pull request #6581: Moments Sketch custom 
aggregator
URL: https://github.com/apache/incubator-druid/pull/6581#discussion_r231727983
 
 

 ##########
 File path: 
extensions-contrib/momentsketch/src/main/java/org/apache/druid/query/aggregation/momentsketch/MomentSketchWrapper.java
 ##########
 @@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.query.aggregation.momentsketch;
+
+import com.github.stanfordfuturedata.momentsketch.MomentSolver;
+import com.github.stanfordfuturedata.momentsketch.MomentStruct;
+
+import java.nio.ByteBuffer;
+
+public class MomentSketchWrapper
+{
+  public MomentStruct data;
+  // Whether we use arcsinh to compress the range
+  public boolean useArcSinh = true;
+
+  public MomentSketchWrapper(
+      int k
+  )
+  {
+    data = new MomentStruct(k);
+  }
+
+  public MomentSketchWrapper(
+      MomentStruct data
+  )
+  {
+    this.data = data;
+  }
+
+  public void setCompressed(boolean flag)
+  {
+    useArcSinh = flag;
+  }
+
+  public boolean getCompressed()
+  {
+    return useArcSinh;
+  }
+
+  public int getK()
+  {
+    return data.power_sums.length;
+  }
+
+  public double[] getPowerSums()
+  {
+    return data.power_sums;
+  }
+
+  public double getMin()
+  {
+    return data.min;
+  }
+
+  public double getMax()
+  {
+    return data.max;
+  }
+
+  public void add(double rawX)
+  {
+    double x = rawX;
+    if (useArcSinh) {
+      x = Math.log(rawX + Math.sqrt(1 + rawX * rawX));
+    }
+    data.add(x);
+  }
+
+  public void merge(MomentSketchWrapper other)
+  {
+    data.merge(other.data);
+  }
+
+  public byte[] toByteArray()
+  {
+    ByteBuffer bb = ByteBuffer.allocate(2 * Integer.BYTES + 
(data.power_sums.length + 2) * Double.BYTES);
+    return toBytes(bb).array();
+  }
+
+  public MomentSolver getSolver()
+  {
+    MomentSolver ms = new MomentSolver(data);
+    return ms;
+  }
+
+  public double[] getQuantiles(double[] fractions)
+  {
+    MomentSolver ms = new MomentSolver(data);
+    ms.setGridSize(1024);
 
 Review comment:
   Please add some explanation about why 1024 and 15 are chosen

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to