Skip to content

ACCUMULO-4730 Created EntryLengthSummarizer#320

Closed
jkrdev wants to merge 14 commits intoapache:masterfrom
jkrdev:ACCUMULO-4730
Closed

ACCUMULO-4730 Created EntryLengthSummarizer#320
jkrdev wants to merge 14 commits intoapache:masterfrom
jkrdev:ACCUMULO-4730

Conversation

@jkrdev
Copy link
Copy Markdown
Contributor

@jkrdev jkrdev commented Nov 8, 2017

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.

@ctubbsii ctubbsii changed the title Accumulo-4730 Created EntryLengthSummarizer ACCUMULO-4730 Created EntryLengthSummarizer Nov 8, 2017
Copy link
Copy Markdown
Contributor

@keith-turner keith-turner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I will implement this, definitely will make the code cleaner.


};
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

@jkrdev jkrdev Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {
Copy link
Copy Markdown
Contributor

@keith-turner keith-turner Nov 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

/*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove these comments

combiner.merge(stats1, stats2);

/*
System.out.println("========= Merged");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

combiner.merge(stats1, stats2);

/*
System.out.println("========= Merged");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

* 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.
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add @since 2.0.0 javadoc tag.

Copy link
Copy Markdown
Contributor

@keith-turner keith-turner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@keith-turner
Copy link
Copy Markdown
Contributor

I squashed these commits into 9cd4be0 and pushed that to master. I ran mvn verify -DskipITs and it did some slight reformatting which is included in 9cd4be0

@jkrdev
Copy link
Copy Markdown
Contributor Author

jkrdev commented Nov 15, 2017

I would like to be added to the people page the info I want is just my name Jared R. Thanks.

@keith-turner
Copy link
Copy Markdown
Contributor

I added Jared R. to people page.

@jkrdev jkrdev deleted the ACCUMULO-4730 branch December 1, 2017 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants