cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Edward Capriolo (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CASSANDRA-6870) Transform operation
Date Sun, 16 Mar 2014 07:44:42 GMT

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

Edward Capriolo commented on CASSANDRA-6870:
--------------------------------------------

https://github.com/edwardcapriolo/cassandra/compare/arizona?expand=1

CQLwise this function could look something like this:

{quote}
update table set col1=increment(col1) where rowkey = 5;
{quote}

Thrift world it looks like this:
{quote}
struct TransformRequest {
    1: optional binary key,
    2: optional string column_family,
    3: optional string function_name,
    4: optional map<binary,binary> function_properties
    5: optional cassandra.ConsistencyLevel serial_consistency_level=cassandra.ConsistencyLevel.SERIAL,
    6: optional cassandra.ConsistencyLevel commit_consistency_level=cassandra.ConsistencyLevel.QUORUM,
    7: optional cassandra.SlicePredicate predicate
}
{quote}


Given an interface like this:
{code}
public interface Transformer {
  public ColumnFamily transform(ColumnFamily source, Map<String,String> properties,
CFMetaData cfm);
}
{code}

We can perform an increment.
{code}
public class Increment implements Transformer {
  @Override
  public ColumnFamily transform(ColumnFamily source, Map<String, String> properties,
CFMetaData cfm) {
    ColumnFamily updates = ArrayBackedSortedColumns.factory.create(cfm);
    if (source == null){
      return updates;
    }
    for (Cell cell : source.getSortedColumns()) {
      CellName cn = CellNames.simpleDense(cell.name().get(0));
      int newValue = 0;
      try {
        newValue = Integer.parseInt(ByteBufferUtil.string(cell.value())) +1;
      } catch (NumberFormatException | CharacterCodingException e) {
        e.printStackTrace();
        return updates;
      }
      updates.addColumn(cn, ByteBufferUtil.bytes(newValue+""), FBUtilities.timestampMicros());
    }
    return updates;
  }
}
{code}

I have this working in my branch. By working I mean compiling and test passing. (I am fuzzy
on paxos so I am not sure if this is implemented correctly). This concept is powerful, increment,
append, operations on collections could be possible. 

> Transform operation
> -------------------
>
>                 Key: CASSANDRA-6870
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-6870
>             Project: Cassandra
>          Issue Type: New Feature
>            Reporter: Edward Capriolo
>            Assignee: Edward Capriolo
>            Priority: Minor
>
> Compare and swap uses paxos to only update a value only if some criteria is met. If I
understand correctly we should be able to use this feature to provide a wider variety of server
side operations. 
> For example inside a paxos transaction performing a slice and then using a function to
manipulate the slice. You could accomplish features like append and increment this way. 
> I took a stab at doing this. I **think** I did it correctly. Comments welcome.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message