JasperSoft Library with Cassandra

I've created a very simple example report that uses a Cassandra Data Adapter (com.jaspersoft.connectors.cassandra.adapter.CassandraDataAdapterImpl) and a simple dataset and query and use these to populate a crosstab. This works well using TIBCO JasperSoft Studio and the report previews with the data all there.

I then created a very simple Java application using JasperSoft Library:

JasperPrint jp = JasperFillManager.fillReport("PATH TO COMPILED REPORT TEMPLATE EXPORTED FROM STUDIO", params);
File reportfile = new File("./" + UUID.randomUUID().toString() + ".report.html");
JasperExportManager.exportReportToHtmlFile(jp, reportfile.getAbsolutePath());
String report = Files.toString(reportfile, Charset.defaultCharset());

but when I run this (as a Java application) I get:

No query executer factory registered for the "CQL" language.

Setting the data source to empty:

JasperPrint jp = JasperFillManager.fillReport("PATH TO COMPILED REPORT TEMPLATE EXPORTED FROM STUDIO", params, new JREmptyDataSource());

works, but of course the report is empty. I've tried taking the Cassandra plugin library from Studio (com.jaspersoft.studio.data.cassandra_6.3.1.final.jar) and adding to the classpath but that didn't help. I'm going to try pulling out the lib jars in there and add these directly too and see if I can create a CassandraDataSource.

In the mean time does anyone have any ideas on where I'm going wrong and what I might need to do to fix this?

peter.cliff's picture
Joined: Oct 28 2016 - 8:08am
Last seen: 5 years 7 months ago

OK, so adding the jars in the plugin above:

cassandra-driver-core-2.1.3.jar
js-cassandracql3-datasource-2.3.jar
metrics-core-3.0.2.jar
netty-3.9.0.Final.jar
jasperreports_extension.properties

to the classpath changes the error to:

There is no underlying connection. Please check your datasource
Sounds like progress. Just need to work out how to sensibly create a CassandraDataSource perhaps?
peter.cliff - 5 years 7 months ago

1 Answer:

OK, so I think I've figured it partially out...

Not very tidy but as this is a proof-of-concept I'll worry about tidy later...

I unpacked the various jars as above, but in the end removed "cassandra-driver-core-2.1.3.jar" from the classpath and added it as a Maven dependency instead:

<dependency>
    <groupId>com.datastax.cassandra</groupId>
    <artifactId>cassandra-driver-core</artifactId>
    <version>2.1.3</version>
</dependency>

The jar doesn't come with all the dependencies needed - I was getting a ClassNotFound for log4j. Thinking I might try v3 of the driver next...

Then I create my own connection to Cassandra, manually execute the query and then pass the ResultSet to the CassandraDataSource. Finally pass that in to the report and I get data.

Cluster cluster = Cluster.builder().addContactPoint("localhost").build();
Session session = cluster.connect("my_lovely_keyspace");
ResultSet rs = session.execute("SELECT * FROM table");
 
CassandraDataSource ds = new CassandraDataSource(rs);
 
JasperPrint jp = JasperFillManager.fillReport(PATH_TO_COMPILED_REPORT, params, ds);
 
File reportfile = new File("./" + UUID.randomUUID().toString() + ".report.html");
JasperExportManager.exportReportToHtmlFile(jp, reportfile.getAbsolutePath());
String report = Files.toString(reportfile, Charset.defaultCharset());.

Of course this only helps because I know the CQL for the report so suggestions for a better way welcome.

peter.cliff's picture
Joined: Oct 28 2016 - 8:08am
Last seen: 5 years 7 months ago
Feedback
randomness