我在cassandra中有一个表,它是一个集合类型,并在scala中创建了case类:
case class test(
var status: Option[Set[String]]
)
字符串
现在我尝试使用cassandra java driver core将cassandra中的数据检索到scala中的case类:
Option(row.getSet("status", classOf[String]))
Error :
found : Set[String] (in java.util)
required: Set[String] (in scala.collection.immutable)
型
如何从cassandra到scala case set访问set类型?
我完整的方法来访问它是:
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
}
}
型
1条答案
按热度按时间y3bcpkx11#
我把它和
字符串
不得不进口:
型