You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Nirmala Agadgar <ni...@gmail.com> on 2010/04/16 11:56:15 UTC

Cassandra Java Client

Hi,

Can anyone tell how to implement Client that can insert data into cassandra
in Java. Any Code or guidelines would be helpful.

-
Nirmala

RE: Cassandra Java Client

Posted by Dop Sun <su...@dopsun.com>.
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 bit:

 

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

 

Cheers~~~

Dop 

 

From: Ran Tavory [mailto:rantav@gmail.com] 
Sent: Tuesday, April 20, 2010 1:36 AM
To: user@cassandra.apache.org
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 <su...@dopsun.com> 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"),
now);
     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();
     criteria.keyList(Lists.newArrayList(userName))
         .columnRange(nameAge, nameLast, 10);
     Map<String, List<IColumn>> map = criteria.select();
     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 = criteria.select();
     Assert.assertEquals(2, map.get(userName).size());

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

   }
 }

-----Original Message-----
From: Jonathan Ellis [mailto:jbellis@gmail.com]
Sent: Monday, April 19, 2010 10:35 PM
To: user@cassandra.apache.org

Subject: Re: Cassandra Java Client

How is Jassandra different from http://github.com/rantav/hector ?

On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <su...@dopsun.com> wrote:
> May I take this chance to share this link here:
>
> http://code.google.com/p/jassandra/
>
>
>
> 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 [mailto:nirmala.ab@gmail.com]
> Sent: Friday, April 16, 2010 5:56 PM
> To: user@cassandra.apache.org
> Subject: Cassandra Java Client
>
>
>
> Hi,
>
> Can anyone tell how to implement Client that can insert data into
cassandra
> in Java. Any Code or guidelines would be helpful.
>
> -
> Nirmala
>



 


Re: Cassandra Java Client

Posted by Schubert Zhang <zs...@gmail.com>.
Thanks!
I want have a detailed study of Hector.

On Thu, Apr 29, 2010 at 1:39 PM, Ran Tavory <ra...@gmail.com> wrote:

> Hi Schubert, I'm sorry Hector isn't a good fit for you, so let's see what's
> missing for your.
>
> On Thu, Apr 29, 2010 at 8:22 AM, Schubert Zhang <zs...@gmail.com> wrote:
>
>> I found hector is not a good design.
>>
>> 1. We cannot create multiple threads (each thread have a connection to
>> cassandra server) to one cassandra server.
>>     As we known, usually, cassandra client should be multiple-threads to
>> achieve good throughput.
>>
> I usually use hector with many threads, so I'm not sure I understand your
> point. Threads and connections are two different things; in hector to obtain
> a connection you call borrowClient and then you release the connection by
> releaseClient. You may choose to have one connection per thread (I think
> it's the simplest way), or many connections per thread. You may also choose
> to have many threads using the same connection, but this I think is
> less desirable and less scalable. To keep it simple, a good rule of thumb is
> connection-per-thread.
> Let me know if you have specific design questions and feel free to email
> (and join) hector-users@googlegroups.com
>

A use case as: We want one connection per thread. But a cassandra node can
provide multiple connections to one client node.


>> 2. The implementation is too fat.
>>
> Feel free to send your diet, improvements and suggestions to
> hector-dev@googlegroups.com or hector-users@googlegroups.com
>
>>
>> 3. Introduce traditional RDBMS habit into Cassandra is not a good idea.
>
> Which RDBMS habit did you mean?
>

I mean the DAO.


>
>>
>>
>> On Wed, Apr 21, 2010 at 1:25 AM, Ran Tavory <ra...@gmail.com> wrote:
>>
>>> great, I'm happy you found hector useful and reused it in your client.
>>>
>>>
>>> On Tue, Apr 20, 2010 at 5:11 PM, Dop Sun <su...@dopsun.com> wrote:
>>>
>>>>  Hi,
>>>>
>>>>
>>>>
>>>> I have downloaded hector-0.6.0-10.jar. As you mentioned, it has good
>>>> implementation for the connection pooling, JMX counters.
>>>>
>>>>
>>>>
>>>> What I’m doing is: using Hector to create the Cassandra client (be
>>>> specific: borrow_client(url, port)). And my understanding is: in this way,
>>>> the Jassandra will enjoy the client pool and JMX counter.
>>>>
>>>>
>>>>
>>>> http://code.google.com/p/jassandra/issues/detail?id=17
>>>>
>>>>
>>>>
>>>> Please feel free to let me know if you have any suggestions.
>>>>
>>>>
>>>>
>>>> The new build 1.0.0 build 3(http://code.google.com/p/jassandra/)
>>>> created. From Jassandra client side, no API changes.
>>>>
>>>>
>>>>
>>>> Cheers~~~
>>>>
>>>> Dop
>>>>
>>>>
>>>>
>>>> *From:* Ran Tavory [mailto:rantav@gmail.com]
>>>> *Sent:* Tuesday, April 20, 2010 1:36 AM
>>>> *To:* user@cassandra.apache.org
>>>> *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 <su...@dopsun.com> 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"),
>>>> now);
>>>>      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();
>>>>      criteria.keyList(Lists.newArrayList(userName))
>>>>          .columnRange(nameAge, nameLast, 10);
>>>>      Map<String, List<IColumn>> map = criteria.select();
>>>>      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 = criteria.select();
>>>>      Assert.assertEquals(2, map.get(userName).size());
>>>>
>>>>      // 7. Get count like this
>>>>      criteria = cf.createCriteria();
>>>>      criteria.keyList(Lists.newArrayList(userName));
>>>>      int count = criteria.count();
>>>>      Assert.assertEquals(2, count);
>>>>    } finally {
>>>>      // 8. Don't forget to close the connection.
>>>>      connection.close();
>>>>
>>>>    }
>>>>  }
>>>>
>>>> -----Original Message-----
>>>> From: Jonathan Ellis [mailto:jbellis@gmail.com]
>>>> Sent: Monday, April 19, 2010 10:35 PM
>>>> To: user@cassandra.apache.org
>>>>
>>>> Subject: Re: Cassandra Java Client
>>>>
>>>> How is Jassandra different from http://github.com/rantav/hector ?
>>>>
>>>> On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <su...@dopsun.com> wrote:
>>>> > May I take this chance to share this link here:
>>>> >
>>>> > http://code.google.com/p/jassandra/
>>>> >
>>>> >
>>>> >
>>>> > 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 [mailto:nirmala.ab@gmail.com]
>>>> > Sent: Friday, April 16, 2010 5:56 PM
>>>> > To: user@cassandra.apache.org
>>>> > Subject: Cassandra Java Client
>>>> >
>>>> >
>>>> >
>>>> > Hi,
>>>> >
>>>> > Can anyone tell how to implement Client that can insert data into
>>>> cassandra
>>>> > in Java. Any Code or guidelines would be helpful.
>>>> >
>>>> > -
>>>> > Nirmala
>>>> >
>>>>
>>>>
>>>>
>>>
>>>
>>
>

