简体   繁体   English

如何从Cassandra表中检索数据类型为“list”的列?

[英]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.

相关问题 Cassandra/Datastax:如何在 Java 中获取具有列表数据类型的列的值 - Cassandra/Datastax: How to get values of column having list datatype in java Cassandra:无论数据类型如何,如何获取列数据的字符串值 - Cassandra : How to get the String value of column data irrespective of datatype 如何使用jdbc和java-swing从特定列检索完整的xml(DataType as XMLTYPE) - How to retrieve the complete xml (DataType as XMLTYPE) from the specific column using jdbc and java-swing Cassandra,Hector:如何在1次调用中从列族中检索特定键的特定列集? - Cassandra , Hector :how to retrieve specific set of columns for specific keys from a column family in 1 call? 如何为对象列表提供数据类型以将其存储在表列中 - What to provide datatype for List of objects for storing it in table column 如何从MySql表列中将特定字段的总和检索到变量中 - How to retrieve the Sum of particular field from MySql table column into variable 如何使用休眠Lucene搜索从表中检索特定列? - How to retrieve a specific column from a table using hibernate lucene search? 如何使用JSQLPARSE从SQl检索表和列名称 - How to retrieve table and column names from SQl using JSQLPARSE 如何将表中的多个条目检索到一个列表中? - How to retrieve multiple entries from table into one list? 如何从相同模型的不同表中检索对象列表? - How to retrieve a list of objects from a different table in same model?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM