如何检索数据类型为“list”的列从卡桑德拉的表? [英] How to retrieve the column having datatype as "list" from the table of Cassandra?

查看:113
本文介绍了如何检索数据类型为“list”的列从卡桑德拉的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Scala连接Cassandra并在其中应用我的查询,我在Cassandra中创建了一个简单的表,它有两列row_id和row_values。
row_id的数据类型为varchar,row_values存储元素列表。我在表中插入了一些随机值,想要检索这些值。
用于创建表:

I am using Scala to connect with Cassandra and applying my queries in it, I have created a simple table in Cassandra which has two columns row_id and row_values. row_id has datatype as "varchar" and row_values stores the List of elements. I inserted some random values in the Table and want to retrieve these. For creating table:

CREATE TABLE Matrix1(row_id VARCHAR PRIMARY KEY, row_values LIST<VARCHAR>);

对于插入表格:

INSERT INTO Matrix1(row_id, row_values) VALUES ('abcd3', ['dsf23', 'fsf1','dsdf1']);

现在我想要检索值并使用Scala打印它们,我使用的代码来保存来自的值查询

Now I want to retrieve values and print them using Scala, I am using a code to save values from query

val results: ResultSet = session.execute("SELECT * FROM Matrix1 where row_id = 'abcd3'") 

现在我要打印row_id和row_values

Now I want to print the "row_id" and "row_values"

var rowid: String = null
var rowval: List[String] = null
for (row <- results) {
      rowid = row.getString("row_id")
      rowval = row.getList("row_values")
      }   

使用此代码我在rowid中获取值,因为它是一个String,但是rowval存在错误。如何从ResultSet中检索列(列表类型)?

with this code I am getting the values in "rowid" because it is a String, but there is an error for "rowval". How can I retrieve the column (List type) from the ResultSet?

推荐答案

尝试将类添加到 getList 方法:

row.getList("row_values", classOf[String])

这篇关于如何检索数据类型为“list”的列从卡桑德拉的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