3

我正在尝试按照“ http://www.datastax.com/dev/blog/big-analytics-with-r-cassandra-and-hive ”上给出的示例将 R 与 Cassandra 连接起来。以下是我的代码:

library(RJDBC)

    #Load in the Cassandra-JDBC diver
    cassdrv <- JDBC("org.apache.cassandra.cql.jdbc.CassandraDriver", list.files("D:/cassandra/lib",pattern="jar$",full.names=T))

    #Connect to Cassandra node and Keyspace
    casscon <- dbConnect(cassdrv, "jdbc:cassandra://127.0.0.1:9042/demodb")

当我在 R 中运行上述代码时,出现以下错误:

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 (-2113929216)!

在 Cassandra 服务器窗口上,上述代码出现以下错误:

ERROR 14:41:26,671 Unexpected exception during request
java.lang.ArrayIndexOutOfBoundsException: 34
        at org.apache.cassandra.transport.Message$Type.fromOpcode(Message.java:1
06)
        at org.apache.cassandra.transport.Frame$Decoder.decode(Frame.java:168)
        at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDeco
der.java:425)
        at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(Fram
eDecoder.java:303)
        at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:26
8)
        at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:25
5)
        at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
        at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(Abstract
NioWorker.java:109)
        at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNi
oSelector.java:312)
        at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioW
orker.java:90)
        at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

我试图将端口从 9042 更改为 9160,然后在这种情况下请求将无法到达服务器。我还尝试将大小thrift_framed_transport_size_in_mb从 15 增加到 500,但错误是相同的。

Cassandra 运行良好,数据库通过“devcenter”轻松连接/更新。

R version: R-3.1.0,
Cassandra version: 2.0.8,
Operating System: Windows,
XP Firewall: off
4

1 回答 1

2

最后我能够通过 R 连接到 cassandra。我按照以下步骤操作:

  1. 我将我的 java 7 和 R 更新到了最新版本。
  2. 然后,我重新安装了 RJDBC、rJava、DBI
  3. 然后,我使用以下代码,并成功连接:

    library(RJDBC)
    
    drv <- JDBC("org.apache.cassandra.cql.jdbc.CassandraDriver", list.files("D:/cassandra/lib/",pattern="jar$",full.names=T))
    
    .jaddClassPath("D:/mysql-connector-java-3.1.14/cassandra-clientutil-1.0.2.jar")
    
    conn <- dbConnect(drv, "jdbc:cassandra://127.0.0.1:9160/demodb")
    
    res <- dbGetQuery(conn, "select * from emp")
    
    
    
    # print values
    res
    
于 2014-06-19T06:48:05.207 回答