1

i would like to know how to use CQL to insert a new column to a row...

Is it possible? If not, how can i do that easily by using Fluent Cassandra?

Thanks.

user7337271
  • 1,662
  • 1
  • 14
  • 23
Lucas
  • 91
  • 1
  • 8

3 Answers3

0

CQL expects you to define your schema up front. If you want dynamic schema, you must use one of the Thrift-based clients. Fluent Cassandra supports this; check here.

rs_atl
  • 8,935
  • 1
  • 23
  • 28
  • when you say schema up front do you say that before i do a insert that have a new column i have to execute a CQL like: ALTER TABLE messages ADD ColunaTeste varchar; ? Is that correct? Well, i did it here and worked, is here some problem in do this? Thanks! – Lucas Jan 31 '13 at 21:56
  • Yes you have do the alter prior to the insert. CQL requires the schema, as it's a facade on top of the underlying storage rows. Cassandra itself doesn't care, but the CQL engine does. – rs_atl Jan 31 '13 at 21:58
0

Using FluentCassandra, you can add a new column to an existing row quite easily:

var cFamily = db.GetColumnFamily("TestCF");
cFamily.InsertColumn(rowKey, columnName, columnValue);

Alternatively, you can do it like this:

var cFamily = db.GetColumnFamily("TestCF");
var record = cFamily.CreateRecord(existingRowKey) //record already exists
record[newColumnName] = newColumnValue;
beterthanlife
  • 1,668
  • 2
  • 18
  • 30
  • Its worth noting that, after taking some rudimentary timings, it appears that the latter solution (CreateRecord) is around 3 times faster than using InsertColumn. – beterthanlife Feb 08 '13 at 14:17
0

Using FluentCassandra:

dbcontext.ExecuteNonQuery("update TargetColumnFamily set 'ColumnName'='ColumnValue' 
   where keyname='RowKeyValue'")

In my testing, I've found this will create the row if it doesn't exist. Not sure how to tweak this for non-text.

user6775030
  • 81
  • 1
  • 4