cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dop Sun" <>
Subject RE: Cassandra Java Client
Date Mon, 19 Apr 2010 20:26:55 GMT
Hi Ran:


Yep, looks like there is possibility that I can add dependencies to hector, and enhance the
functionality to Jassandra.


I would take this chance to extend the discussion about “xxx Client for Cassandra” a little


In short, Cassandra may need a kind of sub-project to define the “xxx-client for Cassandra”
for most of the popular platforms (like Python, Java, .NET), or, it defines a framework (standard,
guideline, or whatever), and let the community to port/ implement in different language/ platform.


I believe Cassandra product itself needs the flexibility to change Thrift API at any given
time, including deprecating the old API, which may have bad performance, or adding new API
to cover new functionality, but the production deployed applications build on Cassandra in
general (in general, means not the company like FaceBook, Digg, who has huge team to follow
the changes of Cassandra) cannot bear this. And if these products depend on the Thrift API,
which means eventually, these deployment will be left behind with old version.


This problem happens in RDBMS world, and eventually, it’s resolved with xDBC APIs. The new
database coming out, it provides the general features + special features. So, the applications
built on database technologies, in most of the cases, can move smoothly to the latest database
server versions.


With another layer of abstraction, the performance of the application does not necessarily
to be slower, since the newly introduced API developer, can try to use the latest version
of the Thrift API to provide the best performance for the requests of the application. An
immediate example would be: in the Thrift API, the querying API (get_xxx, mult_get, and get_key_slice)
has been enhanced a lot. For the application, before “xxx-client for Cassandra” updated,
it can work with new version of Cassandra with using the old API. And once the “xxx-client”
updated, it will immediately using the new features even without change the application codes.


The reason I believe this “xxx-client for Cassandra” best to be a sub-project, because
since the API of Cassandra is changing, at this stage, the design of such an API need lot
of inside details/ guide. It’s very difficult for people from outside, like me, to define
some API based on guessing, which may eventually can be flexible enough to support feature
Cassandra. I can see several “xxx client for Cassandra” project eventually abandoned,
and my guess is because of this. Maybe one day, Jassandra also cannot be further extended
to meet the new API of future version of Cassandra, and I may abandon it as well. J





From: Ran Tavory [] 
Sent: Tuesday, April 20, 2010 1:36 AM
Subject: Re: Cassandra Java Client


Hi Dop, you may want to look at hector as a low level cassandra client on which you build
jassandra, adding hibernate style magic etc like other ppl have done with ORM layers on top
of it.

Hector's main features include extensive jmx counters, failover and connection pooling. 

It's available for all recent versions, including 0.5.0, 0.5.1, 0.6.0 and 0.6.1

On Mon, Apr 19, 2010 at 5:58 PM, Dop Sun <> wrote:

Well, there are couple of points while Jassandra is created:

1. First of all, I want to create something like that is because I come from
JDBC background, and familiar with Hibernate API. The ICriteria (which is
created for querying) is inspired by the Criteria API from hibernate.

Actually, maybe because of this background, it cost me a lot efforts try to
understand Cassandra in the beginning and Thrift API also takes time to use.

2. The Jassandra creates a layer, which removes the direct link to
underlying Thrift API (including the exceptions, ConsistencyLevel
enumeration etc)

High light this point because I believe the client of the Jassandra will
benefit for the implementation changes in future, for example, if the
Cassandra provides better Thrift API to selecting the columns for a list of
keys, SCFs, or deprecating some structures, exceptions, the client may not
be changed. Of cause, if Jassandra failed to approve itself, this is
actually not the advantage. :)

3. The Jassandra is designed to be an JDBC like API, no less, no more. It
strives to use the best API to do the quering (with token, key, SCF/ CF),
doing the CRUD, but no more than that. For example, it does not cover any
API like object mapping. But it should cover all the API functionalities
Thrift provided.

These 3 points, are different from Hector (I should be honest that I have
not tried to use it before, the feeling of difference are coming from the
sample code Hector provided).

So, the API Jassandra abstracted was something like this:

   IConnection connection = DriverManager.getConnection(
       "thrift://localhost:9160", info);
   try {
     // 2. Get a KeySpace by name
     IKeySpace keySpace = connection.getKeySpace("Keyspace1");

     // 3. Get a ColumnFamily by name
     IColumnFamily cf = keySpace.getColumnFamily("Standard2");

     // 4. Insert like this
     long now = System.currentTimeMillis();
     ByteArray nameFirst = ByteArray.ofASCII("first");
     ByteArray nameLast = ByteArray.ofASCII("last");
     ByteArray nameAge = ByteArray.ofASCII("age");
     ByteArray valueLast = ByteArray.ofUTF8("Smith");
     IColumn colFirst = new Column(nameFirst, ByteArray.ofUTF8("John"),
     cf.insert(userName, colFirst);

     IColumn colLast = new Column(nameLast, valueLast, now);
     cf.insert(userName, colLast);

     IColumn colAge = new Column(nameAge, ByteArray.ofLong(42), now);
     cf.insert(userName, colAge);

     // 5. Select like this
     ICriteria criteria = cf.createCriteria();
         .columnRange(nameAge, nameLast, 10);
     Map<String, List<IColumn>> map =;
     List<IColumn> list = map.get(userName);
     Assert.assertEquals(3, list.size());
     Assert.assertEquals(valueLast, list.get(2).getValue());

     // 6. Delete like this
     cf.delete(userName, colFirst);
     map =;
     Assert.assertEquals(2, map.get(userName).size());

     // 7. Get count like this
     criteria = cf.createCriteria();
     int count = criteria.count();
     Assert.assertEquals(2, count);
   } finally {
     // 8. Don't forget to close the connection.


-----Original Message-----
From: Jonathan Ellis []
Sent: Monday, April 19, 2010 10:35 PM

Subject: Re: Cassandra Java Client

How is Jassandra different from ?

On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <> wrote:
> May I take this chance to share this link here:
> It currently based with Cassandra 0.6 Thrift APIs.
> The class ThriftCriteria and ThriftColumnFamily has direct use of Thrift
> API. Also, the site itself has test code, which is actually works on
> Jassandra abstraction.
> Dop
> From: Nirmala Agadgar []
> Sent: Friday, April 16, 2010 5:56 PM
> To:
> Subject: Cassandra Java Client
> Hi,
> Can anyone tell how to implement Client that can insert data into
> in Java. Any Code or guidelines would be helpful.
> -
> Nirmala


View raw message