Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 944361092E for ; Sun, 16 Mar 2014 07:44:50 +0000 (UTC) Received: (qmail 66469 invoked by uid 500); 16 Mar 2014 07:44:47 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 66071 invoked by uid 500); 16 Mar 2014 07:44:44 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 66051 invoked by uid 99); 16 Mar 2014 07:44:43 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 16 Mar 2014 07:44:43 +0000 Date: Sun, 16 Mar 2014 07:44:43 +0000 (UTC) From: "Edward Capriolo (JIRA)" To: commits@cassandra.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (CASSANDRA-6870) Transform operation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CASSANDRA-6870?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13937029#comment-13937029 ] Edward Capriolo edited comment on CASSANDRA-6870 at 3/16/14 7:44 AM: --------------------------------------------------------------------- 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: {code} struct TransformRequest { 1: optional binary key, 2: optional string column_family, 3: optional string function_name, 4: optional map 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 } {code} Given an interface like this: {code} public interface Transformer { public ColumnFamily transform(ColumnFamily source, Map properties, CFMetaData cfm); } {code} We can perform an increment. {code} public class Increment implements Transformer { @Override public ColumnFamily transform(ColumnFamily source, Map 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. was (Author: appodictic): 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 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 properties, CFMetaData cfm); } {code} We can perform an increment. {code} public class Increment implements Transformer { @Override public ColumnFamily transform(ColumnFamily source, Map 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)