cassandra-commits mailing list archives

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


Edward Capriolo commented on CASSANDRA-6870:

CQLwise this function could look something like this:

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

Thrift world it looks like this:
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

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

We can perform an increment.
public class Increment implements Transformer {
  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(;
      int newValue = 0;
      try {
        newValue = Integer.parseInt(ByteBufferUtil.string(cell.value())) +1;
      } catch (NumberFormatException | CharacterCodingException e) {
        return updates;
      updates.addColumn(cn, ByteBufferUtil.bytes(newValue+""), FBUtilities.timestampMicros());
    return updates;

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:
>             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

View raw message