使用astyanax客户机编译scala代码时出现问题

pcrecxhr  于 2021-06-14  发布在  Cassandra
关注(0)|答案(1)|浏览(406)
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")
ebdffaop

ebdffaop1#

astyanax列族语法及说明

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作为字符串,这就是为什么类型不匹配的原因。

相关问题