Class CountingSummarizer<K>

java.lang.Object
org.apache.accumulo.core.client.summary.CountingSummarizer<K>
Type Parameters:
K - The counter key type. This type must have good implementations of Object.hashCode() and Object.equals(Object).
All Implemented Interfaces:
Summarizer
Direct Known Subclasses:
AuthorizationSummarizer, FamilySummarizer, VisibilitySummarizer

public abstract class CountingSummarizer<K> extends Object implements Summarizer
This class counts arbitrary keys while defending against too many keys and keys that are too long.

During collection and summarization this class will use the functions from converter() and encoder(). For each key/value the function from converter() will be called to create zero or more counter objects. A counter associated with each counter object will be incremented, as long as there are not too many counters and the counter object is not too long.

When Summarizer.Collector.summarize(Summarizer.StatisticConsumer) is called, the function from encoder() will be used to convert counter objects to strings. These strings will be used to emit statistics. Overriding encoder() is optional. One reason to override is if the counter object contains binary or special data. For example, a function that base64 encodes counter objects could be created.

If the counter key type is mutable, then consider overriding copier().

The function returned by converter() will be called frequently and should be very efficient. The function returned by encoder() will be called less frequently and can be more expensive. The reason these two functions exists is to avoid the conversion to string for each key value, if that conversion is unnecessary.

Below is an example implementation that counts column visibilities. This example avoids converting column visibility to string for each key/value. This example shows the source code for VisibilitySummarizer.

 
   public class VisibilitySummarizer extends CountingSummarizer<ByteSequence> {
     @Override
     protected UnaryOperator<ByteSequence> copier() {
       // ByteSequences are mutable, so override and provide a copy function
       return ArrayByteSequence::new;
     }

     @Override
     protected Converter<ByteSequence> converter() {
       return (key, val, consumer) -> consumer.accept(key.getColumnVisibilityData());
     }
   }
 
 
Since:
2.0.0
See Also: