如何从Cassandra用R读取数据? [英] How to read data from Cassandra with R?
问题描述
我使用R 2.14.1和Cassandra 1.2.11,我有一个单独的程序,它将数据写入单个Cassandra表。
I am using R 2.14.1 and Cassandra 1.2.11, I have a separate program which has written data to a single Cassandra table. I am failing to read them from R.
Cassandra模式定义如下:
The Cassandra schema is defined like this:
create table chosen_samples (id bigint , temperature double, primary key(id))
我已经尝试过RCassandra软件包( http://www.rforge.net/RCassandra/ )
I have first tried the RCassandra package (http://www.rforge.net/RCassandra/)
> # install.packages("RCassandra")
> library(RCassandra)
> rc <- RC.connect(host ="192.168.33.10", port = 9160L)
> RC.use(rc, "poc1_samples")
> cs <- RC.read.table(rc, c.family="chosen_samples")
连接似乎成功,但是将表解析为数据框失败:
The connection seems to succeed but the parsing of the table into data frame fails:
> cs
Error in data.frame(..dfd. = c("@\"ffffff", "@(<cc><cc><cc><cc><cc><cd>", :
duplicate row.names:
连接器,如下所示: http://www.datastax.com/ dev / blog / big-analytics-with-r-cassandra-and-hive
> # install.packages("RJDBC")
> library(RJDBC)
> cassdrv <- JDBC("org.apache.cassandra.cql.jdbc.CassandraDriver", "/Users/svend/dev/libs/cassandra-jdbc-1.2.5.jar", "`")
像这样:
Error in .jfindClass(as.character(driverClass)[1]) : class not found
即使java驱动程序的位置是正确的
Even though the location to the java driver is correct
$ ls /Users/svend/dev/libs/cassandra-jdbc-1.2.5.jar
/Users/svend/dev/libs/cassandra-jdbc-1.2.5.jar
推荐答案
您必须下载 apache-cassandra-2.0。 10-bin.tar.gz 和 cassandra-jdbc-1.2.5.jar 和 cassandra-all-1.1.0.jar 。
不需要在本地机器上安装Cassandra;只需将cassandra-jdbc-1.2.5.jar和cassandra-all-1.1.0.jar文件放在解压缩的apache-cassandra-2.0.10-bin.tar.gz的lib目录中。然后您可以使用
There is no need to install Cassandra on your local machine; just put the cassandra-jdbc-1.2.5.jar and the cassandra-all-1.1.0.jar files in the lib directory of unziped apache-cassandra-2.0.10-bin.tar.gz. Then you can use
library(RJDBC)
drv <- JDBC("org.apache.cassandra.cql.jdbc.CassandraDriver",
list.files("D:/apache-cassandra-2.0.10/lib",
pattern="jar$",full.names=T))
这是在我的unix,但不是在我的Windows机器上。
希望有帮助。
That is working on my unix but not on my windows machine. Hope that helps.
这篇关于如何从Cassandra用R读取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!