Writing to Cassandra Database using Pelops Client

63 views
Skip to first unread message

Raihan Jamal

unread,
Apr 6, 2013, 8:06:55 PM4/6/13
to sca...@googlegroups.com
I recently started working with Cassandra database. I was able to setup single node cluster in my local machine.

And now I was thinking to start writing some sample data to Cassandra Database using `Pelops client`. 

Below is the keyspace and column family I have created so far-


 
create keyspace my_keyspace with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and strategy_options = {replication_factor:1};
use my_keyspace;
create column family users with column_type = 'Standard' and comparator = 'UTF8Type';


Below is the code that I have so far-



public class MyPelops {
private static final Logger log = Logger.getLogger(MyPelops.class);

public static void main(String[] args) throws Exception {

// A comma separated List of Nodes
String NODES = "localhost";
// Thrift Connection Pool
String THRIFT_CONNECTION_POOL = "Test Cluster";
// Keyspace
String KEYSPACE = "my_keyspace";
// Column Family
String COLUMN_FAMILY = "users";
Cluster cluster = new Cluster(NODES, 9160);
Pelops.addPool(THRIFT_CONNECTION_POOL, cluster, KEYSPACE);
Mutator mutator = Pelops.createMutator(THRIFT_CONNECTION_POOL);
log.info("- Write Column -");
mutator.writeColumn(
COLUMN_FAMILY,
"Row1",
new Column().setName(" Name ".getBytes()).setValue(
" Test One ".getBytes()));
mutator.writeColumn(
COLUMN_FAMILY,
"Row1",
new Column().setName(" Work ".getBytes()).setValue(
" Engineer ".getBytes()));
log.info("- Execute -");
mutator.execute(ConsistencyLevel.ONE);
Selector selector = Pelops.createSelector(THRIFT_CONNECTION_POOL);
int columnCount = selector.getColumnCount(COLUMN_FAMILY, "Row1",
ConsistencyLevel.ONE);
log.info("- Column Count = " + columnCount);
List<Column> columnList = selector
.getColumnsFromRow(COLUMN_FAMILY, "Row1",
Selector.newColumnsPredicateAll(true, 10),
ConsistencyLevel.ONE);
log.info("- Size of Column List = " + columnList.size());
for (Column column : columnList) {
log.info("- Column: (" + new String(column.getName()) + ","
+ new String(column.getValue()) + ")");
}
log.info("- All Done. Exit -");
System.exit(0);
}
}

   


Whenever I am running this program, I am getting this exception always-

   Exception in thread "main" org.scale7.cassandra.pelops.exceptions.InvalidRequestException: Column timestamp is required

And this exception is coming as soon as it tries to execute this line-

`mutator.execute` line

As I mentioned above, I am new to Cassandra Database and Pelops client as well. This is my first time working with that. Can anyone help me with this problem with step by step process? I am running Cassandra 1.2.3 in my local box.


Any step by step guidance like how to insert data in Cassandra database will help me a lot in understanding how Cassandra works.

And also can anyone explain me in simple layman language- 

What is the full process behind the scenes that happened whenever we are writing to `Cassandra Database`.?


Thanks in advance.





Dan Washusen

unread,
Apr 7, 2013, 2:29:49 AM4/7/13
to sca...@googlegroups.com
When writing columns I suggest you use mutator.newColumn("name", "Dan") to create the column (see example on pelops github page). Alternatively when constructing the column set it's time stamp property...







--
You received this message because you are subscribed to the Google Groups "Scale 7 - Libraries and systems for scalable computing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scale7+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Dan Washusen
Make big files fly!
Reply all
Reply to author
Forward
0 new messages