8

I am trying to connect R to Cassandra and I am getting the following error - even though I explicitly add this directory folder to the classpath before I run the code (and I also point to the classpath within the statement)? Thanks for any help!

require(RJDBC)

.jaddClassPath("C:\\Users\\atrombley\\Desktop\\R\\")
cassdrv <- JDBC("org.apache.cassandra.cql.jdbc.CassandraDriver",
                "C:\\Users\\atrombley\\Desktop\\R\\cassandra-jdbc-1.2.5.jar")

Error in .jfindClass(as.character(driverClass)[1]) : class not found

A Trombley
  • 79
  • 1
  • 1
  • 2

5 Answers5

5

In my case, the database driver was missing from the location named in my call of JDBC(). Just added the Jar to that location and it works! For example:

JDBC(driverClass="com.vertica.jdbc.Driver", classPath="C:/Program Files/Vertica Systems/JDBC/vertica-jdbc-7.2.1-0.jar")

This helpful clue resulted from turning on debugging:

.jclassLoader()$setDebug(1L)

as advised here: https://github.com/s-u/RJDBC/issues/26

Steve Pitchers
  • 7,088
  • 5
  • 41
  • 41
1

Cassandra JDBC driver v1.2.5 does not work with Cassandra 2.* and is very very deprecated, still uses the thrift API and does only connect to a single node.

You should grab the new version I made that uses the Datastax Java Driver underneath : https://github.com/adejanovski/java-driver

Here's a link to the compiled version with all the necessary dependencies : https://drive.google.com/file/d/0B7fwX0DqcWSTLUFqSEMxVFVWY2M/view?usp=sharing

Use the appropriate driver class and JDBC url as shown on this page : https://github.com/adejanovski/java-driver/tree/2.1/driver-jdbc

Another more efficient option (though I'm not familiar with R) should be to use R on Spark and access Cassandra through the spark-cassandra connector provided by Datastax.

  • I put all the dependencies in the folder and updated the scripts to your suggested (thanks so much for the help btw) cassdrv <- JDBC("com.datastax.driver.jdbc.CassandraDriver", list.files("C:/Users/atrombley/Desktop/R/cassandra/",pattern="jar$",full.names=T)) casscon <- dbConnect(cassdrv, "jdbc:cassandra://hostip:9042/api") – A Trombley Sep 10 '15 at 18:03
  • and I still get the following error: Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], : java.sql.SQLNonTransientConnectionException: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /10.121.184.XX:9042 (com.datastax.driver.core.ConnectionException: [/10.121.184.XX:9042] Unexpected error during transport initialization – A Trombley Sep 10 '15 at 18:07
  • The error message suggests that your Cassandra server cannot be reached on port 9042. Can you confirm that you can reach this server from the same machine using Datastax DevCenter, which uses the native port too ? – Alexander DEJANOVSKI Sep 11 '15 at 05:56
  • I can confirm that I can reach it from DevCenter using that port (can't add screen shot or i would show you) – A Trombley Sep 11 '15 at 19:52
  • I can connect from port 9160 from cqlsh legal-mac01:~ atrombley$ cqlsh 10.121.184.15 9160 userXXXXX pwXXXX Connected to Test Cluster at 10.121.184.15:9160. [cqlsh 4.1.1 | Cassandra 2.1.5.469 | CQL spec 3.1.1 | Thrift protocol 19.39.0] Use HELP for help. – A Trombley Sep 11 '15 at 20:34
  • It seems, based on your first comment, that you're not passing user and password for authentication while through cqlsh it seems you're authenticating. Shouldn't you specify those in dbConnect() ? Can you give the full stack trace of the exception ? – Alexander DEJANOVSKI Sep 13 '15 at 10:02
  • I have followed these instructions, put the dependencies in `/Library/Java/Extensions` and specified the `com.datastax.driver.jdbc.CassandraDriver` driver. However, I still get the "`class not found`" error... any clue as to what I may have missed, or what else I could check to debug? – Serenthia Oct 20 '15 at 17:13
0

So, the documentation is terrible out there, I was able to find out that you need the following "Dependency" jars, AND you need to put them in the same folder as the driver jar file.

List of JARS:

apache-cassandra-thrift-1.2.6 cassandra-jdbc-2.1.1 log4j-1.2.15 slf4j-simple-1.5.2 libthrift-0.7.0 jackson-core-asl-1.9.2 cassandra-all-1.2.9 slf4j-api-1.5.2 apache-cassandra-clientutil-1.2.6 jackson-mapper-asl-1.9.2 guava-15.0 slf4j-log4j12-1.5.2

However, even if you do get lucky enough to resolve this issue and R finds your driver, you will then have a problem and get the error below which no one seems to have fixed yet......

log4j:WARN No appenders could be found for logger (org.apache.cassandra.cql.jdbc.CassandraDriver). log4j:WARN Please initialize the log4j system properly. Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], : java.sql.SQLNonTransientConnectionException: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2097152000)!

A Trombley
  • 79
  • 1
  • 1
  • 2
0

Please add cassandra-jdbc-1.2.5-1.0.0.jar file in cassandra/lib folder. That working for me.

Karen Hovhannisyan
  • 1,140
  • 2
  • 21
  • 31
-1

None of the R examples worked for me, and I have read that even the ones that do work for you, you will have to build in pagination which is a pain in the a$$. Just do it in python with this script, and it does the pagination for you.

import sys
sys.path.append('/Library/Python/2.7/site-packages/')
import cql
from cassandra.cluster import Cluster
cluster = Cluster(contact_points=['10.121.xxx.xx'], protocol_version=3);
session = cluster.connect();
result = session.execute("select client_id, request_time, request_id,client_ip, exception, method, query_parameters, request_body, resource,response_duration_in_ms, response_http_code, user_id from api.api_usage_log")
A Trombley
  • 79
  • 1
  • 1
  • 2