jkrdev commented on a change in pull request #320: ACCUMULO-4730 Created 
EntryLengthSummarizer
URL: https://github.com/apache/accumulo/pull/320#discussion_r150548023
 
 

 ##########
 File path: 
core/src/main/java/org/apache/accumulo/core/client/summary/summarizers/EntryLengthSummarizer.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.accumulo.core.client.summary.summarizers;
+
+import java.math.RoundingMode;
+import java.util.Map;
+
+import org.apache.accumulo.core.client.summary.Summarizer;
+import org.apache.accumulo.core.client.summary.SummarizerConfiguration;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Value;
+
+import com.google.common.math.IntMath;
+
+/**
+ * Summarizer that computes summary information about field lengths.
+ * Specifically key length, row length, family length, qualifier length, 
visibility length, and value length.
+ * Incrementally computes minimum, maximum, count, sum, and log2 histogram of 
the lengths.
+ */
+public class EntryLengthSummarizer implements Summarizer {
+
+  /* Helper function that calculates the various statistics that is used for 
the Collector methods.*/
+  private static class LengthStats {
+    private long min = Long.MAX_VALUE;
+    private long max = Long.MIN_VALUE;
+    private long sum = 0;
+    private long[] counts = new long[32];
+
+    private void accept(int length) {
+      int idx;
+
+      if (length < min) {
+        min = length;
+      }
+
+      if (length > max) {
+        max = length;
+      }
+
+      sum += length;
+
+      if (length == 0) {
+        idx = 0;
+      } else {
+        idx = IntMath.log2(length, RoundingMode.HALF_UP);
+      }
+
+      counts[idx]++;
+    }
+
+    void summarize (String prefix, StatisticConsumer sc) {
+      sc.accept(prefix+".min", (min != Long.MAX_VALUE ? min:0));
+      sc.accept(prefix+".max", (max != Long.MIN_VALUE ? max:0));
+      sc.accept(prefix+".sum", sum);
+
+      for (int i = 0; i < counts.length; i++) {
+        if (counts[i] > 0) {
+          sc.accept(prefix+".logHist."+i, counts[i]);
+        }
+      }
+    }
+
+  }
+
+  /* Helper function for merging that is used by the Combiner. */
+  private static void merge(String prefix, Map<String, Long> stats1, 
Map<String,Long> stats2 ) {
+    stats1.merge(prefix+".min", stats2.get(prefix+".min"), Long::max);
+    stats1.merge(prefix+".max", stats2.get(prefix+".max"), Long::max);
+    stats1.merge(prefix+".sum", stats2.get(prefix+".sum"), Long::sum);
+    stats2.forEach((k,v) -> stats1.merge(k, v, Long::sum));
 
 Review comment:
   Hmmm so for the Combiner I think I understand what should happen for the 
values that are singular; min,max,sum, and total, but for the log2Histo should 
it just add the value of the 2nd map to the 1st and combine the total for keys 
that match? 

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

Reply via email to