[英]How to retrieve the column having datatype as “list” from the table of Cassandra?
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. 我使用Scala连接Cassandra并在其中应用我的查询,我在Cassandra中创建了一个简单的表,它有两列row_id和row_values。 row_id has datatype as "varchar" and row_values stores the List of elements.
row_id的数据类型为“varchar”,row_values存储元素列表。 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>);
For Inserting Into the table: 对于插入表格:
INSERT INTO Matrix1(row_id, row_values) VALUES ('abcd3', ['dsf23', 'fsf1','dsdf1']);
Now I want to retrieve values and print them using Scala, I am using a code to save values from query 现在我想检索值并使用Scala打印它们,我正在使用代码来保存查询中的值
val results: ResultSet = session.execute("SELECT * FROM Matrix1 where row_id = 'abcd3'")
Now I want to print the "row_id" and "row_values" 现在我要打印“row_id”和“row_values”
var rowid: String = null
var rowval: List[String] = null
for (row <- results) {
rowid = row.getString("row_id")
rowval = row.getList("row_values")
}
with this code I am getting the values in "rowid" because it is a String, but there is an error for "rowval". 使用此代码我在“rowid”中获取值,因为它是一个String,但“rowval”有错误。 How can I retrieve the column (List type) from the ResultSet?
如何从ResultSet中检索列(列表类型)?
尝试将类添加到getList
方法:
row.getList("row_values", classOf[String])
Quick elaboration: You specify the java class. 快速详细说明:您指定java类。 eg,
例如,
val driverDerivedRow = MyRow(row.getString("s"),
row.getInt("i"),
row.getList("l", classOf[java.lang.Long])
.asScala.toList.map(Long.unbox)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.