ACCUMULO-4730 Created EntryLengthSummarizer#320
ACCUMULO-4730 Created EntryLengthSummarizer#320jkrdev wants to merge 14 commits intoapache:masterfrom
Conversation
keith-turner
left a comment
There was a problem hiding this comment.
@jkrdev thanks for the contribution and welcome to Accumuo! I am still looking at this, I have not looked at the test yet.
| public static final String SUM_VALUES_STAT = "sumValues"; | ||
|
|
||
| public static final String TOTAL_STAT = "total";// Total number of Keys | ||
|
|
There was a problem hiding this comment.
It would be nice to reduce the redundant code. One possible way to do this is to create an internal class like the following.
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 lenght) {
int idx;

 if (length < minKey) {
 min = length;
 }

 if (length > max) {
 maxKey = length;
 }

 sum += length;

 if (length == 0) {
 idx = 0;
 } else {
 idx = IntMath.log2(length, RoundingMode.HALF_UP);
 }

 counts[idx]++;
}
void summarize(String prefix, SummaryConsumer sc) {
sc.accept(prefix+"min", (min != Long.MAX_VALUE ? min:0));
 sc.accept(prexif+"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]);
 }
 }
}
}Then create an instance of this class for each field and use it in the Collectors accept and summarize methods.
There was a problem hiding this comment.
Thanks I will implement this, definitely will make the code cleaner.
|
|
||
| }; | ||
| } | ||
|
|
There was a problem hiding this comment.
Could possibly a have static method like the following to cut down on redundant code.
private static merge(String prefix, Map<string, Long> stats1, Map<String, Long> stats2) {
// merge min, max, sum, and hist for all props with prefix.
}This method could be called for each prefix.
| 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)); |
There was a problem hiding this comment.
It seems like this will sum everything, even the min and max keys. I suspect this is only intended to sum log histogram keys? If so it needs a check for the key before doing merge. Also, it seems like the test should catch this?
There was a problem hiding this comment.
I'm not sure I can articulate this correctly but I will try. I believe that since there is only one value passed into the merge functions that the remapping function recomputes the same value passed in. If that makes sense. Either way though, I played around with that during my initial coding, and it doesn't in this particular case seem to make any difference. I could make that parameter "null" if that would be better, the output will be the same according to the test.
There was a problem hiding this comment.
Now looking at it again it does seem it shouldn't be working but why it is I don't exactly know, but again whether max, min, sum or null it returns sams values.
There was a problem hiding this comment.
I wasn't sure why the test were not catching this so I cloned the branch to experiment locally. Realized the test are not calling this code, I completely missed that. Below are the beginnings of a test I wrote while looking into this.
@Test
public void testFoo() {
SummarizerConfiguration sc = SummarizerConfiguration.builder(EntryLengthSummarizer.class).build();
EntryLengthSummarizer entrySum = new EntryLengthSummarizer();
Collector collector1 = entrySum.collector(sc);
collector1.accept(new Key("1","f1","q1"), new Value("v1"));
collector1.accept(new Key("1234","f1","q1"), new Value("v111"));
collector1.accept(new Key("12345678","f1","q1"), new Value("v111111"));
Map<String, Long> stats1 = new TreeMap<>();
collector1.summarize(stats1::put);
Collector collector2 = entrySum.collector(sc);
collector2.accept(new Key("5432","f11","q12"), new Value("2"));
collector2.accept(new Key("12","f11","q1234"), new Value("12"));
collector2.accept(new Key("12","f11","q11234567"), new Value("4444"));
Map<String, Long> stats2 = new TreeMap<>();
collector2.summarize(stats2::put);
System.out.println("========= Stats 1");
stats1.entrySet().forEach(System.out::println);
System.out.println("========= Stats 2");
stats2.entrySet().forEach(System.out::println);
Combiner combiner = entrySum.combiner(sc);
combiner.merge(stats1, stats2);
System.out.println("========= Merged");
stats1.entrySet().forEach(System.out::println);
}There was a problem hiding this comment.
Oh wow that is complete oversight on my part, I was so focused on the Collector, I didn't test the Combiner. I will write up some test for that also and fix according. Thanks for pointing this out.
There was a problem hiding this 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?
| } | ||
|
|
||
| /* i must be less than 32 since counts[] size max is 32. */ | ||
| for (int i = 0; i < 32; i++) { |
There was a problem hiding this comment.
Not quite sure if 32 is correct here, if someone can confirm would be appreciated.
|
|
||
| /* Helper function for merging that is used by the Combiner. */ | ||
| private static void merge(String prefix, Map<String, Long> stats1, Map<String,Long> stats2 ) { | ||
| if (stats2.containsKey(prefix+".min") && (stats1.containsKey(prefix+".min") == false)) { |
There was a problem hiding this comment.
I would put this code into a private function where you pass in a key and function. Something like the following
private void merge(String key, BiFunction<Long,Long,Long> mergeFunc, Map<String, Long> stats1, Map<String,Long> stats2){...}Then the code in this function could just call
merge(prefix+".min", Long::min, stats1, stats2);|
|
||
| /* Helper functions for merging that is used by the Combiner. */ | ||
| private static void merge(String key, BiFunction<Long,Long,Long> mergeFunc, Map<String, Long> stats1, Map<String,Long> stats2) { | ||
| if (stats2.containsKey(key) && (stats1.containsKey(key) == false)) { |
There was a problem hiding this comment.
I think Java's merge() function on map handles the case where a key is not present. So I think the following code will insert the value from stats2 if stats1 did not have a value (w/o calling mergeFunc).
Long val2 = stats2.get(key);
if(val2 != null) {
stats1.merge(key, val2, mergeFunc);
}This also avoid calling contains() and then later get() on the map which is two lookups.
| HashMap<String, Long> stats2 = new HashMap<>(); | ||
| collector2.summarize(stats2::put); | ||
|
|
||
| /* |
There was a problem hiding this comment.
should remove these comments
| combiner.merge(stats1, stats2); | ||
|
|
||
| /* | ||
| System.out.println("========= Merged"); |
| combiner.merge(stats1, stats2); | ||
|
|
||
| /* | ||
| System.out.println("========= Merged"); |
| * 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. | ||
| */ |
There was a problem hiding this comment.
should add @since 2.0.0 javadoc tag.
keith-turner
left a comment
There was a problem hiding this comment.
@jkrdev thanks for the contribution! Let me know if you would like to be added to the people page as a contributor. I can add you if you give me the info or you can submit a PR to the accumulo-website repo.
|
I would like to be added to the people page the info I want is just my name Jared R. Thanks. |
|
I added Jared R. to people page. |
Built in Summarizer that computes summary information about field lengths. Specifically key length, row length, family length, qualifier length, visibility length, and value length. Incrementally computes min, max, count, sum, and log2 histogram.