Cassandra is a distributed NoSql database, similar to Google BigTable or HBase.
It is hybrid between Key-Value and Column oriented database.
There are client drivers for all langages (internal protocol is binary “Thrift”).
There is also a langage CQL very similar to SQL, with an interactive shell to execute commands: CQLSH
Trying to do a select with un-indexed criteria … like “Full Table Scan” in sql:
OK, let be explicitely doing wrong things like sql:
Using secondary indexes:
Update 1 row using complete pk:
Try update rows using partial pk:
Try update rows using non pk criteria:
Preliminary conclusions on Cassandra & CQL : it looks really simple, really like SQL, but with “natural” limitations from a Key-Value database.
Using Java client (10 minutes)
I tryed to use the all-in-one springboot-data-cassandra, but as you can see later , it is in a broken state for Cassandra 3!!
Let’s start with a simple Cassandra driver connection.
Create a maven project, and edit your pom.xml to add
Type “mvn install”, and import in eclipse.
First write java code to connect to Cassandra server:
Then execute a query
It really looks like jdbc API, but simply replace java.sql.ResultSet by com.datastax.driver.core.ResultSet …
Run it … it just works!
Using springboot-data-cassandra with cassandra (~ 2 hours trial solving errors)
Springboot is an amazing project, and springboot-data is also an amazing sub-project for simplifying java code for acessing repositories of data (not only jpa hibernate, but also key-values db, neo4j db, …).
To test a Java client using springboot-data + Cassandra, go to
http://start.spring.io/
check option “Cassandra”, then click on “download” button
Unzip, and type “mvn install”, then in Eclipse “import as maven project”.
the project is only a maven skeleton, it does not contains code.
If you ar einterrested, you can search for “google springdata cassandra sample”, or also read the doc
http://docs.spring.io/autorepo/docs/spring-data-cassandra/current/reference/html/
I have then coded my class with @Table, @PrimaryKey, my primary key class with @PrimaryKeyClass and @PrimaryKeyColumn(..) columns and my interface Repository …
The code with spring-data is very elegant. (Could be even better with lombok for getter/setter removal).
Unfortunatly, the first time I launched the client, I got this error ! … I forgot to change the schema keyspace ?
The “magic” initialisation comes from class org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration.
It uses properties from org.springframework.boot.autoconfigure.cassandra.CassandraProperties
So I have added this line in file application.properties
… and re-executed “mvn install” !! (because eclipse does NOT update resources files from src/main/resources to target/classes)
Unfortunatly, this version does not compile, because cassadra-driver-dse is not released yet on same version 3.1.3, and version 3.0.0-rc1 is not compatible…
I got errors like, for an incompatibility between spring-data-cassandra and cassandra-driver …
I tryed using the latest spring-data-cassandra, directly from github source code
even test do not compile! (so… rm -rf spring-data-cassandra/src/test/java/org)
I have also cloned the springboot-starter github project, and use the SNAPSHOT build..
Notice also that when not putting a default empty constructor on my @Table class, I had a silly confusing error message
Finally, I got some successful results!!
Conclusion: waiting springboot-data to publish an official release that work successfully with Cassandra version 3 !!
Cassandra, springboot & springboot-data are amazing projects.