0
val CF_USER_STATS = new ColumnFamily[java.lang.Long, String]("Standard2", LongSerializer.get, StringSerializer.get)

val m: MutationBatch = keyspace.prepareMutationBatch()

m.withRow(CF_USER_STATS, "acct1234").incrementCounterColumn("CounterColumn1", 1)

m.execute()

以上是创建一个列族,旨在用作 Cassandra 中的计数器。无论出于何种原因,编译都会失败,原因如下:

type mismatch;
[error]  found   : com.netflix.astyanax.model.ColumnFamily[Long,String]
[error]  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]
[error] 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.
[error] 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)
[error]   m.withRow(CF_USER_STATS, "acct1234")
4

1 回答 1

0

带有描述的 Astyanax ColumnFamily 语法

ColumnFamily<String, String> CF = 
     new ColumnFamily<String, String>(
     "Standard1",              // Column Family Name
     StringSerializer.get(),   // Key Serializer
     StringSerializer.get());  // Column Serializer

现在,在您的情况下,您将 rowkey 作为 Long 类型,将 column 作为 String ,并且在更新计数器时使用 key 作为字符串,这就是这种类型 mismatch的原因。

于 2013-05-02T10:14:41.233 回答