无法通过R连接cassandra

时间:2014-06-17 20:09:01

标签: r cassandra rjdbc

我试图效仿" 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运行正常,数据库通过&#34; devcenter&#34;轻松连接/更新。

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

1 个答案:

答案 0 :(得分: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