如何使用Cassandra访问Cassandra表中的数据

如何使用Cassandra访问Cassandra表中的数据,r,cassandra,rc,R,Cassandra,Rc,我需要在Cassandra数据库表的列中获取数据。我用桑德拉来做这个。得到数据后,我需要对其进行一些文本挖掘。请建议我如何连接到cassandra,并使用cassandra将数据输入我的R脚本 我的RScript: library(RCassandra) connect.handle <- RC.connect(host="127.0.0.1", port=9160) RC.cluster.name(connect.handle) RC.use(connect.handle, 'mykey

我需要在Cassandra数据库表的列中获取数据。我用桑德拉来做这个。得到数据后,我需要对其进行一些文本挖掘。请建议我如何连接到cassandra,并使用cassandra将数据输入我的R脚本

我的RScript:

library(RCassandra)
connect.handle <- RC.connect(host="127.0.0.1", port=9160)
RC.cluster.name(connect.handle)
RC.use(connect.handle, 'mykeyspace')

sourcetable <- RC.read.table(connect.handle, "sourcetable")
print(ncol(sourcetable))
print(nrow(sourcetable))
print(sourcetable)
但是我的cassandra表包含四列,但这里只显示一列。我需要将每个列的值分开。那么,如何获取各个列的值(例如,每个feedurl)我应该在R脚本中做哪些更改


我已经将Cassandra和R与正确的Cran Jar文件一起使用,但是Cassandra更容易。RCASandra是Cassandra的直接接口,无需使用Java。要连接到Cassandra,您将使用RC.connect返回如下连接句柄

RC.connect(host = <xxx>, port = <xxx>)
RC.login(conn, username = "bar", password = "foo")
RC.connect(主机=,端口=)
RC.登录(conn,username=“bar”,password=“foo”)
然后可以使用
RC.get
命令检索数据,或使用
RC.ReadTable
命令读取表格数据


但是,首先您应该阅读

我已经将Cassandra和R与正确的Cran Jar文件一起使用,但是Cassandra更容易。RCASandra是Cassandra的直接接口,无需使用Java。要连接到Cassandra,您将使用RC.connect返回如下连接句柄

RC.connect(host = <xxx>, port = <xxx>)
RC.login(conn, username = "bar", password = "foo")
RC.connect(主机=,端口=)
RC.登录(conn,username=“bar”,password=“foo”)
然后可以使用
RC.get
命令检索数据,或使用
RC.ReadTable
命令读取表格数据


但是,首先你应该读一读,我也很困惑。表demo.emp有4行4列(empid、deptid、first_name和last_name)。RC.get和RC.read.table都不获取所有数据

cqlsh:demo> select * from emp;

empid | deptid | first_name | last_name
-------+--------+------------+-----------
 1 |      1 |       John |       Doe
 1 |      2 |        Mia |     Lewis
 2 |      1 |       Jean |       Doe
 2 |      2 |      Manny |     Lewis

> RC.get.range.slices(c, "emp", limit=10)
[[1]]
key value           ts
1           1.474796e+15
2      John 1.474796e+15
3       Doe 1.474796e+15
4           1.474796e+15
5       Mia 1.474796e+15

[[2]]
 key value           ts
1           1.474796e+15
2      Jean 1.474796e+15
3       Doe 1.474796e+15
4           1.474796e+15
5     Manny 1.474796e+15

我也很困惑。表demo.emp有4行4列(empid、deptid、first_name和last_name)。RC.get和RC.read.table都不获取所有数据

cqlsh:demo> select * from emp;

empid | deptid | first_name | last_name
-------+--------+------------+-----------
 1 |      1 |       John |       Doe
 1 |      2 |        Mia |     Lewis
 2 |      1 |       Jean |       Doe
 2 |      2 |      Manny |     Lewis

> RC.get.range.slices(c, "emp", limit=10)
[[1]]
key value           ts
1           1.474796e+15
2      John 1.474796e+15
3       Doe 1.474796e+15
4           1.474796e+15
5       Mia 1.474796e+15

[[2]]
 key value           ts
1           1.474796e+15
2      Jean 1.474796e+15
3       Doe 1.474796e+15
4           1.474796e+15
5     Manny 1.474796e+15

但是,当我使用RC.read.table时,我得到一个数据帧作为输出,ncol=1。我的cassandra数据库表中有4列,其中只有两列作为一列显示在该数据框中。为什么会这样?另外,如果我使用RC.get,我将获得相应表的行列表。但是如何获取每列的值呢?我完全搞糊涂了!但是,当我使用RC.read.table时,我得到一个数据帧作为输出,ncol=1。我的cassandra数据库表中有4列,其中只有两列作为一列显示在该数据框中。为什么会这样?另外,如果我使用RC.get,我将获得相应表的行列表。但是如何获取每列的值呢?我完全搞糊涂了!请编辑您的帖子并添加您尝试执行的R代码。请编辑您的帖子并添加您尝试执行的R代码。