You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2019/05/08 08:11:49 UTC

[GitHub] [incubator-druid] samarthjain commented on a change in pull request #7331: TDigest backed sketch aggregators

samarthjain commented on a change in pull request #7331: TDigest backed sketch aggregators
URL: https://github.com/apache/incubator-druid/pull/7331#discussion_r281958380
 
 

 ##########
 File path: extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestBuildSketchBufferAggregator.java
 ##########
 @@ -0,0 +1,125 @@
+/*
+ * 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.tdigestsketch;
+
+import com.google.common.base.Preconditions;
+import com.tdunning.math.stats.MergingDigest;
+import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.query.aggregation.BufferAggregator;
+import org.apache.druid.segment.ColumnValueSelector;
+
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.GuardedBy;
+import java.nio.ByteBuffer;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+/**
+ * Aggregator that builds t-digest backed sketches using numeric values read from {@link ByteBuffer}
+ */
+public class TDigestBuildSketchBufferAggregator implements BufferAggregator
+{
+
+  @Nonnull
+  private final ColumnValueSelector selector;
+  @Nonnull
+  private final int compression;
+
+  @GuardedBy("this")
+  private Map<ByteBuffer, Int2ObjectMap<MergingDigest>> sketches = new IdentityHashMap<>();
+
+  public TDigestBuildSketchBufferAggregator(
+      final ColumnValueSelector valueSelector,
+      final Integer compression
+  )
+  {
+    Preconditions.checkNotNull(valueSelector);
+    this.selector = valueSelector;
+    if (compression != null) {
+      this.compression = compression;
+    } else {
+      this.compression = TDigestBuildSketchAggregator.DEFAULT_COMPRESSION;
+    }
+  }
+
+  @Override
+  public synchronized void init(ByteBuffer buffer, int position)
 
 Review comment:
   @jihoonson - unfortunately the documentation on the base classes/interfaces doesn't clearly mention which methods could be called in a multi-threaded fashion. So I ended up following what the DataSketches implementation does. 
   For ex - 
   https://github.com/apache/incubator-druid/blob/master/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/DoublesSketchBuildBufferAggregator.java#L54
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org