可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答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.
回答2:
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
回答3:
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)!
回答4:
Please add cassandra-jdbc-1.2.5-1.0.0.jar file in cassandra/lib folder. That working for me.
回答5:
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")