我在可选列上有一个二级索引:
class Sessions extends CassandraTable[ConcreteSessions, Session] {
object matchId extends LongColumn(this) with PartitionKey[Long]
object userId extends OptionalLongColumn(this) with Index[Option[Long]]
...
}
但是,indexedToQueryColumn
隐式转换不适用于可选列,因此无法编译:
def getByUserId(userId: Long): Future[Seq[Session]] = {
select.where(_.userId eqs userId).fetch()
}
这也不是:
select.where(_.userId eqs Some(userId)).fetch()
或者改变索引的类型:
object userId extends OptionalLongColumn(this) with Index[Long]
有没有办法使用幻像执行这样的查询?
我知道我可以进行非规范化,但这会涉及一些非常混乱的内务管理,并使我们的(大量)数据大小增加三倍。查询通常只返回少数结果,所以在这种情况下我愿意使用二级索引。