Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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>);

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

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

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")
      }   

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?

like image 569
Shashank Srivastava Avatar asked Jan 12 '17 21:01

Shashank Srivastava


People also ask

How do I get all column names in Cassandra?

To Select the data from Cassandra , Select statement is used. If you need to select all columns , you can use "*" or provide list of column names.

Which command modifies the column properties of a table in Cassandra?

Modifies the columns and properties of a table. Changes the datatype of a columns, add new columns, drop existing columns, renames columns, and change table properties. The command returns no results.


1 Answers

Try to add class to getList method:

row.getList("row_values", classOf[String])
like image 126
Cortwave Avatar answered Nov 15 '22 03:11

Cortwave