accumulo-notifications mailing list archives

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

    [ https://issues.apache.org/jira/browse/ACCUMULO-4746?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16269423#comment-16269423
] 

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.

{code:java}
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;
  }
}
{code}

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

{code:java}
    Mutation m1 = new Mutation("row1");

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

    m1.mutate().family(fam).qualifier("q1").set("v1");
    m1.mutate().family(fam).qualifier("q2").set(bb);
    m1.mutate().family(fam).qualifier("q3").delete();
    
    ByteBuffer bb2 = null;
    
    //below is an example of using the existing put method with different types
    byte[] tmp = new byte[bb2.remaining()];
    bb2.put(tmp);
    // must make all types same, so made all into byte arrays
    m1.put(fam, "q4".getBytes(StandardCharsets.UTF_8), tmp);
{code}

> Create Builder for Mutation
> ---------------------------
>
>                 Key: ACCUMULO-4746
>                 URL: https://issues.apache.org/jira/browse/ACCUMULO-4746
>             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
(v6.4.14#64029)

Mime
View raw message