无法通过R连接cassandra



我试图遵循在"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

最后我能够通过r连接到cassandra。我遵循以下步骤:

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

    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
    

相关内容

  • 没有找到相关文章

最新更新