email iconemail phone iconcall

DataStax C/C++ Driver: Beta release available!

By Michael Penick -  June 11, 2014 | 0 Comments

The drivers team is pleased to announce the first beta release of the newly designed C/C++ driver for Apache Cassandra . This version targets Cassandra 2.0 and the CQL Native Protocol version 2, but future releases will bring support for Cassandra 1.2 and 2.1 (CQL Native Protocol versions 1 and 3). This first beta version comes with a complete rewrite of the initial code we've shared on GitHub. We've heard your feedback and also realized the technical limitations of the previous design, so we decided that we should provide an improved architecture, a higher performance implementation (based on libuv) and a cleaner pure C API. Here are some highlights of the features and improvements:

  • Clean and concise C API, allowing for easier integration with a broad set of applications including ANSI C applications and scripting languages
  • Full asynchronous API and internal architecture
  • Minimal dependencies, allowing the driver to support a variety of platforms including Linux, Windows, and Mac OSX.
  • High performance implementation that is scalable on multi-core systems
  • Support for prepared and batch statements
  • Support for CQL collections
  • Robust fail over and reconnection handling
  • Streamlined design that’s careful not to expose internal dependencies or implementation details

You can grab the source code from here. To help you get started using the driver we’ve provided several examples as well as a thoroughly documented header file: include/cassandra.h. To give you a taste of the new C API here are some snippets:

#include <stdio.h>
#include <string.h>
#include <cassandra.h>

int main() 
  /* Configure cluster and connect session */
  const char* contact_points = ",,";
  CassCluster* cluster = cass_cluster_new();
  cass_cluster_setopt(cluster, CASS_OPTION_CONTACT_POINTS,
                      contact_points, strlen(contact_points));

  CassFuture* connect_future = cass_cluster_connect(cluster);
  CassSession* session = cass_future_get_session(connect_future);

  /* Contruct statement and bind values */
  CassString insert_query = cass_string_init(
          "INSERT INTO blog.posts (create_ts, title, content) VALUES (?, ?, ?)");
  CassStatement* statement = cass_statement_new(insert_query, 3,

  CassUuid create_ts;
  cass_statement_bind_uuid(statement, 0, create_ts);

  CassString title
      = cass_string_init("DataStax C/C++ Driver: Beta release available!");
  cass_statement_bind_string(statement, 1, title );

  CassString content
      = cass_string_init(
          "The drivers team is pleased to announce the first beta release...");
  cass_statement_bind_string(statement, 2, content);

  /* Execute the statement and check result */
  CassFuture* future = cass_session_execute(session, statement);

  if(cass_future_error_code(future) == CASS_OK) {
    puts("Blog posted!");
  } else {
    CassString message = cass_future_error_message(future);
    CassError code = cass_future_error_code(future);
            "Error posting to blog: '%.*s' (0x%08X)\n",
            (int)message.length,, code);

  /* Cleanup and close session */

  CassFuture* close_future = cass_session_close(session);


  return 0;
  /* Same setup as in the insert */

  /* Contruct statement and execute query */
  CassString select_query = cass_string_init("SELECT * FROM blog.posts");
  CassStatement* statement = cass_statement_new(select_query, 0, CASS_CONSISTENCY_ONE);

  CassFuture* future = cass_session_execute(session, statement);
  if(cass_future_error_code(future) == CASS_OK) {
    /* Construct a new iterator from the result */
    const CassResult* result = cass_future_get_result(future);
    CassIterator* iterator = cass_iterator_from_result(result);

    if(cass_iterator_next(iterator)) {
      const CassRow* row = cass_iterator_get_row(iterator);

      /* Get and decode values from row */
      CassUuid create_ts;
      CassString title;
      CassString content;
      cass_value_get_uuid(cass_row_get_column(row, 0), create_ts);
      cass_value_get_string(cass_row_get_column(row, 1), &amp;content);
      cass_value_get_string(cass_row_get_column(row, 2), &amp;title);

      char create_ts_string[CASS_UUID_STRING_LENGTH];
      cass_uuid_string(create_ts, create_ts_string);
      printf("Post: create_ts %s, title '%.*s', content '%.*s'\n",

  } else {
    CassString message = cass_future_error_message(future);
    CassError code = cass_future_error_code(future);
    fprintf(stderr, "Error getting blog posts: '%.*s' (0x%08X)\n", (int)message.length,, code);

  /* Same cleanup as in the insert */
    = { 'class' : 'SimpleStrategy',
        'replication_factor' : 3 };

CREATE TABLE blog.posts (create_ts timeuuid,
                         title text,
                         content text,
                         PRIMARY KEY(create_ts));

This release is just the beginning. In upcoming releases, we plan to rapidly support the same feature set as our other drivers. This includes supporting policies, SSL, compression and authentication. You can take a look at what we have planned on JIRA. As with our other drivers, we have spent significant effort testing this release. We have ensured good coverage by porting a number of tests from the previous C++ driver as well as other drivers. Here are some additional resources help you get started:

We look forward to you using the driver and hearing your feedback.

DataStax has many ways for you to advance in your career and knowledge.

You can take free classes, get certified, or read one of our many white papers.

register for classes

get certified

DBA's Guide to NoSQL


Your email address will not be published. Required fields are marked *

Subscribe for newsletter: