clintropolis commented on code in PR #12498:
URL: https://github.com/apache/druid/pull/12498#discussion_r941939444


##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/kll/KllDoublesSketchToCDFPostAggregator.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.datasketches.kll;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import org.apache.datasketches.kll.KllDoublesSketch;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.query.aggregation.AggregatorFactory;
+import org.apache.druid.query.aggregation.PostAggregator;
+import org.apache.druid.query.aggregation.post.PostAggregatorIds;
+import org.apache.druid.query.cache.CacheKeyBuilder;
+import org.apache.druid.segment.ColumnInspector;
+import org.apache.druid.segment.column.ColumnType;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Map;
+import java.util.Set;
+
+public class KllDoublesSketchToCDFPostAggregator implements PostAggregator
+{
+
+  private final String name;
+  private final PostAggregator field;
+  private final double[] splitPoints;
+
+  @JsonCreator
+  public KllDoublesSketchToCDFPostAggregator(
+      @JsonProperty("name") final String name,
+      @JsonProperty("field") final PostAggregator field,
+      @JsonProperty("splitPoints") final double[] splitPoints)
+  {
+    this.name = Preconditions.checkNotNull(name, "name is null");
+    this.field = Preconditions.checkNotNull(field, "field is null");
+    this.splitPoints = Preconditions.checkNotNull(splitPoints, "array of split 
points is null");
+  }
+
+  @Override
+  public Object compute(final Map<String, Object> combinedAggregators)
+  {
+    final KllDoublesSketch sketch = (KllDoublesSketch) 
field.compute(combinedAggregators);
+    if (sketch.isEmpty()) {
+      final double[] cdf = new double[splitPoints.length + 1];
+      Arrays.fill(cdf, Double.NaN);
+      return cdf;

Review Comment:
   I think `double[]` is ok to return here (it actually isn't currently, if the 
output of this is fed into an expression without a round-trip through Jackson, 
but this I think is a flaw and I'm going to fix that). When I fix the issue 
with `double[]` I will also update the javadocs for `ColumnType` to indicate 
the allowed return types.



-- 
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