我正在尝试执行以下操作,但由于某种原因,由于 KeySerializer 的类型不匹配,我的代码无法编译。
implicit val keyspace = ConnectionPool.bigdataKeyspace
implicit val CF_PAST = ColumnFamily.newColumnFamily(CF, LongSerializer.get, StringSerializer.get)
def update(model: M) = {
val batch = keyspace.prepareMutationBatch().setConsistencyLevel(ConnectionPool.CL_WRITE)
val rk = model.rowkey
try {
batch.withRow(CF_PAST, rk)
.putColumnIfNotNull(model.epoch, model.value, model.ttl)
batch.execute
Option(model)
} catch {
case e: Exception =>
logger.warn("Unable to insert past model", e)
None
}
}
编译错误如下"
error: type mismatch; found
: com.netflix.astyanax.model.ColumnFamily[Long,String] required: com.netflix.astyanax.model.ColumnFamily[Comparable[_ >:
String with Long <: Comparable[_ >: String with Long <:
Comparable[_ >: String with Long <:
java.io.Serializable] with java.io.Serializable] with java.io.Serializable] with java.io.Serializable,String] Note:
Long <: Comparable[_ >: String with Long <: Comparable[_ >:
String with Long <: Comparable[_ >: String with Long <:
java.io.Serializable] with java.io.Serializable] with java.io.Serializable] with java.io.Serializable, but Java-defined class ColumnFamily is invariant in type K.
You may wish to investigate a wildcard type such as `_ <:
Comparable[_ >: String with Long <: Comparable[_ >:
String with Long <: Comparable[_ >: String with Long <: java.io.Serializable] with
java.io.Serializable] with java.io.Serializable] with java.io.Serializable`.
(SLS 3.2.10)
batch.withRow(CF_PAST, rk)
这似乎只发生在 Scala 中,KeySerializers 不是字符串,ColumnSerializers 其他类型似乎工作正常?有解决办法吗?