Generate Cassandra 0.8.1 C# Thrift API

In this example we will generate the Cassandra 0.8.1 Thrift API. To do this we will have to download the Thrift code and compile the the Thrift compiler so that we can generate the Cassandra API code.

What is Thrift

Thrift is a software project spanning a variety of programming languages and use cases. Who’s goal is to make reliable, performant communication and data serialization across languages as efficient and seamless as possible.

Basically it allows you to define an API in a myApp.thrift file, which you can then use to generate API code for different languages.

How to generate Cassandra 0.8.1 API using Thrift

Install Cygwin and remember to add these packages:

  • GNU build tools (autoconf 2.60, automake 1.10, libtool 1.5.24)
  • boost 1.33.1+
  • g++ 4.0+
  • bison 2.3-1
  • boost 1.33.1-4
  • boost-devel 1.33.1-4
  • flex 2.5.33-1
  • pkgconfig
  • libtool

Unpack Thrift to this folder

c:\thrift-0.6.1\

Open Cygwin and browse to the Thrift folder

/cygdrive/c/thrift-0.6.1/

Then type

./configure

Then browse to this folder

/cygdrive/c/thrift-0.6.1/compiler/cpp

Next lets compile the code generator

make

Once this is complete you should have this file

thrift.exe

Next create a directory for the Cassandra thrift API file

/cygdrive/c/thrift-0.6.1/compiler/cpp/casssandra/0.8.1/interface

Now unpack your Cassandra download into a folder

c:\cassandra\0.8.1\

And copy this file

c:\cassandra\0.8.1\interface\casssandra.thrift

Into here

/cygdrive/c/thrift-0.6.1/compiler/cpp/casssandra/0.8.1/interface

Now lets generate the C# API code

./thrift.exe --gen csharp casssandra/0.8.1/interface/casssandra.thrift

Now you should have the generated C# code in this folder

c:\thrift-0.6.1\compiler\cpp\gen-csharp\Apache\Cassandra\

You should have these files

AuthenticationException.cs
AuthenticationRequest.cs
AuthorizationException.cs
Cassandra.cs
CfDef.cs
Column.cs
ColumnDef.cs
ColumnOrSuperColumn.cs
ColumnParent.cs
ColumnPath.cs
Compression.cs
ConsistencyLevel.cs
Constants.cs
CounterColumn.cs
CounterSuperColumn.cs
CqlResult.cs
CqlResultType.cs
CqlRow.cs
Deletion.cs
IndexClause.cs
IndexExpression.cs
IndexOperator.cs
IndexType.cs
InvalidRequestException.cs
KeyCount.cs
KeyRange.cs
KeySlice.cs
KsDef.cs
Mutation.cs
NotFoundException.cs
SchemaDisagreementException.cs
SlicePredicate.cs
SliceRange.cs
SuperColumn.cs
TimedOutException.cs
TokenRange.cs
UnavailableException.cs

Next create a new Visual Studio Class Library project and add the generated code. You will need to compile Thrift, as the Cassandra API depends on it.

You will find the Thrift source code here

c:\thrift-0.6.1\lib\csharp\src

Just open the Thrift Visual Studio solution and compile it

Thrift.sln

If you want to skip all of the above, you can download the Cassandra 0.8.1 API code here

These Thrift Wiki articles may also be useful



Comments

No comments yet.

Add Yours

  • Author Avatar

    YOU


Comment Arrow




About Author

Robert

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning hands down.