accumulo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Keith Turner (JIRA)" <>
Subject [jira] [Commented] (ACCUMULO-4746) Create Builder for Mutation
Date Tue, 28 Nov 2017 20:40:00 GMT


Keith Turner commented on ACCUMULO-4746:

While trying to puzzle through the issues I was running into with ConditionalMutation I thought
about this issue more deeply. I came to the conclusion that a builder is not the right path
for Mutation.  For Key it made more sense because Key had a lot of constructors and no setters.
 However for mutation, it has all of these put methods.  So after creating a mutation with
a builder, its possible to call put methods to further change it. This seems silly to me.

What is nice about the key builder is that it allows easy mixing of different types.  For
example its easy to have a byte array for the row, String for the family, and byte array for
the qualifier.  Currently this is not possible with the mutation put methods.  There are put
methods for all byte arrays or all strings, but not combinations.  

Based on the reasons above, I think having a fluent way to mix types for an existing mutation
instead of a builder is a better path.  If we were designing the API from scratch I think
a builder that creates immutable mutations would be the way to go.  However that is not an
option for the current API.  Below is a proposed Fluent API for mutating that easily supports
mixing types.

class Mutation {
  public interface FamilyStep extends QualifierStep {
    // TODO other types?
    QualifierStep family(CharSequence f);

    QualifierStep family(byte[] f);

    QualifierStep family(ByteBuffer f);

  public interface QualifierStep extends VisibilityStep {
    // TODO other types?
    VisibilityStep qualifier(CharSequence q);

    VisibilityStep qualifier(byte[] q);

    VisibilityStep qualifier(ByteBuffer q);

  public interface VisibilityStep extends TimestampStep {
    // TODO other types?
    TimestampStep visibility(CharSequence cv);

    TimestampStep visibility(byte[] cv);

    TimestampStep visibility(ByteBuffer cv);

    TimestampStep visibility(ColumnVisibility cv);

  public interface TimestampStep extends MutateStep {
    MutateStep timestamp(long t);

  public interface MutateStep {
    // TODO other types?
    void set(byte[] v);

    void set(ByteBuffer v);

    void set(CharSequence v);

    void delete();

  // this could be called put... 
  public FamilyStep mutate() {
    //TODO implement.. could return a private inner class that implements all interfaces...
    return null;

Below is an example of using the new API that shows easily mixing different types

    Mutation m1 = new Mutation("row1");

    byte[] fam = new byte[] {42, 21, 7, 9, 3, 34};
    ByteBuffer bb = null;

    ByteBuffer bb2 = null;
    //below is an example of using the existing put method with different types
    byte[] tmp = new byte[bb2.remaining()];
    // must make all types same, so made all into byte arrays
    m1.put(fam, "q4".getBytes(StandardCharsets.UTF_8), tmp);

> Create Builder for Mutation
> ---------------------------
>                 Key: ACCUMULO-4746
>                 URL:
>             Project: Accumulo
>          Issue Type: Sub-task
>          Components: client
>            Reporter: Keith Turner
>             Fix For: 2.0.0
> Accumulo needs a builder for mutation similar to the one that was added for Key.

This message was sent by Atlassian JIRA

View raw message