Re: Cassandra Java Client

Posted by Ran Tavory <ra...@gmail.com>.
Hi Schubert, I'm sorry Hector isn't a good fit for you, so let's see what's
missing for your.

On Thu, Apr 29, 2010 at 8:22 AM, Schubert Zhang <zs...@gmail.com> wrote:

> I found hector is not a good design.
>
> 1. We cannot create multiple threads (each thread have a connection to
> cassandra server) to one cassandra server.
>     As we known, usually, cassandra client should be multiple-threads to
> achieve good throughput.
>
I usually use hector with many threads, so I'm not sure I understand your
point. Threads and connections are two different things; in hector to obtain
a connection you call borrowClient and then you release the connection by
releaseClient. You may choose to have one connection per thread (I think
it's the simplest way), or many connections per thread. You may also choose
to have many threads using the same connection, but this I think is
less desirable and less scalable. To keep it simple, a good rule of thumb is
connection-per-thread.
Let me know if you have specific design questions and feel free to email
(and join) hector-users@googlegroups.com

>
> 2. The implementation is too fat.
>
Feel free to send your diet, improvements and suggestions to
hector-dev@googlegroups.com or hector-users@googlegroups.com

>
> 3. Introduce traditional RDBMS habit into Cassandra is not a good idea.

Which RDBMS habit did you mean?

>
>
>
> On Wed, Apr 21, 2010 at 1:25 AM, Ran Tavory <ra...@gmail.com> wrote:
>
>> great, I'm happy you found hector useful and reused it in your client.
>>
>>
>> On Tue, Apr 20, 2010 at 5:11 PM, Dop Sun <su...@dopsun.com> wrote:
>>
>>>  Hi,
>>>
>>>
>>>
>>> I have downloaded hector-0.6.0-10.jar. As you mentioned, it has good
>>> implementation for the connection pooling, JMX counters.
>>>
>>>
>>>
>>> What I’m doing is: using Hector to create the Cassandra client (be
>>> specific: borrow_client(url, port)). And my understanding is: in this way,
>>> the Jassandra will enjoy the client pool and JMX counter.
>>>
>>>
>>>
>>> http://code.google.com/p/jassandra/issues/detail?id=17
>>>
>>>
>>>
>>> Please feel free to let me know if you have any suggestions.
>>>
>>>
>>>
>>> The new build 1.0.0 build 3(http://code.google.com/p/jassandra/)
>>> created. From Jassandra client side, no API changes.
>>>
>>>
>>>
>>> Cheers~~~
>>>
>>> Dop
>>>
>>>
>>>
>>> *From:* Ran Tavory [mailto:rantav@gmail.com]
>>> *Sent:* Tuesday, April 20, 2010 1:36 AM
>>> *To:* user@cassandra.apache.org
>>> *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 <su...@dopsun.com> 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"),
>>> now);
>>>      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();
>>>      criteria.keyList(Lists.newArrayList(userName))
>>>          .columnRange(nameAge, nameLast, 10);
>>>      Map<String, List<IColumn>> map = criteria.select();
>>>      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 = criteria.select();
>>>      Assert.assertEquals(2, map.get(userName).size());
>>>
>>>      // 7. Get count like this
>>>      criteria = cf.createCriteria();
>>>      criteria.keyList(Lists.newArrayList(userName));
>>>      int count = criteria.count();
>>>      Assert.assertEquals(2, count);
>>>    } finally {
>>>      // 8. Don't forget to close the connection.
>>>      connection.close();
>>>
>>>    }
>>>  }
>>>
>>> -----Original Message-----
>>> From: Jonathan Ellis [mailto:jbellis@gmail.com]
>>> Sent: Monday, April 19, 2010 10:35 PM
>>> To: user@cassandra.apache.org
>>>
>>> Subject: Re: Cassandra Java Client
>>>
>>> How is Jassandra different from http://github.com/rantav/hector ?
>>>
>>> On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <su...@dopsun.com> wrote:
>>> > May I take this chance to share this link here:
>>> >
>>> > http://code.google.com/p/jassandra/
>>> >
>>> >
>>> >
>>> > 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 [mailto:nirmala.ab@gmail.com]
>>> > Sent: Friday, April 16, 2010 5:56 PM
>>> > To: user@cassandra.apache.org
>>> > Subject: Cassandra Java Client
>>> >
>>> >
>>> >
>>> > Hi,
>>> >
>>> > Can anyone tell how to implement Client that can insert data into
>>> cassandra
>>> > in Java. Any Code or guidelines would be helpful.
>>> >
>>> > -
>>> > Nirmala
>>> >
>>>
>>>
>>>
>>
>>
>

Re: Cassandra Java Client

Posted by Schubert Zhang <zs...@gmail.com>.
I found hector is not a good design.

1. We cannot create multiple threads (each thread have a connection to
cassandra server) to one cassandra server.
    As we known, usually, cassandra client should be multiple-threads to
achieve good throughput.

2. The implementation is too fat.

3. Introduce traditional RDBMS habit into Cassandra is not a good idea.


On Wed, Apr 21, 2010 at 1:25 AM, Ran Tavory <ra...@gmail.com> wrote:

> great, I'm happy you found hector useful and reused it in your client.
>
>
> On Tue, Apr 20, 2010 at 5:11 PM, Dop Sun <su...@dopsun.com> wrote:
>
>>  Hi,
>>
>>
>>
>> I have downloaded hector-0.6.0-10.jar. As you mentioned, it has good
>> implementation for the connection pooling, JMX counters.
>>
>>
>>
>> What I’m doing is: using Hector to create the Cassandra client (be
>> specific: borrow_client(url, port)). And my understanding is: in this way,
>> the Jassandra will enjoy the client pool and JMX counter.
>>
>>
>>
>> http://code.google.com/p/jassandra/issues/detail?id=17
>>
>>
>>
>> Please feel free to let me know if you have any suggestions.
>>
>>
>>
>> The new build 1.0.0 build 3(http://code.google.com/p/jassandra/) created.
>> From Jassandra client side, no API changes.
>>
>>
>>
>> Cheers~~~
>>
>> Dop
>>
>>
>>
>> *From:* Ran Tavory [mailto:rantav@gmail.com]
>> *Sent:* Tuesday, April 20, 2010 1:36 AM
>> *To:* user@cassandra.apache.org
>> *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 <su...@dopsun.com> 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"),
>> now);
>>      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();
>>      criteria.keyList(Lists.newArrayList(userName))
>>          .columnRange(nameAge, nameLast, 10);
>>      Map<String, List<IColumn>> map = criteria.select();
>>      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 = criteria.select();
>>      Assert.assertEquals(2, map.get(userName).size());
>>
>>      // 7. Get count like this
>>      criteria = cf.createCriteria();
>>      criteria.keyList(Lists.newArrayList(userName));
>>      int count = criteria.count();
>>      Assert.assertEquals(2, count);
>>    } finally {
>>      // 8. Don't forget to close the connection.
>>      connection.close();
>>
>>    }
>>  }
>>
>> -----Original Message-----
>> From: Jonathan Ellis [mailto:jbellis@gmail.com]
>> Sent: Monday, April 19, 2010 10:35 PM
>> To: user@cassandra.apache.org
>>
>> Subject: Re: Cassandra Java Client
>>
>> How is Jassandra different from http://github.com/rantav/hector ?
>>
>> On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <su...@dopsun.com> wrote:
>> > May I take this chance to share this link here:
>> >
>> > http://code.google.com/p/jassandra/
>> >
>> >
>> >
>> > 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 [mailto:nirmala.ab@gmail.com]
>> > Sent: Friday, April 16, 2010 5:56 PM
>> > To: user@cassandra.apache.org
>> > Subject: Cassandra Java Client
>> >
>> >
>> >
>> > Hi,
>> >
>> > Can anyone tell how to implement Client that can insert data into
>> cassandra
>> > in Java. Any Code or guidelines would be helpful.
>> >
>> > -
>> > Nirmala
>> >
>>
>>
>>
>
>

Re: Cassandra Java Client

Posted by Ran Tavory <ra...@gmail.com>.
great, I'm happy you found hector useful and reused it in your client.

On Tue, Apr 20, 2010 at 5:11 PM, Dop Sun <su...@dopsun.com> wrote:

>  Hi,
>
>
>
> I have downloaded hector-0.6.0-10.jar. As you mentioned, it has good
> implementation for the connection pooling, JMX counters.
>
>
>
> What I’m doing is: using Hector to create the Cassandra client (be
> specific: borrow_client(url, port)). And my understanding is: in this way,
> the Jassandra will enjoy the client pool and JMX counter.
>
>
>
> http://code.google.com/p/jassandra/issues/detail?id=17
>
>
>
> Please feel free to let me know if you have any suggestions.
>
>
>
> The new build 1.0.0 build 3(http://code.google.com/p/jassandra/) created.
> From Jassandra client side, no API changes.
>
>
>
> Cheers~~~
>
> Dop
>
>
>
> *From:* Ran Tavory [mailto:rantav@gmail.com]
> *Sent:* Tuesday, April 20, 2010 1:36 AM
> *To:* user@cassandra.apache.org
> *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 <su...@dopsun.com> 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"),
> now);
>      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();
>      criteria.keyList(Lists.newArrayList(userName))
>          .columnRange(nameAge, nameLast, 10);
>      Map<String, List<IColumn>> map = criteria.select();
>      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 = criteria.select();
>      Assert.assertEquals(2, map.get(userName).size());
>
>      // 7. Get count like this
>      criteria = cf.createCriteria();
>      criteria.keyList(Lists.newArrayList(userName));
>      int count = criteria.count();
>      Assert.assertEquals(2, count);
>    } finally {
>      // 8. Don't forget to close the connection.
>      connection.close();
>
>    }
>  }
>
> -----Original Message-----
> From: Jonathan Ellis [mailto:jbellis@gmail.com]
> Sent: Monday, April 19, 2010 10:35 PM
> To: user@cassandra.apache.org
>
> Subject: Re: Cassandra Java Client
>
> How is Jassandra different from http://github.com/rantav/hector ?
>
> On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <su...@dopsun.com> wrote:
> > May I take this chance to share this link here:
> >
> > http://code.google.com/p/jassandra/
> >
> >
> >
> > 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 [mailto:nirmala.ab@gmail.com]
> > Sent: Friday, April 16, 2010 5:56 PM
> > To: user@cassandra.apache.org
> > Subject: Cassandra Java Client
> >
> >
> >
> > Hi,
> >
> > Can anyone tell how to implement Client that can insert data into
> cassandra
> > in Java. Any Code or guidelines would be helpful.
> >
> > -
> > Nirmala
> >
>
>
>

Re: Cassandra Java Client

Posted by Nathan McCall <na...@vervewireless.com>.
Dop,
Thank you for trying out hector. I think you have the right approach
for using it with your project. Feel free to ping us directly
regarding Hector on either of these mailings lists as appropriate:
http://wiki.github.com/rantav/hector/mailing-lists

Cheers,
-Nate

On Tue, Apr 20, 2010 at 7:11 AM, Dop Sun <su...@dopsun.com> wrote:
> Hi,
>
>
>
> I have downloaded hector-0.6.0-10.jar. As you mentioned, it has good
> implementation for the connection pooling, JMX counters.
>
>
>
> What I’m doing is: using Hector to create the Cassandra client (be specific:
> borrow_client(url, port)). And my understanding is: in this way, the
> Jassandra will enjoy the client pool and JMX counter.
>
>
>
> http://code.google.com/p/jassandra/issues/detail?id=17
>
>
>
> Please feel free to let me know if you have any suggestions.
>
>
>
> The new build 1.0.0 build 3(http://code.google.com/p/jassandra/) created.
> From Jassandra client side, no API changes.
>
>
>
> Cheers~~~
>
> Dop
>
>
>
> From: Ran Tavory [mailto:rantav@gmail.com]
> Sent: Tuesday, April 20, 2010 1:36 AM
> To: user@cassandra.apache.org
> 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 <su...@dopsun.com> 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"),
> now);
>      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();
>      criteria.keyList(Lists.newArrayList(userName))
>          .columnRange(nameAge, nameLast, 10);
>      Map<String, List<IColumn>> map = criteria.select();
>      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 = criteria.select();
>      Assert.assertEquals(2, map.get(userName).size());
>
>      // 7. Get count like this
>      criteria = cf.createCriteria();
>      criteria.keyList(Lists.newArrayList(userName));
>      int count = criteria.count();
>      Assert.assertEquals(2, count);
>    } finally {
>      // 8. Don't forget to close the connection.
>      connection.close();
>
>    }
>  }
>
> -----Original Message-----
> From: Jonathan Ellis [mailto:jbellis@gmail.com]
> Sent: Monday, April 19, 2010 10:35 PM
> To: user@cassandra.apache.org
>
> Subject: Re: Cassandra Java Client
>
> How is Jassandra different from http://github.com/rantav/hector ?
>
> On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <su...@dopsun.com> wrote:
>> May I take this chance to share this link here:
>>
>> http://code.google.com/p/jassandra/
>>
>>
>>
>> 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 [mailto:nirmala.ab@gmail.com]
>> Sent: Friday, April 16, 2010 5:56 PM
>> To: user@cassandra.apache.org
>> Subject: Cassandra Java Client
>>
>>
>>
>> Hi,
>>
>> Can anyone tell how to implement Client that can insert data into
> cassandra
>> in Java. Any Code or guidelines would be helpful.
>>
>> -
>> Nirmala
>>
>
>

RE: Cassandra Java Client

Posted by Dop Sun <su...@dopsun.com>.
Hi,

 

I have downloaded hector-0.6.0-10.jar. As you mentioned, it has good implementation for the connection pooling, JMX counters.

 

What I’m doing is: using Hector to create the Cassandra client (be specific: borrow_client(url, port)). And my understanding is: in this way, the Jassandra will enjoy the client pool and JMX counter.

 

http://code.google.com/p/jassandra/issues/detail?id=17

 

Please feel free to let me know if you have any suggestions.

 

The new build 1.0.0 build 3(http://code.google.com/p/jassandra/) created. From Jassandra client side, no API changes.

 

Cheers~~~

Dop

 

From: Ran Tavory [mailto:rantav@gmail.com] 
Sent: Tuesday, April 20, 2010 1:36 AM
To: user@cassandra.apache.org
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 <su...@dopsun.com> 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"),
now);
     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();
     criteria.keyList(Lists.newArrayList(userName))
         .columnRange(nameAge, nameLast, 10);
     Map<String, List<IColumn>> map = criteria.select();
     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 = criteria.select();
     Assert.assertEquals(2, map.get(userName).size());

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

   }
 }

-----Original Message-----
From: Jonathan Ellis [mailto:jbellis@gmail.com]
Sent: Monday, April 19, 2010 10:35 PM
To: user@cassandra.apache.org

Subject: Re: Cassandra Java Client

How is Jassandra different from http://github.com/rantav/hector ?

On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <su...@dopsun.com> wrote:
> May I take this chance to share this link here:
>
> http://code.google.com/p/jassandra/
>
>
>
> 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 [mailto:nirmala.ab@gmail.com]
> Sent: Friday, April 16, 2010 5:56 PM
> To: user@cassandra.apache.org
> Subject: Cassandra Java Client
>
>
>
> Hi,
>
> Can anyone tell how to implement Client that can insert data into
cassandra
> in Java. Any Code or guidelines would be helpful.
>
> -
> Nirmala
>



 


Re: Cassandra Java Client

Posted by Ran Tavory <ra...@gmail.com>.
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 <su...@dopsun.com> 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"),
> now);
>      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();
>      criteria.keyList(Lists.newArrayList(userName))
>          .columnRange(nameAge, nameLast, 10);
>      Map<String, List<IColumn>> map = criteria.select();
>      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 = criteria.select();
>      Assert.assertEquals(2, map.get(userName).size());
>
>      // 7. Get count like this
>      criteria = cf.createCriteria();
>      criteria.keyList(Lists.newArrayList(userName));
>      int count = criteria.count();
>      Assert.assertEquals(2, count);
>    } finally {
>      // 8. Don't forget to close the connection.
>      connection.close();
>     }
>  }
>
> -----Original Message-----
> From: Jonathan Ellis [mailto:jbellis@gmail.com]
> Sent: Monday, April 19, 2010 10:35 PM
> To: user@cassandra.apache.org
> Subject: Re: Cassandra Java Client
>
> How is Jassandra different from http://github.com/rantav/hector ?
>
> On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <su...@dopsun.com> wrote:
> > May I take this chance to share this link here:
> >
> > http://code.google.com/p/jassandra/
> >
> >
> >
> > 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 [mailto:nirmala.ab@gmail.com]
> > Sent: Friday, April 16, 2010 5:56 PM
> > To: user@cassandra.apache.org
> > Subject: Cassandra Java Client
> >
> >
> >
> > Hi,
> >
> > Can anyone tell how to implement Client that can insert data into
> cassandra
> > in Java. Any Code or guidelines would be helpful.
> >
> > -
> > Nirmala
> >
>
>
>

RE: Cassandra Java Client

Posted by Dop Sun <su...@dopsun.com>.
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"),
now);
      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();
      criteria.keyList(Lists.newArrayList(userName))
          .columnRange(nameAge, nameLast, 10);
      Map<String, List<IColumn>> map = criteria.select();
      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 = criteria.select();
      Assert.assertEquals(2, map.get(userName).size());

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

-----Original Message-----
From: Jonathan Ellis [mailto:jbellis@gmail.com] 
Sent: Monday, April 19, 2010 10:35 PM
To: user@cassandra.apache.org
Subject: Re: Cassandra Java Client

How is Jassandra different from http://github.com/rantav/hector ?

On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <su...@dopsun.com> wrote:
> May I take this chance to share this link here:
>
> http://code.google.com/p/jassandra/
>
>
>
> 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 [mailto:nirmala.ab@gmail.com]
> Sent: Friday, April 16, 2010 5:56 PM
> To: user@cassandra.apache.org
> Subject: Cassandra Java Client
>
>
>
> Hi,
>
> Can anyone tell how to implement Client that can insert data into
cassandra
> in Java. Any Code or guidelines would be helpful.
>
> -
> Nirmala
>



Re: Cassandra Java Client

Posted by Jonathan Ellis <jb...@gmail.com>.
How is Jassandra different from http://github.com/rantav/hector ?

On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <su...@dopsun.com> wrote:
> May I take this chance to share this link here:
>
> http://code.google.com/p/jassandra/
>
>
>
> 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 [mailto:nirmala.ab@gmail.com]
> Sent: Friday, April 16, 2010 5:56 PM
> To: user@cassandra.apache.org
> Subject: Cassandra Java Client
>
>
>
> Hi,
>
> Can anyone tell how to implement Client that can insert data into cassandra
> in Java. Any Code or guidelines would be helpful.
>
> -
> Nirmala
>

RE: Cassandra Java Client

Posted by Dop Sun <su...@dopsun.com>.
May I take this chance to share this link here:

http://code.google.com/p/jassandra/

 

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 [mailto:nirmala.ab@gmail.com] 
Sent: Friday, April 16, 2010 5:56 PM
To: user@cassandra.apache.org
Subject: Cassandra Java Client

 

Hi,

Can anyone tell how to implement Client that can insert data into cassandra
in Java. Any Code or guidelines would be helpful.

-
Nirmala
 


Re: Cassandra Java Client

Posted by dir dir <si...@gmail.com>.
What is a SpyMemCahced??
What is the correlation between SpyMemCahced and Cassandra??
Thank You.

Dir.

On Sat, Apr 17, 2010 at 3:10 AM, Weijun Li <we...@gmail.com> wrote:

> I'm using spymemcached and it works great! Easy to use, support sharding
> and compression and can handle high volume traffic.
>
> http://code.google.com/p/spymemcached/
>
> -Weijun
>
>
> On Fri, Apr 16, 2010 at 3:29 AM, Linton N <ga...@gmail.com>wrote:
>
>> import java.util.List;
>> import java.io.UnsupportedEncodingException;
>>
>> import org.apache.thrift.transport.TTransport;
>>
>> import org.apache.thrift.transport.TSocket;
>> import org.apache.thrift.protocol.TProtocol;
>> import org.apache.thrift.protocol.TBinaryProtocol;
>> import org.apache.thrift.TException;
>> import org.apache.cassandra.service.*;
>>
>> public class CClient
>> {
>>     public static void main(String[] args)
>>     throws TException, InvalidRequestException, UnavailableException, UnsupportedEncodingException, NotFoundException
>>
>>     {
>>         TTransport tr = new TSocket("localhost", 9160);
>>
>>         TProtocol proto = new TBinaryProtocol(tr);
>>         Cassandra.Client client = new Cassandra.Client(proto);
>>
>>         tr.open();
>>
>>         String key_user_id = "1";
>>
>>         // insert data
>>         long timestamp = System.currentTimeMillis();
>>
>>         client.insert("Keyspace1",
>>                       key_user_id,
>>                       new ColumnPath("Standard1", null, "name".getBytes("UTF-8")),
>>
>>                       "Chris Goffinet".getBytes("UTF-8"),
>>                       timestamp,
>>                       ConsistencyLevel.ONE);
>>         client.insert("Keyspace1",
>>                       key_user_id,
>>                       new ColumnPath("Standard1", null, "age".getBytes("UTF-8")),
>>
>>                       "24".getBytes("UTF-8"),
>>                       timestamp,
>>                       ConsistencyLevel.ONE);
>>
>>         // read single column
>>         ColumnPath path = new ColumnPath("Standard1", null, "name".getBytes("UTF-8"));
>>
>>         System.out.println(client.get("Keyspace1", key_user_id, path, ConsistencyLevel.ONE));
>>
>>
>>         // read entire row
>>         SlicePredicate predicate = new SlicePredicate(null, new SliceRange(new byte[0], new byte[0], false, 10));
>>
>>         ColumnParent parent = new ColumnParent("Standard1", null);
>>
>>         List<ColumnOrSuperColumn> results = client.get_slice("Keyspace1", key_user_id, parent, predicate, ConsistencyLevel.ONE);
>>
>>         for (ColumnOrSuperColumn result : results)
>>         {
>>             Column column = result.column;
>>             System.out.println(new String(column.name, "UTF-8") + " -> " + new String(column.value, "UTF-8"));
>>
>>         }
>>
>>         tr.close();
>>     }
>> }
>>
>>
>>
>>
>>
>> On Fri, Apr 16, 2010 at 3:26 PM, Nirmala Agadgar <ni...@gmail.com>wrote:
>>
>>> Hi,
>>>
>>> Can anyone tell how to implement Client that can insert data into
>>> cassandra in Java. Any Code or guidelines would be helpful.
>>>
>>> -
>>> Nirmala
>>>
>>>
>>
>>
>>
>> --
>> --
>> With Love
>>  Lin N
>>
>
>

Re: Cassandra Java Client

Posted by Weijun Li <we...@gmail.com>.
I'm using spymemcached and it works great! Easy to use, support sharding and
compression and can handle high volume traffic.

http://code.google.com/p/spymemcached/

-Weijun

On Fri, Apr 16, 2010 at 3:29 AM, Linton N <ga...@gmail.com>wrote:

> import java.util.List;
> import java.io.UnsupportedEncodingException;
>
> import org.apache.thrift.transport.TTransport;
> import org.apache.thrift.transport.TSocket;
> import org.apache.thrift.protocol.TProtocol;
> import org.apache.thrift.protocol.TBinaryProtocol;
> import org.apache.thrift.TException;
> import org.apache.cassandra.service.*;
>
> public class CClient
> {
>     public static void main(String[] args)
>     throws TException, InvalidRequestException, UnavailableException, UnsupportedEncodingException, NotFoundException
>     {
>         TTransport tr = new TSocket("localhost", 9160);
>         TProtocol proto = new TBinaryProtocol(tr);
>         Cassandra.Client client = new Cassandra.Client(proto);
>         tr.open();
>
>         String key_user_id = "1";
>
>         // insert data
>         long timestamp = System.currentTimeMillis();
>         client.insert("Keyspace1",
>                       key_user_id,
>                       new ColumnPath("Standard1", null, "name".getBytes("UTF-8")),
>                       "Chris Goffinet".getBytes("UTF-8"),
>                       timestamp,
>                       ConsistencyLevel.ONE);
>         client.insert("Keyspace1",
>                       key_user_id,
>                       new ColumnPath("Standard1", null, "age".getBytes("UTF-8")),
>                       "24".getBytes("UTF-8"),
>                       timestamp,
>                       ConsistencyLevel.ONE);
>
>         // read single column
>         ColumnPath path = new ColumnPath("Standard1", null, "name".getBytes("UTF-8"));
>         System.out.println(client.get("Keyspace1", key_user_id, path, ConsistencyLevel.ONE));
>
>         // read entire row
>         SlicePredicate predicate = new SlicePredicate(null, new SliceRange(new byte[0], new byte[0], false, 10));
>         ColumnParent parent = new ColumnParent("Standard1", null);
>         List<ColumnOrSuperColumn> results = client.get_slice("Keyspace1", key_user_id, parent, predicate, ConsistencyLevel.ONE);
>         for (ColumnOrSuperColumn result : results)
>         {
>             Column column = result.column;
>             System.out.println(new String(column.name, "UTF-8") + " -> " + new String(column.value, "UTF-8"));
>         }
>
>         tr.close();
>     }
> }
>
>
>
>
>
> On Fri, Apr 16, 2010 at 3:26 PM, Nirmala Agadgar <ni...@gmail.com>wrote:
>
>> Hi,
>>
>> Can anyone tell how to implement Client that can insert data into
>> cassandra in Java. Any Code or guidelines would be helpful.
>>
>> -
>> Nirmala
>>
>>
>
>
>
> --
> --
> With Love
>  Lin N
>

Re: Cassandra Java Client

Posted by Linton N <ga...@gmail.com>.
import java.util.List;
import java.io.UnsupportedEncodingException;

import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.TException;
import org.apache.cassandra.service.*;

public class CClient
{
    public static void main(String[] args)
    throws TException, InvalidRequestException, UnavailableException,
UnsupportedEncodingException, NotFoundException
    {
        TTransport tr = new TSocket("localhost", 9160);
        TProtocol proto = new TBinaryProtocol(tr);
        Cassandra.Client client = new Cassandra.Client(proto);
        tr.open();

        String key_user_id = "1";

        // insert data
        long timestamp = System.currentTimeMillis();
        client.insert("Keyspace1",
                      key_user_id,
                      new ColumnPath("Standard1", null,
"name".getBytes("UTF-8")),
                      "Chris Goffinet".getBytes("UTF-8"),
                      timestamp,
                      ConsistencyLevel.ONE);
        client.insert("Keyspace1",
                      key_user_id,
                      new ColumnPath("Standard1", null,
"age".getBytes("UTF-8")),
                      "24".getBytes("UTF-8"),
                      timestamp,
                      ConsistencyLevel.ONE);

        // read single column
        ColumnPath path = new ColumnPath("Standard1", null,
"name".getBytes("UTF-8"));
        System.out.println(client.get("Keyspace1", key_user_id, path,
ConsistencyLevel.ONE));

        // read entire row
        SlicePredicate predicate = new SlicePredicate(null, new
SliceRange(new byte[0], new byte[0], false, 10));
        ColumnParent parent = new ColumnParent("Standard1", null);
        List<ColumnOrSuperColumn> results =
client.get_slice("Keyspace1", key_user_id, parent, predicate,
ConsistencyLevel.ONE);
        for (ColumnOrSuperColumn result : results)
        {
            Column column = result.column;
            System.out.println(new String(column.name, "UTF-8") + " ->
" + new String(column.value, "UTF-8"));
        }

        tr.close();
    }
}





On Fri, Apr 16, 2010 at 3:26 PM, Nirmala Agadgar <ni...@gmail.com>wrote:

> Hi,
>
> Can anyone tell how to implement Client that can insert data into cassandra
> in Java. Any Code or guidelines would be helpful.
>
> -
> Nirmala
>
>



-- 
--
With Love
 Lin N

Re: Cassandra Java Client

Posted by Colin Vipurs <zo...@gmail.com>.
Take a look at Hector, a Java client:

http://wiki.github.com/rantav/hector/

There's example code here:

http://github.com/rantav/hector/blob/master/src/main/java/me/prettyprint/cassandra/service/ExampleClient.java

On Fri, Apr 16, 2010 at 10:56 AM, Nirmala Agadgar <ni...@gmail.com> wrote:
> Hi,
>
> Can anyone tell how to implement Client that can insert data into cassandra
> in Java. Any Code or guidelines would be helpful.
>
> -
> Nirmala
>
>



-- 
Maybe she awoke to see the roommate's boyfriend swinging from the
chandelier wearing a boar's head.

Something which you, I, and everyone else would call "Tuesday", of course.

RE: Cassandra Java Client

Posted by Ake Tangkananond <ia...@gmail.com>.
Hi Nirmala,

 

Welcome to Cassandra! Is this the one you are looking for ?

http://www.sodeso.nl/?p=80

 

 

-Ake

 

From: Nirmala Agadgar [mailto:nirmala.ab@gmail.com] 
Sent: Friday, April 16, 2010 4:56 PM
To: user@cassandra.apache.org
Subject: Cassandra Java Client

 

Hi,

Can anyone tell how to implement Client that can insert data into cassandra
in Java. Any Code or guidelines would be helpful.

-
Nirmala