DEV Community

Cover image for How to build your own Cassandra workbench

Posted on • Updated on

How to build your own Cassandra workbench

This blog refers to building a simple and easy Cassandra workbench using well known and mostly used technology stack.

"too lazy to do it"

Above quotation saved lots of my time, increased my productivity and switched me to create this workbench.

before going to the key point.

let's understand what is actually Cassandra is ?

Apache Cassandra is an open source, distributed NoSQL database that began internally at Facebook and was released as an open-source project in July 2008. Cassandra delivers continuous availability (zero downtime), high performance, and linear scalability that modern applications require, while also offering operational simplicity and effortless replication across data centers and geographies. Cassandra can handle petabytes of information and thousands of concurrent operations per second, enabling organizations to manage large amounts of data across hybrid cloud and multi cloud environments.

Large companies like Google, Microsoft, Github, Instagram, Uber, Datastax other thousands of companies are using on their own basis.

Now, Coming to the key point

i as a developer using Cassandra, most of times use to logging into the terminal and executes the query. it's always kills my productivity because i have to login into terminal for executing even a simple select queries also.

Most of non-database people like me will only use database for verifying the data. i.e executes select queries only.

Then, i have decided to have my own a simple workbench where i can configure the multiple node sessions and verify the required node data.

Finally after having thoughts as a back-end developer i have chosen Datastax for their pre-built dependencies and other technology stacks like

  • Java8
  • Spring boot
  • Datastax Cassandra dependencies
  • Html5
  • Css
  • Javascript
  • Thymeleaf
  • Cassandra CQL (for verifying data)
  • Maven build tool

Now, What i have done for building a simple workbench is very simple.

Datastax is providing a dependencies where we create maintain Cassandra session and execute queries.

We can configure session and execute CQL queries as below.

Cluster cluster = Cluster.builder().addContactPoint(ipAddress)
                  .withCredentials(userName, password)

Session session = cluster.connect(keyspace); //keyspace is optional
Enter fullscreen mode Exit fullscreen mode
String query = "select * from keyspace.tableName";
Enter fullscreen mode Exit fullscreen mode

we really get a question like how we can handle the exceptions ?

we no need of worrying about exceptions because the Datastax dependencies are already taking care internally and returning proper exception messages as below.

[Invalid query] message="unconfigured table test1"

As i am using spring boot, i have defined a singleton beans then i can use session any where in the application.

here, to execute the queries we required a query that to be passed dynamically. so i have created a REST API using spring boot. it accepts query as string and returns list of rows.

public List<Object> getDataUsingQuery(@RequestParam("query") String query) {
    List<Object> dataByQuery = cassandraService.getDataByQuery(query.trim());
    return dataByQuery;
Enter fullscreen mode Exit fullscreen mode

right now, i restricted my workbench for executing only select queries. we can enhance it further.

Finally, we should have a proper UI for executing query and displaying the results.

To make it as simple as possible, i am not attaching any images here. please do refer my GitHub URL for source code and sample UI.


Thank you for reading my first blog, please keep in touch for my next one. :-)

Top comments (0)