I have a table in cassandra which is a set type and have case class created in scala as:
case class test(
var status: Option[Set[String]]
)
now I am trying to retreive the data from cassandra to this case class in scala using cassandra java driver core as :
Option(row.getSet("status", classOf[String]))
Error :
found : Set[String] (in java.util)
required: Set[String] (in scala.collection.immutable)
how can I access set type from cassandra to scala case set?
my full method to acess it is:
def getData(id: String): Option[test] = {
try {
val result = session.execute(
s"SELECT * FROM $Keyspace.table WHERE id=?",
id
)
if (result.getAvailableWithoutFetching != 1) {
logger.error(s"Failed to find $Id")
None
} else {
val row = result.one()
Some(test(
id,
Option(row.getSet("customer_status", classOf[String]))
))
}
} catch {
case e: IllegalArgumentException =>
logger.error(s"Requested column names incorrect when attempting to get customer record: $e")
None
case e: Exception =>
logger.error(s"Exception in getting customer record for customer $id: $e")
None
}
}
I got it working with
and had to import: