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

 ##########
 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:
   If a query is issued while a stream ingestion task is running, then the 
query would be routed to that task. This is when concurrent reads and writes 
can happen. Since only `OnHeapIncrementalIndex` is used at ingestion time which 
uses `Aggregator`, we need to consider if there's any concurrency issue between 
`get()` and `aggregate()`. Check out these comments: 
https://github.com/apache/incubator-druid/pull/5002#issuecomment-341179982, 
https://github.com/apache/incubator-druid/pull/5148#discussion_r170906998
   
   I'm not sure why `HistogramAggregator` is not synchronized even though it 
looks to have to. 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to