[ 
https://issues.apache.org/jira/browse/DRILL-7117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16804475#comment-16804475
 ] 

ASF GitHub Bot commented on DRILL-7117:
---------------------------------------

amansinha100 commented on pull request #1715: DRILL-7117: Support creation of 
equi-depth histogram for selected dat…
URL: https://github.com/apache/drill/pull/1715#discussion_r270244682
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/statistics/TDigestMergedStatistic.java
 ##########
 @@ -0,0 +1,135 @@
+/*
+ * 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.drill.exec.physical.impl.statistics;
+
+// Library implementing TDigest algorithm to derive approximate quantiles. 
Please refer to:
+// 'Computing Extremely Accurate Quantiles using t-Digests' by Ted Dunning and 
Otmar Ertl
+
+import com.clearspring.analytics.stream.quantile.TDigest;
+import org.apache.drill.common.types.TypeProtos;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.server.options.OptionManager;
+import org.apache.drill.exec.vector.NullableVarBinaryVector;
+import org.apache.drill.exec.vector.ValueVector;
+import org.apache.drill.exec.vector.complex.MapVector;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.nio.ByteBuffer;
+
+public class TDigestMergedStatistic extends AbstractMergedStatistic {
+  private Map<String, TDigest> tdigestHolder;
+  private int compression;
+
+  public TDigestMergedStatistic() {
+    this.tdigestHolder = new HashMap<>();
+    state = State.INIT;
+  }
+
+  @Override
+  public void initialize(String inputName, double samplePercent) {
+    super.initialize(Statistic.TDIGEST_MERGE, inputName, samplePercent);
+    state = State.CONFIG;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+
+  @Override
+  public String getInput() {
+    return inputName;
+  }
+
+  @Override
+  public void merge(MapVector input) {
+    // Check the input is a Map Vector
+    assert (input.getField().getType().getMinorType() == 
TypeProtos.MinorType.MAP);
+    for (ValueVector vv : input) {
+      String colName = vv.getField().getName();
+      TDigest colTdigestHolder = null;
+      if (tdigestHolder.get(colName) != null) {
+        colTdigestHolder = tdigestHolder.get(colName);
+      }
+      NullableVarBinaryVector tdigestVector = (NullableVarBinaryVector) vv;
+      NullableVarBinaryVector.Accessor accessor = tdigestVector.getAccessor();
+
+      try {
+        if (!accessor.isNull(0)) {
+          TDigest other = TDigest.fromBytes(ByteBuffer.wrap(accessor.get(0)));
+          if (colTdigestHolder != null) {
+            colTdigestHolder.add(other);
+            tdigestHolder.put(colName, colTdigestHolder);
+          } else {
+            tdigestHolder.put(colName, other);
+          }
+        }
+      } catch (Exception ex) {
+        //TODO: Catch IOException/CardinalityMergeException
 
 Review comment:
   I will add logging for this. 
 
----------------------------------------------------------------
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:
us...@infra.apache.org


> Support creation of histograms for numeric data types (except Decimal) and 
> date/time/timestamp
> ----------------------------------------------------------------------------------------------
>
>                 Key: DRILL-7117
>                 URL: https://issues.apache.org/jira/browse/DRILL-7117
>             Project: Apache Drill
>          Issue Type: Sub-task
>          Components: Query Planning &amp; Optimization
>            Reporter: Aman Sinha
>            Assignee: Aman Sinha
>            Priority: Major
>             Fix For: 1.16.0
>
>
> This JIRA is specific to creating histograms for numeric data types: INT, 
> BIGINT, FLOAT4, FLOAT8  and their corresponding nullable/non-nullable 
> versions.  Additionally, since DATE/TIME/TIMESTAMP are internally stored as 
> longs, we should allow the same numeric type histogram creation for these 
> data types as well. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to